Upload
stefanyc-fanel
View
5
Download
1
Embed Size (px)
Citation preview
Jörg Prim
A clap switch circuit isa classic beginner’s
project. Equipment canbe switched on and offby just clapping your
hands. Add a tinymicrocontroller and
you can easily build-insome more
useful features.
Intelligent Clap
Manual remote controlwith extras
The microcontroller in this circuitmakes it a simple job to add some use-ful features that are not seen on otherclap switch designs:
– Changeover relay contacts enablethe unit to be wired in conjunctionwith a manual changeover switch sothat manual override of the switchedequipment is always possible.
– The unit is only responsive to a spe-cific sequence of sounds i.e., twoclaps within a defined time window.
– A safety feature masks the input fora given time window if misuse(repeated commands) is detected(useful if children have discoveredhow it works).
The safety feature and two-clapsequence detector can be built usingTTL or CMOS flip-flops but by using a
single microcontroller the circuit canbe greatly simplified. A mains powersupply is included so no additionalpower source is required.
A compact ControllerThe Microchip flash PIC12F629 micro-controller is a neat device; the small 8-pin package contains a complete micro-controller including clock generator,reset circuitry, Flash ROM, RAM andEEPROM. Two of the eight pins areused for the supply connections whilethe remaining six are general-purposeI/O pins. A few of these pins have spe-cial function like the comparator inputs.The sound sensitivity of the circuit canbe adjusted by programming the com-parator threshold level in software.The circuit diagram in Figure 1 showsthat besides the microcontroller there
are very few other components. Thetwo-pin electret microphone producesan electrical signal in response to soundpressure waves. Transistor T1 amplifiesthe signal and preset P1 allows someadjustment of the circuit sensitivity byaltering the bias voltage of T1.Two of the PIC output pins are used todrive a bistable relay via transistors T2and T3. This type of relay has twoenergising coils. A short electricalpulse on one of the coils is enough toswitch the relay in one direction whilea pulse to the other coil will cause therelay to switch back. This type of relayhas two main advantages: the relay islatching in both open and close direc-tion so a short pulse is all that is nec-essary to switch it. Secondly the latch-ing feature ensures that the relayretains its switched state even duringa power failure. Changeover relay con-
1/2005 - elektor electronics 65
TR1
B1
B80C1500
78L05IC1
C1
220µ25V
C2
100n
+5V
+UK1
GP4/COUT
GP5/CIN
12F629
GP3/MC
IC2
GP1
GP0
GP2
3
1
6
8
2
7
5
4
JP1
R6
4k7
R7
4k7
T2
T3
BC238
R5
150
Ω
R4
10k
R2
150k
R1
4k7
100k
P1
T1
BC238R3
22k
C3
1µ
D1
1N4148
D2
1
K2
2x
2x
RE1
+5V +U
030166 - 11
2VA36V
D3
duo-LEDgreen/red
MIC1
electret
230V
CO
M
Figure 1. A tiny PIC12F629 samples the input and switches a bistable relay.
Switch
tacts enable the unit to be wiredtogether with a changeover type man-ual switch, allowing the equipment tobe switched manually if for any reasonthe clap switch is switched off.Pins 2 and 7 are used to switch a two-colour LED providing a visual indica-tion of the switched state of the relay.
The last output pin of the PIC is notused and is connected to a jumper toallow switching software options.
SoftwareWhen the signal level at GP1 goeslow (clap detected) the program
waits for approximately 200 ms dur-ing which time the LED glows red.After this period the LED switches togreen and the software samples theinput for approximately three sec-onds. If a second clap is detected dur-ing this period, the controllerswitches the output. After switching,the controller ignores any further clapsounds for approximately 10 s andthe LED lights red. The output stateis stored in EEPROM so that if apower failure occurs the software willswitch the correct relay coil whenpower is re-established.
A safety feature counts each switchingevent on an internal counter, which isdecremented slowly in software.Should this counter exceed a thresholdlevel, the circuit will ignore any inputsignals for approximately one minuteand the LED blinks red. This willensure that the circuit does notrespond to an extended burst of noise(e.g., applause).
The PCBThe PCB layout shown in Figure 2accommodates all components apartfrom the electret microphone. This isattached to the board at the MIC +/–connections with a length of shieldedaudio lead (keep the wire length toless than around 10 cm).
Mounting the components onto thePCB should be quite straightforward.Start by fitting the single wire bridgenext to rectifier B1. Ensure that allpolarised components (diodes, LEDs,capacitors and the IC) are fitted thecorrect way round. The LED leadsshould be trimmed so that when it issoldered to the board it protrudesthrough a hole in the lid when the caseis assembled; alternatively use atranslucent enclosure.
Once all components have been fittedand all solder connections have beeninspected the PCB can be fitted into aninsulated enclosure. The mains inputlead will require some form of strainrelief. Be aware that some tracks carrylethal voltages. All appropriate safetyguidelines must therefore be adheredto. A small hole can be made in the liddirectly over preset P1 if it is necessaryto adjust the sensitivity of the circuitwithout dismantling the unit. Lastly,don’t forget to add perforations in thecase so that sound waves can reachthe microphone capsule.
(030166-1)
elektor electronics - 1/200566
(C) ELEKTOR030166-1
B1
C1
C2
C3
D1D2
D3
IC1
IC2
JP1
K1
K2
P1R1
R2R3
R4
R5R6
R7
RE1
T1
T2
T3
TR1
230V~ 030166-1
MIC1+
-
COM
Figure 2. All components apart from the electret microphone are accommodated onthe PCB.
COMPONENTSLISTResistors:R1,R6,R7 = 4kΩ7R2 = 150kΩR3 = 22kΩR4 = 10kΩR5 = 150ΩP1 = 100kΩ preset H
Capacitors:C1 = 220µF 25V radialC2 = 100nFC3 = 1µF 16V
Semiconductors:B1 = B80C1500 (round case, 80V piv,
1.5A)D1,D2 = 1N4148D3 = bicolour LED (red/green)IC1 = 78L05
IC2 = PIC12F629CP, programmed,order code 030166-41
T1,T2,T3 = BC238 or BC547
Miscellaneous:JP1 = 2-way pinheader with jumperK1 = 2-way PCB terminal block, lead
pitch 7.5mmK2 = 3- way PCB terminal block, lead
pitch 7.5mmMIC1 = 2-terminal electret microphone
capsuleRe1 = bistable relay, 2 x changeover
(e.g., Schrack RT314F12)Tr1 = mains transformer 1 x 6V, min.
2VA, short-circuit proof (e.g.,Marschner VN30.15/10522 or Era030-7340.0T; Conrad Electronics #506141)
PCB, order code 030166-1 (seeReaders Services page)
Disk, source and hex files, order code030166-11 or Free Download