USB powered clapper switch - Extremely little HW Required!

 by EngineeringShock
Featured
DSC_0094.JPG
Hi all!
Thanks for having a look at my instructable!  If you have by chance seen my original clap-clap on/clap clap off circuit instructable.  This clapper circuit is very different than my original, in that it requires absolutely no amplification of the audio signal being sampled by the on-board electret microphone! As well, the circuitry is powered exclusively by the USB port on my PC!

For all of you who find this instructable interesting, I would apprecaite your vote in the USB contest.  As well, please rate this instructable.  If you found it to be good, I want to know!  If you found it needed work, I want to know!  Thank you for your consideration!
I'll be creating a kit for this instructable within the next few weeks, but without the relay. It will be available here:
http://www.electroniclessons.com 
Or here:
http://ww.engineeringshock.com

Here are some of the key features:
* By simply turning your computer on, you can clap-clap on anything powered by AC that is within the limit of the 5v relay you are using (A desk lamp for example - Seen in the below video)

* EXTREMELY LITTLE HARDWARE REQUIRED!  Less than $10

* No amplifier circuitry required.  The audio is sampled through the use of an ADC (Analog to Digital Converter), located on the MCU.

* Powered SAFELY by the USB port on your PC or laptop.

THIS VIDEO TALKS ABOUT THE PROJECT, GIVES YOU A DEMONSTRATION, AND TALKS ABOUT THE SCHEMATIC DIAGRAM! 
                             
 
Remove these adsRemove these ads by Signing Up

Step 1: How It Works!

DSC_0083.JPG
DSC_0084.JPG
DSC_0092.JPG
DSC_0093.JPG
DSC_0094.JPG
DSC_0095.JPG
There are many different variations of the clap circuit.  You can have circuits that activate when it hears a loud noise (clap), and deactivates when it hears another.  Typical clap circuits, such as the one I created in my second instructable requires two loud noises (claps) within a very short period of time to activate the circuit, then anoother two claps do deactivate the circuit.  This is all done through simple programming. 

The electronic hardware is very limited, which is great, as most of us don't have a ton of money to spend on our side projects.  I'm very proud of this fact.  I've never seen any version of the clapper that used an ADC to sample for noise.  All of my previous clap circuits, and all of the other clap circuit variations that I've seen require either passive or active amplification.  It took a bit of time to get the programming right.... I had to make many changes to several timing registers before I was content with the result.

The CIRCUIT SCHEMATIC on the following page includes an in depth analysis of the simple circuitry involved.  You should have no problem following along.  For now, let's talk about the basic theory behind the circuit.  As well, if you've watched the video, you'll have seen a schematic breakdown from myself personally.

Step-By-Step:
1)  As soon as the devive is plugged into the USB port of the computer, it becomes active.  By active, I mean that is is constantly scanning for loud noises, such as a clap.

2)  As soon as the device detects a loud enough noise, it starts a countdown sequence.  In this very short time, the device is constantly scanning for a second loud noise.  The duration of the countdown sequence is under 600 milliseconds. 

3) If within the period of the countdown sequence a second loud noise is detected, the microprocessor activates a relay, which is connected to an AC power source, and a load that requires AC (A lamp, fan, LCD,etc).  If the countdown sequence elapses without another noise being detected, then the program starts over, and scans for an initial loud noise.  This is to ensure that two claps are required for activation, not just one.

4)  If the device detected two claps, your relay is now activated, and your AC device is powered.  The program now goes into an extremely similar area of the program that basically mimics the first part of the program.  It waits for another set of claps, only this time the relay will deactivate if two claps are detected. 

5)  If two more claps are detected within the countdown sequence, the relay is deactivated, and the AC device turns off.  The program then starts over.

It is a very simple programming algorithm.  I decided to use the PIC10F222 Microprocessor (MCU), which is EXTREMELY cheap - Less than $1 if purchased in bulk).  The problem with the PIC10 series, is that it is an archiac MCU, and it comes without the BTG (Bit toggle)  and COMPARE commands.  This made programming the MCU a pretty large pain in the butt.  It requires a lot more code, and a TON more patience.  I've provided the code in the SOFTWARE step, so have a look at it.  I've done my best to comment the code, so try to follow along with it!

NO AMPLIFIER???
That's right!  No amplifier!  The coupled signal coming from the microphone is so small that it typically requires amplification in order to be compatible with the PIC.  What I've done here is, through programming, taken readings from the ADC, and looked for signals in the 20-40 millivolt range (0.02-0.04 volts).  If the noise is loud enough, the ADC is able to pick up that small signal, and turn it into a hexadecimal value, which is then compared against a pre-loaded value.  If the signal is stronger than 20mv, then it is accepted by the programming as a "CLAP".

THE ADC:
The PIC10F222 has an internal ADC capability that allows for the user to sample an analog signal between 0v and 5v.  This analog value is then turned into a HEX value based on a binary number.  This is an 8-bit HEX value. 
If we have 5v at our analog input, and we take a sample, the value in the ADC register will be "1111 1111, which equals FF in HEX"
If we have 0v at our analog input, and we take a sample, the value in the ADC register will be "0000 0000, which equals 00 in HEX"
In the programming, I run a routine that samples the voltage at the ADC input, and if the value is 0000 0001 (01H) or greater, it is recognized by the program as a "Clap".
 
COMPONENT LIST (Using USB as the power supply):
* Electret/Condenser microphone
* PIC10F222 MCU 8-pin DIP IC
* USB cable
* Terminal Block
* 5v relay
* NPN small signal transistor, such as 2N2222, 2N4401, or S9013
* Dollar Store power bar
* Resistors: 470R / 100k / 2x 10k
* Red LED
* N4004 diode
* Capacitors: 2x 0.1uf / 10uf
* Prototyping PCB (5cm / 7cm)

TOOLS REQUIRED:
1) Soldering Iron
2) Glue Gun
3) Safety Goggles
4) Patience
5) Some soldering experience

GlennFTW says: Apr 28, 2013. 4:25 AM
Hi. I have a problem when transferring the hexfile into my pic10f220 :/
It's says that the OSCCAL value in invalid, and i can't "Auto regenerate" it.
So I wondering if you know the OSCCAL value so I can set I manually?
(Error: 0x000000)
Thanks! :)
nodoubtman says: Nov 28, 2012. 4:07 PM
It is possible to do it with pic12f683 : http://embedded-lab.com/blog/?p=6439

thank you!
marC:)
jukees says: Nov 11, 2012. 12:56 PM
hello do you think that it's possible to use pic12f675 instead?
hamouz718 says: Jan 23, 2012. 4:59 PM
I managed to write your code in C so the code can work with most MCUs, can u tell me how long are the delays in your asm code?

Cherz
jimuguano says: Jan 5, 2012. 6:23 PM
(removed by author or community request)
EngineeringShock (author) in reply to jimuguanoJan 5, 2012. 8:00 PM
If you have the capability to compile and load Microchip templates for PICs (Found at microchip.com), then this should work. Even if it doesn't, the problem is usually easy to troubleshoot. I don't know how to make HEX files out of the program.

Sorry
Pat
hamouz718 says: Jan 5, 2012. 6:06 PM
Dude this is amazing!
I understood the most of the steps except for the code, could u plz upload a flowchart of the code if possible?
ssanthosh says: Jan 4, 2012. 6:16 AM
Can u please E-mail me the diagram of this clap switch that works without connecting to the usb port
My email id is sanjvwin10@gmail.com
ssanthosh says: Jan 2, 2012. 6:55 AM
can i connect the ac power directly without using a power bar?
cjlopez213 says: Jul 25, 2011. 11:06 PM
This is exactly what I was looking for! However, I am a bit confused, do the claps only turn on one specific object? Or can they turn on any object connected to the power strip?

I'll wait until the kit comes out to make things easier, thank again for the instructable!
EngineeringShock (author) in reply to cjlopez213Nov 23, 2011. 8:26 AM
Kit is on the way! Custom PCB and all =) By Christmas. The PCBs have been manufactured, and are on the way to my home. Check out engineerigshock.com for all of our new kits =)
EngineeringShock (author) in reply to cjlopez213Jul 26, 2011. 5:30 AM
Hi there
Yes, anything on the power bar can be turned on. You have to keep in mind the power rating of the Relay, as the leads can only handle so much power. These relays can handle a ton of current, but I wouldn't use it to power your microwave =) Thanks for the comment!
Pat
ggallo says: Nov 4, 2011. 2:43 PM
We want the kit!
EngineeringShock (author) in reply to ggalloNov 23, 2011. 8:26 AM
Kit is on the way! Custom PCB and all =) By Christmas. The PCBs have been manufactured, and are on the way to my home. Check out engineerigshock.com for all of our new kits =)
_Ludo says: Nov 21, 2011. 8:06 AM
Nice!

I had to adapt the detection level to 5D = 0000 0101B because the relay was going to ON and OFF in a loop. I guess this is due to the very low level of detection and to wireless like Wifi or alike.

Thanks for this nice project, I'll maybe amplify the mic with a single transistor.
EngineeringShock (author) in reply to _LudoNov 21, 2011. 9:23 AM
Thanks!
I'm wondering why you had to change anything. You shouldn't need to amplify the mic signal, as the ADC should pick up the smallest sounds. However, changing the value in the detection register can easily change your sensitivity. Did you use the same components?

So glad someone re-created this. Do you have a video?

Thanks again
Pat
airabaxter says: Oct 14, 2011. 3:19 PM
I have a small knowledge of basic electronics and it ends on repairing TVs and radios only. This is a nice tutorial. Thank you for sharing it..

sams club credit card
leandro0012 says: Jul 19, 2011. 8:56 AM
This is great. I have tried the clap clap on/ off circuit you did and works nice. But this is even better because you don't need any amplifier. I think I could do it with a PIC 12f629. Nice job!.
PS: Is it possible to use a triac instead of a relay switch?
EngineeringShock (author) in reply to leandro0012Jul 19, 2011. 9:21 AM
Hi there
Thank you for the comment =) As long as the Triac will turn on completely using a 5v signal, and is properly heat sinked, then I think it'd be a great idea =)
Let me know how it turns out! If you have time, please rate my instructable.
Thanks again for the comment. If you end up making a video, please send it my way!

Thanks
Pat
Electronics Man says: Jul 19, 2011. 6:35 AM
Great job! I have been working on one of theese but I was worried about the amplifier circuit...BUT NOT NOW!!!
EngineeringShock (author) in reply to Electronics ManJul 19, 2011. 7:20 AM
Hi there
Thanks for the comment =) If you still want to incorporate an amplifier, check my channel out. I hvae a another clap clap circuit that incorporates a simple active amplifier (LM324). Thanks again take taking an interest. Please rate my instructable if you have the time =)

Sincerely,
Pat
saraandy says: Jul 18, 2011. 12:47 PM
This is the first time I have visited your site and I am amazed at the amount, the value and the clarity of the information you have provided. This was beautiful and very thought-provoking.
HP LaserJet P1102w
EngineeringShock (author) in reply to saraandyJul 18, 2011. 5:27 PM
Thank you very much =)
Rolcrz says: Jul 18, 2011. 3:57 PM
I absolutely love this project and would like to try it out myself. However, just one question, is there a less expensive programming kit that we could use to program the pic10f222? I'm asking because from what I've searched the kits are extremely expensive, specially for something that i'll use maybe once or twice =/ thanks in advance! Great instructable btw =)
EngineeringShock (author) in reply to RolcrzJul 18, 2011. 5:26 PM
Hi there
Thanks for the comment =) In the coming week, I'll be placing a kit in my ebay store for this. It will include the programmed PIC, the microphone, and all of the other passive components, minus the relay and relay driver. If you are still interested in a week, and you don't see the kit in my store, let me know =)

Thanks!
Pat
frank26080115 says: Jul 18, 2011. 10:21 AM
You know those dirt cheap tiny USB wall chargers? You should build that directly into the AC line (before the relay so it's always on) to power your 5V circuitry.
EngineeringShock (author) in reply to frank26080115Jul 18, 2011. 11:28 AM
Good call.
However, I wanted to have this interfaced with my PC. As well, the dollar store power bars are hard to modify internally. The bars are connected in parallel through metal bars, not wires, which means you have to but the bars internally. I've tried, and it can get messy. Good call though. I see what you're getting at =)
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!