Zedomax DIY120 - de Stem Geactiveerde Lichten van Kerstmis
is klaar te gaan. 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!
Got a new hack, DIY, howto, or gadget? Tip us here.
Search for a Hack:
Bookmark It!
|del.icio.us |Digg it |Netscape |SiteHoppin |Wagg It | TrackBack |
Email this to a Friend
Email This Page


[...] [...]
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… ):
[...] Voice-activated Christmas Lights alarm clock computer, Audio, christmas, christmas-lights, Consumer, dj, favorite music, Gadgets, how to make music, lightning, lights, Music, orb, plasma, power switch, strength level, sync, tube lamp, tube length alarm clock computer, Audio, christmas, christmas-lights, Consumer, dj, favorite music, Gadgets, how to make music, lightning, lights, Music, orb, plasma, power switch, strength level, sync, tube lamp, tube length var dc_UnitID = 14; var dc_PublisherID = 13853; var dc_AdLinkColor = ‘blue’; var dc_adprod=’ADL’; If you like this post then please subscribe to my full feed RSS. You can also subscribe by Email. Got a new hack, DIY, howto, or gadget? Tip us here. [...]
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.