Summary of How to make a Clap-Clap on / Clap-Clap Off switch circuit! using PIC10F222
This article details the construction of a clap-clap on/clap-clap off switch circuit using a PIC10F222 microcontroller. The system requires two rapid claps to toggle a relay, distinguishing it from single-clap triggers. The design features a hardware-only logic approach where an electret microphone amplifies sound via an LM324 op-amp, and software detects noise within a 250ms window to trigger state changes. The project is simple enough to assemble in one evening using a prototyping board and a 9V battery power supply.
Parts used in the Clap-Clap On/Off Switch Circuit:
- Prototyping board (Roughly 1" by 1") or bread board
- 9v Connector
- LM324 Quad Op-Amp IC
- LM78L05 Mini 5v Regulator
- PIC10F222 Micro controller
- Electret microphone
- 5v Relay SPDT or SPST
- 2N2222 NPN Transistor
- 0.1uF Ceramic capacitors
- 1N4001 Diode
- 100k Ohm Multi-Turn Potentiometer
- 100k Ohm 1/4W resistor
- 10k Ohm 1/4W resistors
- 3k Ohm 1/4W resistor
- 7k Ohm 1/4W resistor
- 1k Ohm 1/4W resistor
- Project Box
How to make a Clap-Clap on / Clap-Clap Off switch circuit!
Hi all!
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 =)
PART LIST:
HARDWARE:
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.
PART 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
THE POWER SUPPLY
THE VOLTAGE REGULATOR:
This step is a short one. We’re going to talk about the power supply circuit.
We only need a 9v battery to properly drive this circuit. We can use 7VDC and up. The 78L05 5V regulator is used here because this is a low-power device, and we need not use a big LM7805 when we have so little space to begin with.
The 78L05 has three pins:
1) 5V-Out
2) Ground
3) Voltage-In (7VDC+)
We need only a 0.1uf ceramic decoupling capacitor between the 5v-Out line, and ground to rid the circuit of any unwanted high frequency interference that may come along. However, since we are using a battery, this capacitor is really optional. Good practice, more like. If you are using an AC-DC wall wart, it is suggested you place a 100uf electrolytic capacitor between the Voltage-In pin, and the ground line to protect against any surges on the line, and to smooth the DC going in to the regulator.
THE SIGNAL AMPLIFIER AND COMPARATOR
STAGE#1: The Microphone and the Amplifier
As you can see from the picture below, we have an electret microphone connected to the ground line, and to one end of a 10k resistor. The other end of the resistor is tied to the 5v line. when an audio sound is sensed by the micrpphone, it changes that audio signal into a voltage that emulates the tone picked up. We can use that noise, but first we have to condition it. To rid ourselves of the DC component, we AC-couple the signal using a coupling capacitor. This signal will be extremely small, so we must first amplify it. We are going to do that using a handy-dandy LM324 quad op-amp IC. This chip has 4x on-board op-amps. We are only going to use two of them. Go here for the data sheet: http://www.national.com/ds/LM/LM124.pdf
The pull-down resistor to the right of the coupling capacitor is necessary for the operation of the non-inverting amplifier stage to work. In fact, all components in the below diagram are crutial. The way a non-inverting op-amp works, is it takes two values RA, which is the 1k resistor connected to the (-) input and ground, and RF (100k potentiometer), which is the feedback resistor, which is connected between the (-) input, and the output, and creates a voltage gain factor. The voltage gain factor (AV) is a multiplier. Once we determine the AV, we multiply the voltage at the input by the AV, and we have our output voltage. The 100k pot is used to vary the voltage gain. This will either increase the sensitivity or decrease the sensitivity of the circuit. The equation for AV = RF/RA in a non-inverting amplifier circuit.
For more detail: How to make a Clap-Clap on / Clap-Clap Off switch circuit! using PIC10F222
- How does the software detect the clap sequence?
The software waits for an initial loud noise, then starts a countdown; if another loud noise is detected within about 250 milliseconds, the relay toggles. - Can this circuit be built with hardware only?
Yes, the article mentions that a hardware-only version exists, though the primary focus here is on a circuit requiring a simple program. - What determines the sensitivity of the circuit?
The 100k potentiometer acts as a feedback resistor to vary the voltage gain factor, which increases or decreases the circuit's sensitivity. - Does the device work if the claps are not in quick succession?
No, the claps must be in quick succession, specifically within about 250 milliseconds, otherwise the program resets. - What type of power supply is recommended for this project?
A 9v battery is sufficient to drive the circuit, as it can operate with 7VDC and up. - Why was the LM78L05 chosen over the LM7805?
The LM78L05 was selected because it is a low-power device suitable for the small space available, whereas the LM7805 would be too large. - How many op-amps from the LM324 chip are utilized?
The LM324 quad op-amp IC contains four op-amps, but only two are used for this specific circuit. - Is the decoupling capacitor mandatory when using a battery?
No, the 0.1uf ceramic decoupling capacitor is optional when using a battery but is considered good practice.

