This is only a preview of the November 2005 issue of Silicon Chip. You can view 44 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Studio Series Stereo Headphone Amplifier":
Items relevant to "Build A MIDI Drum Kit":
Items relevant to "Serial I/O Controller & Analog Sampler":
Items relevant to "PICAXE In Schools; Pt.5":
Purchase a printed copy of this issue for $10.00. |
By Clive Seager*
In Part 4, we used our Schools Experimenter board to control DC
motors, solenoids and servos. In this, the final instalment of the
series, we look at adding infrared remote control and voice recording
capabilities. For more advanced experimenters, we also show how to
build a sound detection circuit that complements the simpler light and
temperature circuits described in Parts 2 & 3.
IN THIS ARTICLE you will learn:
• how to use infrared remote
control;
• how to record and play back
sounds;
• how to detect and respond to
sounds.
Many indoor projects lend themselves well to infrared remote control,
so for the first project, we’ll show you
how to add an infrared receiver to your
board that will work with a TV-style
remote control. We’ll then add an
external voice recorder module and
* About the author: Clive Seager is the
Technical Director of Revolution Education
Ltd, the developers of the PICAXE system.
90 Silicon Chip
show you how to record and play back
a sound clip via remote control.
To get started, let’s look at the infrared remote control side of things.
Infrared remote control
Every infrared remote system consists of two parts: a transmitter and
a receiver. There are many different
protocols for sending infrared data,
with most major manufacturers opting
for their own “standard”. The PICAXE
system uses the Sony infrared remote
control (SIRCS) protocol, allowing
it to be used with a normal TV-style
remote control.
All universal, “one-for-all” style
infrared remote controls can be set up
to control Sony brand equipment and
therefore will work with this project.
It’s just a matter of programming the
remote with one of the Sony equipment codes provided in the accompanying instructions. For example, the
TVR010 remote control featured here
must be programmed with the unique
code C-2-1-2.
Note that it’s also possible to make
your own transmitter using a second
PICAXE-08M chip, instead of buying a
universal remote. Check the “PICAXE
Infrared Remote Control” article (featuring “Rudolph the Red-Nosed Reindeer”) in the November 2004 edition
of SILICON CHIP for more details.
The PICAXE-08M requires only four
siliconchip.com.au
additional components to receive infrared transmissions, as shown in the
simplified circuit of Fig.1. This circuit
(minus the PICAXE chip) is easily
constructed on a breadboard and then
connected to the experimenter board,
as illustrated in Fig.2. Make sure that
the DIL switch (SW2) positions 3 & 4
are OFF and that 1 & 2 are ON.
Each infrared transmission is 12 bits
long and is produced by modulating
a 38kHz carrier signal (see Fig.3). A
TSOP4838 infrared receiver module
detects the infrared signal with the use
of a photodiode. The signal is then demodulated (ie, the carrier is removed),
before it is fed into the PICAXE-08M
chip for decoding. A block diagram of
the internals of the TSOP4838 receiver
module is shown in Fig.4.
The BASIC program in Listing 1
shows how to use the infrain2 command to read data from the infrared
receiver module. Once an infrared
transmission is received, the program
uses familiar commands to switch one
of the three LEDs on the experimenter
board on or off, depending on which
of the first six numeric keys on the
remote control is pressed.
Note that within the Sony protocol,
the number transmitted by the remote
control is actually one less than the
number you would expect from the
button (eg, pressing button 4 actually
transmits the data value 3!).
Task – write a program that makes the
green LED flash to indicate the number of
the numeric key pressed (ie, five flashes
for key number five). Keys other than 1-9
should be ignored.
Fig.1: this simple circuit adds infrared support to the PICAXE-08M. A
Vishay TSOP4838 infrared receiver module detects and demodulates the
infrared data stream, which is then fed into the microcontroller on input 3.
Fig.2: here’s how to wire up the infrared receiver circuit on the breadboard
and connect it to the School’s Experimenter.
Recording & replaying sounds
A significant number of functions
are required to record and play back
sound on a computer system. First, the
sound must be picked up by a microphone and amplified. It must then be
filtered and converted from analog to
digital form. It can then be stored in
memory ready for playback.
To play back the sound, it must be retrieved from memory, converted from
digital to analog format, amplified and
then fed to a loudspeaker.
This simplified description holds
true for all digital sound recording systems and one of the key requirements
for such a system is lots of memory
space. Even short sound clips require
a lot more memory than is available
in a low-cost microcontroller like the
PICAXE-08M.
siliconchip.com.au
Here’s what the above circuit looks
like assembled onto the breadboard.
Also shown is the TVR010 infrared
remote control mentioned in the text.
November 2005 91
Fig.3: basics of the SIRCS protocol, showing the composition of each
serial transmission. A logic “1” is represented by a 1.2ms burst of the
38kHz carrier, whereas a logic “0” is represented by a shorter 0.6ms
burst. Each bit is separated by a gap of 0.6ms.
Fig.4: this diagram reveals the basic functional blocks inside the
TSOP4838 infrared receiver. As well as the actual PIN (photo) diode,
it includes amplifier, discrimination and demodulation circuits to
reconstruct the original digital data, which appears on the “OUT” pin.
One way of providing sound recording capabilities on a simple
microcontroller-based system is to use
a dedicated recording chip with inbuilt
memory, such as one of the ISD5100
series Chipcorders (www.isd.com).
These devices can store from 2-16
minutes of voice-quality sound.
Unfortunately, these chips are
quite difficult to interface to the
PICAXE-08M. A much simpler and
cheaper solution is to “hack” into a
pre-assembled recorder module. These
are available in many forms, from
keyring note-takers to surplus modules
originally destined for children’s toys.
Generally, these modules are easily
modified to work with PICAXE microcontrollers. One such module is shown
in one of the photos. It is supplied with
two pushbutton switches (record and
play), a speaker, a LED and a battery
holder, all attached to a small PC board
via flying leads.
The following description deals
exclusively with the PPM155 module
but other types are readily interfaced
to the PICAXE micro in a similar manner. For example, the Oatley VRM1
25s voice recorder (www.oatleye.
com) would probably be suitable, as
would the 45-Second Voice Recorder
project described in SILICON CHIP, in
May 2005.
Note: although designed for 4-cell
(6V) operation, the PPM155 module
described here operates satisfactorily
from a 4.5V supply, as will most other
6V modules. Of course, we cannot
guarantee that all modules will work
from a 4.5V supply, so check for suitability before “hacking”! In some cases,
a separate supply may be required for
the module.
Before going any further, install batteries in the recorder’s holder and try it
out to make sure that it works properly.
This will also give you the opportunity
to discover how it works – before
hacking it! You will note that with
this module, the “record” switch has
to be held down to record, while the
“play” switch only has to be pressed
momentarily to play back the sound.
The LED should light while recording
is taking place.
Hacking the recorder module
The first ‘‘hack” involves cutting
off the battery holder so that the
whole project can use the Schools
Experimenter battery pack. Cut the
red and black wires close to the battery
holder, leaving plenty of length from
the PC board side for connection to
our project.
The second job is to replace the
“play” and “record” switches with outputs from the PICAXE-08M chip. Each
switch is connected to the module via
two red wires; one goes to “0V” and
the other to the input of the speech
memory chip. You need to identify
which of the two wires goes to the
speech memory chip and connect it
to output 1 (for the “play” switch) or
Fig.5: here’s how to
connect the voice
recorder module. If
you’ve already constructed the infrared
receiver on your
breadboard, then don’t
disassemble it – just
add this circuitry as
well. Note that you’ll
need to solder short
single-strand jumper
wires to the end of
each of the recorder’s
flying leads so that you
can plug them into
the small holes in the
breadboard.
92 Silicon Chip
siliconchip.com.au
The sound recorder module offered by MicroZed may differ from the unit
shown here but should be just as easy to interface to the PICAXE micro. This
unit features “record” and “play” buttons, a LED, a miniature speaker and a
battery holder, all attached by short lengths of wire. All functions are performed
by a single IC, which is hidden beneath a mound of black epoxy. Strangely, even
the through-hole components are mounted on the copper side of the board!
output 2 (for the “record” switch) of
the PICAXE.
The correct wire is easily identified
by using your multimeter to measure
the resistance between the negative
(black) battery lead and the two wires
soldered to the switch assembly. The
“0V” wire will measure zero ohms to
battery negative, so it can be ignored;
the other wire is the one to be connected to the PICAXE.
Your completed breadboard layout
should look something like Fig.5.
As you can see, we’ve added 330W
resistors between the two PICAXE
outputs and the module’s switch
inputs, which help to protect against
accidental wiring mistakes! Make sure
that DIL switch (SW2) contacts 1 & 2
on the experimenter board are now
switched off.
The program in Listing 2 will record
10 seconds of sound and then immediately play it back. The playback is then
constantly repeated, with a 1-second
delay between loops. It is important
to note how the outputs work; the
module switches are “active low”
and so we have to switch the PICAXE
outputs high at the start of the program
and then pulse them low to activate
the module.
The final step in the project is to
combine the infrared circuit with the
siliconchip.com.au
sound recorder circuit.
Task – write a program so that the record
and playback features are triggered by a
key press on the infrared remote control.
If you combine this project with a
servo-operated “puppet” on output
4 (see Pt.4 of this series for servo
information), you could build a very
interesting animatronics project!
Sound detection
In previous articles, we looked at
how to measure light (using a lightdependent resistor) and temperature
(using a DS18B20 sensor). Unfortunately, sound is not as easy to detect
with a PICAXE-08M chip, as it requires
considerably more than a simple “single component” solution.
The main problems to be considered
when designing a simple sound detection circuit are as follows:
(1) While electret microphone inserts
are ideal due to their low cost, they
produce a very small signal that requires amplification;
(2) The background noise level can
vary considerably and so some form
of calibration is required; and
(3) Some noises, such as a hand-clap,
are very quick and so could easily be
missed by PICAXE programs.
Fortunately, these problems can
all be overcome at low cost, using an
Par t s Lis t
IR receiver & sound recorder
1 TSOP4838 infrared receiver
module
1 TVR010 remote control (or any
universal remote, see text)
1 PPM155 20s sound recorder
(or similar, see text)
1 4.7mF 16V electrolytic capacitor
1 4.7kW 0.25W 5% resistor
3 330W 0.25W 5% resistors
Note: the remote control (part no.
TVR010) and TSOP4838 sensor
(part no. LED020) are available
individually or in a combination
pack (part no. AXE040) from
MicroZed, see www.picaxe.com.
au for more information or phone
(02) 4351 0886. Microzed can
also supply the PPM155 sound
recorder module.
Sound detector
2 BC548 transistors (Q1 & Q3)
1 BC558 transistor (Q2)
1 1N4148 diode (D1)
1 electret microphone
Capacitors
3 470nF polyester
1 1nF polyester
Resistors (0.25W, 5%)
1 220kW
2 4.7kW
1 100kW
1 100W
1 10kW
1 5kW miniature trimpot (VR1)
1 50kW miniature trimpot (VR2)
November 2005 93
Fig.6: the sound detection circuit uses a handful of low-cost parts. The
first stage amplifies the signal from the microphone, which is then clipped,
peak detected and finally buffered to provide a 0-3V output.
electret microphone together with
three common transistors and a few
resistors and capacitors, as shown in
Fig.6. This circuit will produce an
analog output signal of 0-3V that can
be read by the analog input (eg, input
4) of the PICAXE-08M. It also includes
a time-delay feature that extends the
period of the loudest signal.
The program in Listing 3 demonstrates how to use the readadc
command to read the signal from the
detection circuit connected to input
4 and light the red LED when a loud
sound is heard. Note that contact 4 of
the DIP switch (SW2) must be in the
“off” position.
As before, the circuit can be constructed on your breadboard, using
Fig.7 as a guide. We’ve used multi-turn
trimpots for VR1 & VR2, as they’re easy
to insert in the breadboard. However,
ordinary single-turn miniature trimpots could also be used.
Important: never force over-sized
component leads into the breadboard
holes. Solder short lengths of singlestrand jumper wire to large leads first
to allow easy insertion.
How the detector works
Sound is sensed by a low-cost electret microphone, which for typical
speech levels produces an output of
about 1mV RMS at a distance of about
60cm. This means that we can expect
signal levels of about 1-3mV from the
microphone.
The electret microphone is based on
a special type of Field Effect Transistor (FET), physically constructed to
convert vibrations (from sound or
physical contact) into an electric signal. It is a polarised device and must
be connected the right way around;
the negative (-) lead is easily identified as it is connected to the external
metal can.
The output from the microphone is
coupled to the base of the first transistor (Q1) via a 470nF capacitor. This
transistor acts as an amplifier, providing a gain of 25 over the 300Hz-30kHz
frequency range. The result is a larger
(25-75mV) signal on the collector,
where it is picked off by the wiper of
sensitivity control pot VR1 to feed the
following stage.
Like the sound waves that it represents, the AC signal applied to the
second stage consists of constantly
rising and falling (alternating) voltage
levels. In order to detect a signal (and
therefore a sound) level above a set
amplitude, it is necessary to establish
a reference point on the signal from
which to measure.
To this end, the second-stage transistor (Q2) is biased to cut-off and amplifies only negative-going signals. The
resultant positive-going signal at the
collector causes D1 to conduct, thus
charging the 470nF capacitor at its
cathode to the peak signal level.
The third transistor (Q3) is configured as an emitter follower. Its job is
to buffer the signal from the 470nF
capacitor, providing a low-impedance
output for driving external circuitry.
The signal at the output rises faster
than it falls, proportional to the value
of the 470nF capacitor at the base of
Q3. We can therefore say that this capacitor defines the “delay time” that
the highest sound level is present.
Using the 470nF value shown, the
Fig.7: the sound
detection circuit calls
for a much more
complex breadboard
layout than used
previously and should
prove a challenge!
Make sure that you
don’t mix up the two
different transistor
types and check their
orientation – the flat
side must face the right
way around. Also,
check that you have
the banded (cathode)
end of the diode
pointing the right way.
94 Silicon Chip
siliconchip.com.au
decay time of the output signal is approximately 0.5 seconds. Increasing
the capacitor to 2.2mF provides a decay
time of approximately two seconds.
Adjustments
Initially, set the sensitivity control
(VR1) to minimum (wiper towards
the positive rail). Next, set your multimeter to read DCV and connect it
between the output (emitter of Q3)
and the 0V rail. Now adjust VR2 to a
reading of just above 0V on your meter. This slightly positive bias of a few
millivolts helps to avoid a “dead band”
in the response of the detector.
The sensitivity control (VR1) is now
increased to a suitable level for the
project. Typical speech at about 50cm
from the microphone will give a DC
output of about 1V peak. A handclap
should produce an output of about
3V peak.
As mentioned earlier, you’ll find
that the signal is present for longer
than the noise that causes it, as dictated by the value of the capacitor in
the base circuit of Q3.
And finally . . .
We hope that this series of articles
has given you some confidence in programming and working with PICAXE
microcontrollers. Although this is
the final in our “PICAXE in Schools”
series, there will be more PICAXEbased projects in future issues. Happy
SC
experimenting!
Program Listings
Listing 1
Listing 2
main:
infrain2
if infra = 0 then red_on
if infra = 1 then yellow_on
if infra = 2 then green_on
if infra = 3 then red_off
if infra = 4 then yellow_off
if infra = 5 then green_off
goto main
init:
high 1
high 2
record:
low 2
pause 10000
high 2
play_back:
low 1
pause 100
high 1
pause 10000
pause 1000
goto play_back
red_on:
high 0
goto main
yellow_on:
high 1
goto main
green_on:
high 2
goto main
Listing 3
red_off:
low 0
goto main
main:
readadc 4,b1
if b1 > 100 then bang
goto main
yellow_off:
low 1
goto main
bang:
high 0
pause 1000
low 0
goto main
green_off:
low 2
goto main
TAKE YOUR PIC
Picaxe.com.au
DISTRIBUTOR: MicroZed.com.au
Developed for students, & professional performance
makes PICAXE the most easy-to-use micro ever:
PICAXE “programmer" is two resistors and a 4.5V battery!
PHONE 1300
1300 735
735 420
420
8.30-4.30 AEST Mon-Fri
FAX 1300 735 421 24 Hours
ALL PICAXE ITEMS ON OUR SHELVES!
STOCKISTS
siliconchip.com.au
In AUSTRALIA:
altronics.com.au
(Retail and Mail Order)
oatleyelectronics.com
School Electronic Supplies
In NEW ZEALAND
sicom.co.nz
surplustronics.co.nz
(School orders only – John - 03 8802 0628)
November 2005 95
|