Intro: Clap and Let There Be Light
It’s been a while since I last uploaded an article. Now with my university out of the way and a stable job, free time is no longer hard to come by.
I am here to present to you a simple and maybe useful project – Clap activated Night light.
The idea is really simple. You wake up in middle of the night needing to take a drink of use the bathroom. The nearest light switch is on the other side of the room, it is the case in my bedroom, and you can’t see a thing. With a simple clap and there will be light, provided it’s not going to annoy anyone.
So, what do we need to achieve.
• Detect clap sound
• High brightness LED to achieve reasonable luminosity
• Hold the LED on for certain duration, we don’t want the thing to be on all night
• Small size
• Preferably battery powered, no tangling wires
• Easy to build
Now the material:
• High brightness LED, I use a 1W White LED with star heatsink
• Electrets microphone
• 2X Opamp, TLC272 or similar single supply, preferably CMOS type
• 100k potentiometer, multi-turns can make tuning easier
• A TS555 timer IC, prefer CMOS version
• Diode 1n4148
• 2X NPN transistor BC548 or 2N2222
• A small piece of PCB small enough
• Various resistors and capacitors
• A battery, I use a 1000mAH LiPO, 3X AAA will do too
• A battery protection circuit, necessary if using Lithium battery
• A small transparent or translucent project box, just big enough to house everything
• And if you can get a Supercapacitor, we’ll discuss that later
All these cost under $10.
Step 1: Amplifier
The first issue to tackle is the detection of clap. To make our life easier, we can cheat and say the circuit should response to any loud sound. This approach eliminates filters in the design although less robust.
A short physics lesson, sound is compression waves propagating through a medium such as air. For an electronic circuit to detect sound, this mechanical energy is needed to be translated to electrical signals. Electrets microphone is able to do just that very inexpensively. If you are interested to know more about the mechanism behind, take a read on this site: http://www.brighthub.com/multimedia/audio/articles/114495.aspx
There is a standard configuration for electrets mic, which consists of only 3 components, a resistor and a capacitor as shown.
The electrical signal coming out of the mic is tiny, only a few millivolts at best. Therefore amplification is needed. The sound quality is not our concern thus the choice of amplifier design is vast, ranging from a single transistor amp to matrices of opamp.
Single transistor amplifier is the simplest around. Using just one NPN transistor, the gain of the amp is solely determined by the raw performance of the transistor. For such amp to work properly the base of the transistor needs to be biased so that the output is half the input voltage Vcc. Forcing the transistor stay in forward active region avoiding saturation.
Since our design requires battery operation, where supply voltage is not fixed, ensuring the transistor bias voltage remains in that narrow band of forward active mode is nearly impossible. For more details on BJT operation take a read on this: http://en.wikipedia.org/wiki/Bipolar_junction_transistor#Regions_of_operation
One might say a voltage regulator can solve that, true, but most linear regulator draws at least 5mA to operate that is unnecessary waste.
Opamp or Operational Amplifiers are now our choice to be. Resorting to a simple inverting negative feedback design, two components dictate the gain. Looking at the schematic opamp IC1A has its gain controlled by R5/R4 = 330k / 1k = 330. I used two stages of amplifier to achieve the desired sensitivity, creating a total gain of 330 X 330 = 108900 or 50dB.
Why not put a 100M resistor at R5 and lose the other amp? Well here is the thing. Opamp has a limit called Gain-Bandwidth Product, usually addressed in MHz or GHz. It is the maximum frequency the amp can run at with gain of 1, unity gain. More on that at this URL: http://en.wikipedia.org/wiki/Gain%E2%80%93bandwidth_product
Our low cost CMOS opamp has Unity Gain Bandwidth at 1.2MHz and the frequency of clap sound hovers at 1 KHz, thus the maximum gain I can get on one opamp is only 1200. Given electrets mic puts out such a weak signal is just not enough in my case. It may differ in your case though.
Step 2: Analog to Digital
Next on the list is a circuit to determine when a clap sound is detected. Simply rely one fact clapping is loud can save significant amount of engineering. A comparator converts a set analog signal to digital 1s and 0s which can be easily interoperated by digital circuit. Here the peak of the sound signal is used as the determine factor, adding a peak detector wouldn’t hurt.
The comparator in this configuration will signal a LOW or ‘0’ when the peak of the audio signal is above the level set by the potentiometer R9. Why output LOW? Keep reading…
Step 3: Time Delay
At this point we obtained digital signal indicating a clap is sound. However this signal is much too short and often oscillates at the frequency of the sound. We need to extend the duration of this digital signal to something useful.
A 555 timer has mostly been used as oscillator, there is another configuration called monostable that would work wonderful here. In this mode 555 gives only a single shot at the duration of your choice once it’s triggered. More details at URL below:
I decided to hold the LED on for 10 seconds, a nice number, also give nice values for the timing resistor and capacitor.
Step 4: LED Driver
Now last but not least, LED driver, a high power LED can easily handle the job to lighten up the room. Provided the input power to the LED is controlled properly. A safe way to drive a LED is through current control. This ensures both power dissipation on the LED and protection of the power supply.
To reduce size and cost, I personally wish to avoid using heatsink, which means turn the power down on the LED. Through my experiment I discover the LED with star heatsink can handle 220mA without even getting warm, plus that is bright enough.
Taking current limiter design from the instructables written by user Dan at URL below:
I went to work selecting suitable components for the job. A little power management: since the system runs on Lithium battery or 3XAAA battery, the maximum voltage is just 4.5V the LED creates drop of 3.2V at 220mA. Power dissipates on the transistor Q1 is only (4.5-3.2)*0.22 =286mW. So we only need a transistor that can handle 300mW and 300mA continuous collector current. Luckily the readily available BC548 can do that comfortably. R12 in the schematic determines the current this limiter would allow to flow. If you read the article linked above you would know the resistor would only see 0.7V across it at max. At 3.3Ohm this current limit is set at 0.7/ 3.3 = 212mA and the power dissipated by the resistor is merely 0.7^2/3.3 = 0.15W. Therefore an ordinary 1/4W resistor can do the job.
Step 5: Construction
Our design is complete. It’s time to put it all together. You should follow the schematic to construct the circuit. Make any adjustment and modification as you see fit. I have included PDF of the entire schematics and even the PCB layout if you want to go make your own custom PCB. EAGLE files are also available in this article.
Sorry I did not take any photo during my circuit build. But if you want to build the circuit on a piece of protoboard, you can follow my layout.
Putting the circuit and the battery into the box, turn it on and it is time to tune the circuit. If your circuit never turn off the LED then the comparator is too sensitive. Turn the pot up until you see the LED does go off. Note there is a 10 sec delay we introduced to the circuit. It will be wise to be quite and wait before making conclusion. If your LED never comes on, just turn the pot the other way until it does at a sound level you are comfortable with.
Once the circuit is tested, all adjustment made. You should drill a couple holes to mount the PCB like I did in the pictures. Drill opening for power switch and make holes to let sound into the mic.
Lid it up and you are all done.
Step 6: Optional
This part is not essential.
As you might have notice the Supercapacitor on my PCB. It is only there to add the fading effect when the LED comes on and turn off. There are cheaper and more effective ways to achieve this. I use Supercaps because I can. To be honest I work in a tech company that design and make supercapacitors. So it is fairly easy for me to get hold of these high performance Supercaps. The supercapacitor is connected directly across the LED. Given the current through the LED and Supercap is constant the voltage across the LED/Supercap is charging up linearly, thus creating the fading in effect. Once the power is cut off to the LED, the energy stored in the Supercap during the on time, is now discharged slowly through the LED and the light goes out gradually.
If you decided to use a Supercapacitor, please be note that it must be able to operate at 3.5V, with low enough ESR so that Current * ESR < 0.1V. And the capacitance shouldn’t be too large, less than 0.5F.
Step 7: Conclusion
If the circuit is properly tuned it should be able to pick up a clap no matter where you are in the room, as long as the room isn’t too big.
The standby current draw by my circuit is roughly at 1mA, a 1000mAH battery has lasted me about 2 weeks of continuous operation. Of course you can chose to turn it off during the day and get much longer battery life.
Feel free to ask any question in the comment section below.
I have more interesting and complex project coming up. Thanks for all your support and patience.