Zedomax DIY120 – Voice Activated Christmas Lights
[DIY120]
[gv data="05RBvHnHD7Y"][/gv]
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
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
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!


















































