How to make a Clap-Clap on / Clap-Clap Off switch circuit! using PIC10F222
How to make a Clap-Clap on / Clap-Clap Off switch circuit!
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 =)
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
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:
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.
We recommend EasyEDA for electronic circuit design.
From Schematic Drawing to PCB Production, Just Need One Tool
Cheap PCB Prototype: 10 pcs 2 layers only $10, quick delivery, 100% E-test
Current Project / Post can also be found using:
- clap light circuit diagram
- clap on clap off circuit
- use of PIC microcontroller in clapping
- clap clap sensor 5v batery