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 =)