Use an Arduino to set up a Christmas light show in sync with music.

1 Arduino Uno
3 74HC595 IC (1 for each of 8 channels)
3 8 channel relay board (1 for each of 8 channels)
1 1μF capacitor

This project will teach you how to sync your Christmas lights to music. You can use the same technique to control stage lights and fog machines (that don’t have DMX) with a computer to achieve wonderful synchronization for performances on stage, which is not always possible with manual lighting control consoles.

During last year’s holidays, I was watching videos of Christmas songs on YouTube, and the video above of Christmas lights flashing to the music caught my eye. So I decided to make my own Christmas light show with Arduino. I was wondering how I would sync the lights with a song and send data in sync with a song. I got the idea to use MIDI signals when I was working with a song using sound editing software. I hacked the MIDI signals from the software (which was in sync with a song) and turned them into light control data.

How Does It Work?

Controlling Lights in Sync With a Song

1a-2.jpg

Above is a screenshot of Studio One DAW software (digital audio workstation software) that I used for this project. The MIDI track in the DAW software is in sync with a song. I turned the notes from C3 to E6 (excluding sharp notes) on and off in the MIDI track to control the lights. I used Hairless MIDI to serial bridge to send the MIDI signals to the Arduino and programmed it to turn specific relays on and off according to the notes received. Now the DAW software controls the lights according to the song’s rhythm. I did not use sharp notes (the black keys) because, if you have a real MIDI keyboard, you can program the lights with it. You can play a Glissando and control all the lights!

Block Diagram: Christmas Light Show With Arduino

block.jpg

The Circuit:

2a1.jpg

The lights are connected to the relays on the relay boards. The three 74HC595s are used to control the relays. Three bytes are used to store the light states in the program (on/off). The music software sends out the MIDI data, which is received by the Arduino and sets the corresponding bit of one of the three bytes to 0 or 1. The three bytes are shifted out of the registers and then are latched on so the relays turn on/off. After all the bytes are sent and the process is finished, they are latched, which prevents the relays from turning on/off while shifting the data. Now get ready to build your own Christmas light show with Arduino!

Building the Circuit for Our Christmas Light Show With Arduino

Set up the circuit as shown in the diagram and connect an external relay power source. Remove the jumper in most relay boards. Since it is not recommended to draw the power needed for working on relays from the Arduino board.

PLEASE NOTE: If you are powering the relay board with 12V, make sure that there is no connection (by accident) between the external relay board Vcc (12V) and the 5V on the relay board (remove the jumper seen in most relay boards). If there is any connection, it can destroy the Arduino and ICs.

Setting Up the Software

  • Install Studio One (or any DAW software). I used Studio One 2 Free. Most of the features work in the free version.
  • Install loopMIDI for creating a virtual MIDI port.
  • Run loopMIDI and start a virtual MIDI port.
  • Set up the loopMIDI port as a new instrument in the DAW software.

To do that in Studio One 2, Press Ctrl+, Go to ‘External Devices’ >Add > New Instrument > Send to: loopMIDI port > OK > OK

3a-2.jpg

Open this file for the song "Carol of the Bells", click the area shown below and select New Instrument.

4a-2.jpg

If you are not using Studio One, you can start a new song, create a MIDI track, and send its output to the newly created instrument.

Upload the Christmas Light Show Code to Your Arduino

Download the Christmas light show code, or copy and paste it from below.
/* Christmas New year light show with Arduino
*  by Akshay James
*  My blog: techmusician.wordpress.com/2017/01/01/the-arduino-lights-project/
* 
* This project was inspired from a YouTube video by John Storms
* from his channel ListenToOurLights (http://www.youtube.com/user/listentoourlights).
* Thank you.

* GND (pin 8) to ground,
* Vcc (pin 16) to 5V
* OE (pin 13) to ground
* MR (pin 10) to 5V
* 
* DS (pin 14) to Ardunio DigitalPin 9 (blue wire)
* SH_CP (pin 11) to to Ardunio DigitalPin 8 (yellow wire)
* ST_CP (pin 12) to Ardunio DigitalPin 10 (green wire)
*/

#include"notes_bits.h"

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 9;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 8;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 10;

int pitch, cmd, velocity;
int light;
boolean state;

byte lightData1 = 0, lightData2 = 0, lightData3 = 0; //

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);  
pinMode(clockPin, OUTPUT);
Serial.begin(38400);

}

void loop() {

//read the midi signal
if(Serial.available()>2) {
cmd = Serial.read();
pitch = Serial.read();
velocity = Serial.read();

//the lights are set according to the data on MIDI ch.1
if(cmd==144) state=0;               //144 ch1 noteON ; 0=relayON
else if(cmd==128) state=1;        //128 ch1 noteOFF  ; 1=relayOFF

// so that lights don't change while the new data is being shifted
digitalWrite(latchPin, LOW);

light = getBit(pitch);
// set the corresponding bit in lightData
if(light<8)
bitWrite(lightData1, light, state);
else if(light<16){
light-=8;
bitWrite(lightData2, light, state);
}
else {
light-=16;
bitWrite(lightData3, light, state);
}

// shift out the data
shiftOut(dataPin, clockPin, MSBFIRST, lightData3);
shiftOut(dataPin, clockPin, MSBFIRST, lightData2);
shiftOut(dataPin, clockPin, MSBFIRST, lightData1);

// turn on the lights according to the new data
digitalWrite(latchPin, HIGH);

}
}

Also, make a notes_bits.h file. Copy and paste the code below to it or download it from here.

/*Which bit has to be turned ON or OFF is found
* with the below function.
* 
* The range of music notes used for the control
* of lights is from C3 to E6.
* (sharp notes are excluded)     (total 24 lights)
* 
* So, this function will return the number of the bit
* to be set.
* For eg, C3(note 62) corresponds to the first light,
* So this function will return '1'.
* 
* Similarly, '2' is returned for D3(note 64), etc.
* 
*/

int getBit(int p) {
switch(p) {
case 60: return 0; //note C3 (middle C)
case 62: return 1; //D3
case 64: return 2; //E3
case 65: return 3; //F3
case 67: return 4; //G3
case 69: return 5; //A3
case 71: return 6; //B3
case 72: return 7; //C4
case 74: return 8; //D4
case 76: return 9; //E4
case 77: return 10; //F4
case 79: return 11; //G4
case 81: return 12; //A4
case 83: return 13; //B4
case 84: return 14; //C5
case 86: return 15; //D5
case 88: return 16; //E5
case 89: return 17; //F5
case 91: return 18; //G5
case 93: return 19; //A5
case 95: return 20; //B5
case 96: return 21; //C6
case 98: return 22; //D6
case 100: return 23; //E6
}
}


Setting the Baud Rate

Connect the lights and power to the relay board and connect the Arduino to your computer. Then open Hairless Serial to MIDI bridge and select the Arduino port as the serial port and MIDI in port as loopMIDI.

Then, go to File > Preferences > Set the Baud rate to 38400 > OK.

We have to change the baud rate because we need it to be higher than the MIDI’s baud rate, which is 31250. If the baud rate is below that, we will have a noticeable delay in the lights.

5a-2.jpg

Then tick the Serial<->MIDI bridge option. 

To start the lights: 

Go back to Studio One and play the song. You should see the Green LED in Hairless Serial to MIDI bridge blinking. If that is there, then your relays should also work. 

Now you will see your light show in sync with the song! You can do the circuit on a line or dot PCB. I did it on a line PCB. This is how it looked after connecting everything.

6a-2.jpg

I also connected an external amplifier and speaker to the computer and kept it outside the house for my Christmas light show. Here is the final working video of my Christmas light show with Arduino:

This project was inspired by a YouTube video by John Storms from his channel ListenToOurLightsThank you, John!

Akshay James

Contributors


Forks

Related Projects