The other day when I was at the reuse center I came across a few ikea lamps. I picked up two low voltage spot lights for $2 total. I think they came from this lamp. I also bought a moon lamp for $0.86 and I am still not sure why they charged such an odd amount for it. I wasn't too sure about the moon lamp, but I knew right away what I would do with the spot lights. It wasn't even 12 hours prior that I was trying to sketch up an idea on my slate chalkboard in low light conditions and thought I needed some task lighting. That distraction was what spawned this project.
Surely these lights would do great on their own with just an on/off toggle switch, but where is the fun in that? So, I decided to make a clapper circuit that turned out to be something a little more too.
A "Clapper" is a device that will turn on or off an AC appliance that is plugged into it, such as a lamp or fan when it "hears" you clap twice in approximate succession. They were originally sold in the mid eighties and it appears you can still buy them today.
In my version of the clapper if you clap twice within one second, the circuit toggles the lamp output. On becomes off and vice versa. If you clap three times within one second, the lamps begin dimming up and down via PWM until a fourth clap is detected or a one minute timeout occurs, whichever comes first. The brightness value is then stored and restored for subsequent toggling of the lights on/off with the two clap event. I also added a relay output to turn on and off the moon lamp. To trigger this relay, you shine a laser beam at the circuit to toggle it. Laser beams begets moon beams. It's science.
Here is a video of the Clever Clapper in action.
In case you are confused by the title of this post being the Clever Clapper and the text on the chalk board that says The Dandy Dapper Clapper you should know that the Clever Clapper is the hardware that a Dandy Dapper Clapper uses to clap his or her way to optimal lighting conditions.
These spot lamps didn't come with anything other than the lamp and holder. I needed a way to hold the holder so I banged a couple of nails into a some poplar wood to attach the lamp holder to. Ok, so I didn't "bang" these framing nails into the 1" x 2" bit of poplar wood so much as I drilled a hole slightly smaller than the O.D. of the nail and pressed them in, but you get the idea. This is not a finished installation; just the prototyping stage.
Here is a pic of the lamp, lamp holder, lamp holder holder and the lamp holder holder holder ( aka wall ).
Since we are talking about mechanical stuff, below is a picture of how the circuit and moon lamp are mounted to a piece of red oak. The wood board was drilled and tapped to accept aluminum standoffs to screw the circuit board and TIP120 heatsinks to.
Here are a couple of pictures showing the inside of the moon lamp. I added this black box with relay inside to control the hot AC line of this lamp with a microcontroller.
You can download a .rar of the ATTiny2313 code and Clever Clapper circuit schematic here.
There isn't much to say about the software except that there may be some "legacy" code in it still. That is, variables and the like that I didn't delete when changing things around or removing functionality so the program would fit into the available program space.
Below is a picture of the schematic. Starting at the top left you can see an electret microphone and it's filtered power supply. This is fed into one half of an LM358 Op-amp setup for 100x amplification. The 100k0 potentiometer is used for clap detection sensitivity adjustment. There is a connection to PD3 here that is no longer used, but more on that later. Then, the signal, or more accurately, part of the signal passes thru a low pass filter and on to the other half of the LM358 setup as a comparator. The output of this comparator stage is fed to the ATTiny2313. Otherwise the circuit is pretty straight forward, standard 7805 power supply and uC accoutrements, TIP120 darlington transistor with pulldown resistors. Oh, and don't forget that 1n4004 flywheel diode across the relay coil or you will be replacing your uC in very short order.
Here is a close up of the circuit. You can see the electret mic in the lower middle. There are two phototransistors on the board but only one is connected. They are the clear things with one at the center top of the ATTiny2313. There is also a red tactile switch who's input to the microcontroller is interpreted as two hand claps. This is used in the event you want to be quiet and still toggle the lights on and off.
When I first started this project I knew that I wanted to detect hand claps. As a human, I am quite good at this but, I had no idea how to describe a hand clap to a microcontroller. So, to "see" as a digital device would, I opened Audacity and started clapping my hands. Below is a picture of the spectrum analysis. To help prevent false triggers, it appears I can easily block non-clapping frequencies above ~5khz. This significantly improved the reliability of the circuit.
As I alluded to earlier I was not able to implement all of the features I wanted in my clapper. This is because I ran out of program memory. The last build used 100.0% of the available space. Of course I could have re-written the code trying to optimize for space or more likely I will just use a different uC in subsequent hardware iterations, should I decide the current implementation is prosaic. I feel code and hardware optimizations are a worthy subject of focus, but too, sometimes you just want to get the job done.
Here is a video of one feature that didn't make the cut due to the lack of program memory space. This mode would have been activated by a succession of four claps. In this mode, the raw speaker input ( pre-lowpass filter ) is fed to the microcontroller and modulates the PWM output to the lamps. The light looks like it is "talking" to you. It is a little hard to see in the video as I think the automatic white balance function of the video camera takes some of the resolution away. I was sad to see this feature go.
Over all I am quite pleased with the Clever Clapper. It is a lot of fun walking into a room and command-clapping lights to turn on - to your desired brightness value no less. I have yet to decide if I want to remake the hardware to allow for more features. I may, as one feature I wanted was clap programmable clap codes for instantly setting different lighting moods.
// clap off