This instructable not only gives the reader the information needed to create a clap-clap on/clap clap off switching circuit, but the logic used to make a hardware-only clap-on, clap off circuit. More information on a hardware-only version can be found in the final section of this instructable.
This circuit employs some very simple and cheap circuitry, and a simple program. It is relatively easy to make a hardware only clap on/off circuit, but I wanted to create a circuit that required two claps to switch on, and two claps to switch off. The claps must be in quick succession, as seen in the video below, or else it does not work, which is the entire point of the circuit =) I will go into detail about the circuitry, and the program. I will also do my very best to answer any questions you guys may have. This device can be thrown together in a single evening.
The software works like this:
1) The software waits for an initial loud noise, then starts a countdown sequence.
2) If the device detects another loud noise within about 250 milliseconds, then the relay will toggle on. If the timer runs out of time without detecting another loud noise, the program resets.
3) Once two claps have been detected, and the relay toggles on. The software then starts the same sequence over again, only waiting to toggle the relay off.
4) Once the relay toggles off again after detecting two claps in succession, the program resets back to the original state.
Since the PIC10F222 has a limited instruction set, I had to add in some extra lines of code. I would have used the PIX18F1220, but that would have been over-kill. Ah, but how I miss the BTF (Bit Toggle) instruction =)
Step 1: PART LIST:
I'll start of by giving you guys a part list. The box and the screws are not necessary for this project, but I'll add them to the list.
1x Prototyping board (Roughly 1" by 1") or bread board.
1x 9v Connector
1x LM324 Quad Op-Amp IC
1x LM78L05 Mini 5v Regulator
1x PIC10F222 Micro controller
1x Electret microphone
1x 5v Relay SPDT or SPST
1x 2N2222 NPN Transistor
2x 0.1uF Ceramic capacitors
1x 1N4001 Diode
1x 100k Ohm Multi-Turn Potentiometer
1x 100k Ohm 1/4W resistor
2x 10k Ohm 1/4W resistor
1x 3k Ohm 1/4W resistor
1x 7k Ohm 1/4W resistor
1x 1k Ohm 1/4W resistor
1x Project Box