[DIY120]
Zedomax DIY120: Voice Activated Christmas Lights
In this article we’ll show you how to build a Christmas light controller! The basic concept can easily be expanded to many individually-controlled circuits. Any predefined animation pattern can be displayed, and the system can also respond to voice or music.
First of all, check out the video to see how everything works.
Voice Activated Christmas Lights
Circuit Explanation
Next, let’s take a look at the schematic. I’ve constructed this circuit using a CB280 controller on a CB280-Proto board, along with an SSR4 board and several pieces of electrical hardware.
The analog portion of the circuit is based on half of an LM324N quad op-amp I had on hand. The first stage acts as an amplifier for the small signal received by the electret microphone. The second stage acts as an integrator, since we’re interested in the overall sound level rather than the actual waveform. The larger the value of C1, the slower the circuit responds to volume changes. This circuit was quickly “designed” on a breadboard and values tweaked until desired operation was achieved. No doubt a better circuit could be developed with a larger time investment, but this does the job.
Additional devices on the breadboard include a potentiometer wired as a voltage divider; this is used with an analog input on the CB280 controller as a simple speed control. There is also a pushbutton with pullup resistor, used for switching display modes. The circuit also uses the CB280-Proto board‘s integrated piezo speaker on Port 48 to indicate the current display mode after the button has been pressed.
[edit]
Building the Controller
Nothing left but to grab the hardware and a soldering iron! Here I’ve already soldered the LM324 op-amp into the CB280-Proto board.
The microphone and potentiometer are there, only need the pushbutton and we’re done soldering!
The SSR4 board is ready to go. I’ve cut some jumper wires to carry the ground signal between the terminals.
SSR4 board is has all the signal wires attached; I’ve snapped everything onto a DIN rail (handy to use if your hardware comes prepared for it).
Now I’ve run the wires over to the terminal blocks I selected for my output ports P0, P1, P2, and P3.
Using zipties, I’ve fasted the AC jacks onto the DIN rail, and started wiring them up to the SSR4 outputs.
And here’s the completed project! Ready to add custom animations or sound response to a Christmas tree or the front porch.
Code Explanation
In the following section, I will go through the controller code and explain the purpose of each part.
' Sound-reactive Christmas Light Controller ' Also contains several sequences without sound input Const Device = CB280 Ramclear ' Enable input on ADC Channel 0 Input 24 Input 25 Dim AnalogIn As Integer ' ADC Value Dim Mode As Byte ' Sequence Mode Dim LightMap As Byte ' Contains the levels to be sent to the relays Dim Speed As Integer ' Contains the speed setting Mode = 0 ' Start in voice-reactive mode LightMap = 0 ' Clear output register ' Set interrupt to first external interrupt channel on Port 20 ' Will generate interrupt on falling edge On INT0 Gosub ChangeMode Set Int0 0
In Listing 1 I’ve initialized the controller and any variables I will need. The code is pretty self-explanatory; the device type is set, the analog inputs are initialized, and the interrupt for the mode change button is started.
Listing 2.
' Main Program Loop Do ' Read potentiometer for speed adjustment Speed = 1024 - (Tadin(1)) ' Choose the display mode Select Case Mode Case 0 Gosub SoundReact ' Use outputs as indicator of sound level Case 1 Gosub Expander ' Sequence outputs one at a time from 0 to 3 Case 2 Gosub Contracter ' Sequence outputs one at a time from 3 to 0 Case 3 Gosub Bouncer ' Sequence outputs back and forth between 0 and 3 Case 4 Gosub Filler ' Display a bar graph that rises and falls End Select ' Write only the lower 4 bits of LightMap to the output Out 0,LightMap.BIT0 Out 1,LightMap.BIT1 Out 2,LightMap.BIT2 Out 3,LightMap.BIT3 Loop
The main program loop is contained in Listing 2. Every time the program loops, it checks the analog input that is wired to a potentiometer. The controller converts a 0V to 5V level to a number between 0 and 1023. This is used to provide a delay value to various subroutines, with the net result of adjusting the animation speed. Next, there is a Select…Case statement which chooses one of the animation subroutines to execute, based on the current status of Mode. A subroutine will put the next desired pattern into the LightMap variable. Then the main loop writes the lower four bits of LightMap to the P0, P1, P2, and P3 ports, which are wired to the SSR4 board and then to the Christmas light strings.
Listing 3.
' Responds to interrupt on Pin 20, increments current mode ChangeMode: If (In(20) = 0) Then Dim k As Byte Incr Mode If (Mode > 4) Then Mode = 0 ' Beeps the number of times that correspond to current mode For k = 0 To Mode Beep 48, 30 Delay 250 Next Delay 500 Endif Return
In Listing 3 the external interrupt connected to the pushbutton is used to increment the Mode variable. It then beeps the piezo speaker one through five times, depending on the value of Mode. Then it waits for a short time to minimize double presses and contact bounce.
Listing 4
Expander: ' Sequences light one by one from port 0 to port 3, then repeats LightMap = LightMap < < 1 ' Shift left If (LightMap.NIB0 = 0) Then LightMap = &b00000001 ' Start over Delay Speed + 30 ' Don't want to strobe to fast, might damage Christmas lights Return
The “Expander” routine is shown in Listing 4. It simply shifts a “1” through the LightMap value and returns to the main loop. When it detects that “1” has been shifted out of the lower nibble of LightMap, it resets the pattern. I’ve also added a delay of 30 to whatever speed is currently set, to put an upper limit on how fast the lights can cycle.
Listing 5.
Contracter: ' Sequences light one by one from port 3 to port 0, then repeats LightMap = LightMap >> 1 ' Shift right If (LightMap.NIB0 = 0) Then LightMap = &b00001000 ' Start over Delay Speed + 30 ' Don't want to strobe to fast, might damage Christmas lights Return
“Contracter” in Listing 5 is basically the same as “Expander” except it move the active output in the opposite direction.
Listing 6.
Bouncer: ' Sequences light one by one from port 0 to port 3, then in reverse ' Look at top nibble of Light Map. ' If a bit is in there, keep shifting left ' If we've shifted it all the way out the top, start shifting right If (LightMap.NIB1 > 0) Then LightMap = LightMap < < 1 ' Shift Left Else LightMap = LightMap >> 1 ' Shift Right Endif ' If we've shifted left (getting rid of byte in top nibble) and we've ' shifted right all the back to starting position, put bit back in NIB0 ' Also if LightMap = 0 we want to initialize it If (LightMap < = 1) Then LightMap = &b00100001 ' Start over Delay Speed + 30 ' Don't want to strobe to fast, might damage Christmas lights Return
The “Bouncer” routine in Listing 6 is basically an “Expander” followed by a “Contracter”. The starting pattern has a bit set in the upper half of LightMap that is used as an indicator of which direction to travel. Once it is shifted out the top of the bit, it will disappear and then the routine begins shifting the other direction.
Listing 7.
Filler: ' Slight changes to Bouncer pattern, so that pattern fills up and empties ' Like a bar graph rising and falling ' Look at top nibble of Light Map. ' If a bit is in there, keep shifting left ' If we've shifted it all the way out the top, start shifting right If (LightMap.NIB1 > 0) Then LightMap = LightMap < < 1 ' Shift Left LightMap.BIT0 = 1 Else LightMap = LightMap >> 1 ' Shift Right Endif ' If we've shifted left (getting rid of byte in top nibble) and we've ' shifted right all the back to starting position, put bit back in NIB0 ' Also if LightMap = 0 we want to initialize it If (LightMap = 0) Then LightMap = &b00010000 ' Start over Delay Speed + 30 ' Don't want to strobe to fast, might damage Christmas lights Return
“Filler” in Listing 7 is a modfied version of “Bouncer” that keep writing a “1” to the lower bit. This causes “LightMap” to fill up like a bar graph, and then go back down once it has filled up all the way.
Listing 8.
SoundReact: ' Receive analog input from a microphone and generate an output ' map that corresponds to sound level. Essentially a bar graph. Dim i As Byte ' Take many samples to reduce reaction time to ' a level that won't burn out our relays For i = 1 To 25 AnalogIn = AnalogIn + Adin(0) Delay 3 Next ' Divide by number of samples to get the average value AnalogIn = AnalogIn / 25 LightMap = 0 If (AnalogIn > 5 And AnalogIn < 50) Then LightMap = &b00000001 If (AnalogIn >= 50 And AnalogIn < 150) Then LightMap = &b00000011 If (AnalogIn >= 150 And AnalogIn < 300) Then LightMap = &b00000111 If (AnalogIn >= 300) Then LightMap = &b00001111 Delay 50 Return
“SoundReact” in Listing 8 listens to the microphone and determines the current sound level. It does some additional analog sample averaging to slow down the response to viewable speeds, and then it assigns LightMap according to the averaged value.
Additional photos of the project in operation:
Update:
Also Check out our other Christmas DIYs:
Christmas Controller in 5 Minutes!
Build Golf Club Training Aid Gift for 5 bucks!
Pingback: Zedomax Christmas DIY - Voice Activated Christmas Lights! | zedomax.com - blog about DIYs and Review on reviews of gadgets and technologies...
Where do you purchase the CB280 Contorller and Board?
Heh — I had something similar to this once: http://www.flickr.com/photos/clintjcl/2450662656/
^^ Unfortunately that’s all that’s left.
Interesting. Wish you had some more pics!
Me too!!!! BUt I primarily used it before my first digital camera… ):
Pingback: DJ Plasma LED Lights sync to your Music! | zedomax.com - Obsessively profiling DIYs, Hacks, Gadgets, Tech, Web2.0,and beyond.
Hi, it’s me again. You should sell these things! You saw my flickr link above, right? Stick it in a box with a fresnel lens, and it gets even trippier! Or do it in an “Infinity Mirror” configuration, like with my dad’s $400 infinity mirror (first pic, but others included in case you want to check those out):
http://www.flickr.com/photos/clintjcl/tags/infinitymirror
This has a lot of potential!
Of course, I only paid $3 for mine, at a yard sale in Phoenix.
This is a nice DIY project…What is that resistor connected between positive (+) and P1? I got every feature working and added ssr but I could not make the voice activated to work.
Hi Vic,
That one actually Garrett made, you can e-mail him directly at garrett@cubloc.com to get an answer. But I am not sure you will get an e-mail until after Thanksgiving.
Anyways, happy thanksgiving! 🙂
Hi,
I have found this project quite interesting i was wondering where i could get all of the parts, sometimes on digikey i have found that there are sometimes hundreds to thousands of the same parts and if you could provide a links list that would be great! thanks again, Peter
Hi Peter,
The main parts can be found here:
http://cubloc.com
Most of the other small electronics should be available at Digikey and other major suppliers.
For some free expert help, try e-mailing my friend at garret [at] cubloc.com and tell them Max sent you.
Max,
Any chance you guys will sell the completed projects for people less skillful with a soldering iron?
Hi Brian,
I actually didn’t make this project, Garrett, my former co-worker did. He does odd jobs on the side so you might ask him for a quote.
You can e-mail him at garrett@cubloc.com
Hi, its Peter again, i was just gonna say garret did not respond to me, ill try again. But anyway i was wondering if you would be able to tell me if I were to extend this circuit to like 8 or possibly more how would i do this? What things in the program do I need to change?
Thanks again
where can you get the boards like out of an old computer(compaq com.)