Control Christmas Lights With Music - Arduinio - Microphone

by JakMarsh in Outside > Backyard

190 Views, 2 Favorites, 0 Comments

Control Christmas Lights With Music - Arduinio - Microphone

image1 (1).jpeg

This Christmas light controller will flash the Christmas lights on your house to music played from an external speaker.

THIS IS THE SIMPLEST WAY OF DOING THIS WITH THE LEAST AMOUNT OF EQUIPMENT

This method also has a toggle switch so that you can turn all of the lights on for when you are not playing music. I haven't seen any other tutorials include something like this, which I think is really important especially if your neighborhood has a noise ordinance, or you just don't want to play music all night long, so use my tutorial :)

You don't need to connect this device to the actual sound system, making it a lot simpler, and portable. I will admit this might not be the best option for indoor light control, because the relay board can be a little bit loud. Fix this by getting a digital switch module and change the code and wiring accordingly. This shouldn't be too hard. You'll probably have to change just a couple lines of code.

This device blinks the lights according to VOLUME rather than PITCH. Using pitch would require a Fourier Transform, which is not too difficult, but the cheap microphones compatible with Arduino are probably not good enough to make the lights look good. In the future, I am planning on creating a new controller that uses an aux cord to get the exact sound data, then adjust the code to account for the sound frequency instead of volume.

***WARNING*** Be careful when dealing with electric parts. Just in case, you may want to handle with rubber gloves and have a fire extinguisher nearby when connecting to power. This is all safe, but there is a chance of sparking.

Supplies

Assemble and Wire Arduino

Christmas lights circuit schematic.png

For these Christmas lights, follow the diagram I provided to wire up the Arduino. The diagramming application I used automatically assigned the wires to different pins on the Arduino. I did NOT use the pins it shows. This makes the code different than what you will need. Just make sure you go through and change all references to pins in the code to the pins you end up using so that it all runs.

THIS INCLUDES THE NUMBERS IN THE RELAY ARRAY AT THE TOP OF THE CODE.

I also used an 8 channel relay instead of a 4 channel relay, so the pins referencing the 4 modules I ended up using will probably differ from yours. This diagram uses a 4 channel relay. If you use 8 channels, wire it the same way, but you will take up 4 additional pins on the Arduino.

I suggest gluing all the pieces to a board once they're all wired, or before if that's easier. I didn't, which made transporting, handling, and wiring the extension cords way more difficult than it needed to be. 

Program the Arduino

Use the Arduino code attached. Make sure to adjust references to the pins with the pin numbers you wire in. Read the comments in the code to help with understanding, and adjusting it so it works best for you. After this point, you should be able to test if your hardware and software works so far. You can test with your phone speaker or even your voice.

Wire the Extension Cords

After you wire everything correctly on the Arduino, you are going to take 4 extension cords, or however many relay modules you choose to use and cut them up. For this, use very short cords, this will make handling much easier.

Cut the outer coating off for a section about 6 inches long. This may find this to be too short, but you can always cut more off, but you can't put more on.

At this point you will have exposed three smaller wires, one black, one white, and one teal/green. Black is the hot wire, white is the neutral wire, and green is the ground wire. The current is essentially carried on the hot wire, then comes out the neutral wire, and then the ground wire is used for any extra charge that isn't handled by the neutral wire, protecting you incase of a short. Electricity is traveling from high to low, so hot -> neutral or hot -> ground, so you don't want to cut the neutral or ground wires because the circuit can still be complete, but could be more dangerous. Whenever creating a switch in any setting, you will cut the hot wire, which is what you are doing here.

Cut the black wire.

Then use a wire stripper to strip the rubber off about half a centimeter to the end of each of the ends. You can twist the copper here if you want, this might make it easier to wire into the relay modules.

The modules will have 3 ports. The middle is the common contact (CC), one end will always go in here. The left is the Normally Open (NO) port, the right is the Normally Closed (NC) pin. This sets the toggle function on the relay (if sending a signal to it turns it off or on). I used the NO.

Unscrew the lock on top of each port, stick the ends of  the hot wire all the way into the NO and CC, then screw the locks closed so the wires don't pull out easily.

After this I used electric to wrap around the wires to keep them together, and organized. You don't need to do this, but it may help.

Repeat this for each relay module.

Testing and Tuning

SANITY CHECK:

You can test if it all works by running the program on the Arduino without the lights plugged into the extension cords. The relay will light up if they receive power. Depending on which relay ports you used, the modules might open or close the circuit when receiving power.

Once you plug in the lights, you might see they light up in reverse order, if this case, just switch HIGH and LOW in the blinkLights() method rather than switching the ports you've wired in. 

TUNING:

It should be all set up now. You can plug lights into each of the extension cords, making sure that the lights correspond to the module with the threshold you want. Do some testing to figure this out, or look at the code to see where the thresholds align with the module pins. I plugged power strips into the extension cords so that I could put more than one string of lights onto each module.

To tune the lights to your speaker, adjust the delay at the BOTTOM of the Loop method. This will control how often the microphone checks and reports the speaker volume.

High checking frequency will might make the lights blink more in tune with the music, but can also make the lights twitchy. Lower Frequency smooths it out, but can also throw it out of synch.

Find the sweet spot.

Also adjust the thresholds. You want the lowest threshold to be at a point so that light is on almost all of the time, but still flashing a bit. The highest threshold should be reserved for peaks in the volume. Find a range that looks best to you. 

This video is of me testing all 8 channels on the floor of my dorm room.

ALL DONE!

Plug the extension cords into the Christmas lights outside our powerstrips with the lights. Play your music from an outdoor speaker and set up the controller nearby. Upload the code to the Arduino and watch it go.

I put the controller into a plastic box to protect it from the elements. You may want to keep it elevated so that it doesn't get wet.