In this Instructable, I show you how to build Automatically Blinking Christmas Lights when music is played! The project has 2 parts: the Electrical Circuitry, and the Arduino Code/Algorithm. The circuit works by using an 8 channel relay to close the circuit in each of the 8 individual Christmas light strands. An electret microphone captures the sound waves playing on a set of speakers and sends it into an Arduino using an analog input.
From here there are 2 options for usable programs. You can use the manual code template to manually blink certain strands of lights for specific music tracks, or you can use the automatic code which activates different strands of wire based on the frequency played.
Step 1: Obtain Materials
The materials list for this project is very mild making it a very affordable project. The list of materials and where I purchased everything (amazon affiliate links) include:
1x Arduino Uno http://amzn.to/2DcHQYg
1x Breadboard https://www.digikey.com/product-detail/en/bud-ind...
1x Electret Microphone Amplifier https://www.adafruit.com/product/1713
1x Jumper Wire Bundle 65 PCS https://www.digikey.com/product-detail/en/bud-industries/BC32625/377-2093-ND/4156446
1x Premium Female/Male Jumper Wires - 20 x 12" https://www.adafruit.com/product/1713
1x SunFounder 8 Channel Relay http://amzn.to/2FAwJWH
8x Vickerman Mini Christmas Lights (can also purchase less strands) http://amzn.to/2FEAoD1
It is also worth noting rubber gloves and a fire extinguisher are highly recommended if you are new to these types of projects. There is also a PDF downloadable version of the materials list below.
Step 2: Electrical - Connecting the Relay and Christmas Lights
The heart of the electrical circuitry is the relay. A relay is a mechanical switch which closes when a much smaller voltage is applied to the relay. This works because the smaller voltage runs through a coil of wire, which creates an electromagnet to close the mechanical switch. The switch is connected to the same cut end of each Christmas Light strand. When the switch closes, voltage of the wall outlet is able to run through the strand, creating light!
Note: DO NOT work on the Christmas light strands while the lights are plugged in!
To connect the lights to the relay, make a single cut into the light strand and strip the wire slightly to reveal a small amount of copper on each side of the cut. Once that is done, connect each copper tip to the normally open leads of 1 relay. Do this for 8 light strands.
More on how to connect the relay can be found here: https://www.sunfounder.com/learn/From-Knowing-To-...
Step 3: Electrical - Microphone and Arduino
Next, we need to connect the electret microphone to Arduino so we can start receiving sound waves as analog input. The connections are fairly simple with the microphone VCC and ground connecting to the Arduino 5V and ground respectively, the microphone output connects directly to the Arduino analog 0 pin. The images above and visual Fritzing circuit below detail how the microphone and relay board connect to Arduino.
Step 4: Arduino Code - Automatic Blinking Lights
After connecting all of the electronics, it's time to upload Arduino code! The automatic blinking lights code will cause the Christmas lights to automatically blink based on the frequency of the sound the microphone hears. The code works by using an algorithm called FHT (Fast Hartley Transform) similar to FFT (Fast Fourier Transform) to convert the sound wave from the time domain to the frequency domain.
I don't usually like to use specialized libraries when I write code, but the library over at open music labs was extremely easy to work with and made this project a lot quicker! The code will be available on my GitHub repository: https://github.com/RoboAvatar65/LightControl
Step 5: Arduino Code - Manual Blinking Lights
My GitHub repository also contains code for manually blinking lights. The manual code in this repository is currently calibrated for Carol of Bells but you can change the code to blink to any song by following the same pattern I use in this code! The code will also be available on GitHub: https://github.com/RoboAvatar65/LightControl
Step 6: Setup the Lights and Run the Code!
Places your lights where you want them, upload your code to the Arduino board and watch your light show! Once you're done and it works, you can power your Arduino with a 9V battery so you don't need to keep your laptop nearby. Enjoy the show!