Tutorial: The Music Light Show

This Arduino project creates a music light show by controlling a number of lights according to a song in correct sync with the music. It uses MIDI signals from a music software running on a computer to sync the lights with the music.

Featured on Hack a day: http://hackaday.com/2017/02/01/a-very-midi-christmas-lightshow/

This Arduino project can be used to control stage lights and fog machines (which don’t have DMX) with a computer and achieve wonderful synchronization for performances on stage which is not possible with manual lighting control consoles.

During last year’s holidays, I was watching Christmas song videos on Youtube and this video of Christmas lights flashing according to the music caught my eye. So I decided to make one of those with an Arduino. But I was wondering how I would sync the lights according to a song or how I would send data in sync with a song. I got the idea of using MIDI signals for that when I was working with a song on a sound editing software. So I hacked the MIDI signals from the software (which was in sync with a song) and turned them into light control data.

What are the stuff required to do this?

An Arduino
74HC595 IC (3 nos.) (1 for each 8 channels)
8 channel relay board (3 nos.) (1 for each 8 channels)
1μF capacitor

How did I control the lights in sync with a song?


This is the screenshot of Studio One software (Digital Audio Workstation software) that I used for this project. The MIDI track in the DAW software is in sync with a song. So I turned on/off notes from C3 to E6 (excluding sharp notes) in the MIDI track for controlling the lights. I used ‘Hairless MIDI to serial bridge’ to sent the MIDI signals to the Arduino and programmed it to turn on/off specific relay according to the notes received. So now the DAW software actually controls the lights according to the song.

I did not use the sharp notes (black keys) because, if you had a real MIDI keyboard, you could program the lights with. You could play a Glissando and control all the lights! :p (what is a Glissando?)

Block diagram:


The Circuit:

Untitled-3 blog.jpg

The lights are connected to the relays on the relay boards.

How it works:

Three 74HC595 s are used for controlling the relays. Three bytes are used for storing the states(on/off) of the lights in the program. The music software sends out the MIDI data and the Arduino receives it and sets the corresponding bit of one of the three bytes to 0 or 1. Then the three bytes are shifted out to the registers and then that is latched on so the relays turn on/off. All the bytes are sent and only after that is finished, they are latched and that prevents the relays from turning on/off while shifting the data.

Step 1:

Set up the circuit as shown in the figure 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 of the relays from the Arduino board.


Step 2:

Set 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


Open this file for the song ‘Carol of the bells’ and click the area shown below and select New Instrument.


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

Step 3:

Copy and paste this program:

(Or download form https://github.com/AkshayJames/arduino-midi-lights/blob/master/christmasLightsMIDI.ino)

 * 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)


//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);

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
 bitWrite(lightData1, light, state);
 else if(light<16){
 bitWrite(lightData2, light, state);
 else {
 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 from https://github.com/AkshayJames/arduino-midi-lights/blob/master/notes_bits.h)

 * 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

Step 4:

Connect the lights and power the relay board and connect the Arduino to the 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 baud rate of MIDI which is 31250. If the baud rate is below that, we will have a noticeable delay in the lights.


Then tick the SerialMIDI bridge option.

To start the lights:

Go back to Studio One and play the song. You should see the Green LED on screen in Hairless Serial to MIDI bridge blinking. If that is there, the then your relays should also work.
Now you’ll see your light show according to 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 at the end.


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:

This project was inspired from a YouTube video by John Storms from his channel ListenToOurLights (http://www.youtube.com/user/listentoourlights). Thank you John.

Full story behind this project: techmusician.wordpress.com/2016/12/24/the-christmas-lights-project/

More hacks and projects coming soon. Stay tuned.

The Christmas Lights Project!

Day 1:

During last year’s holidays, I was watching Christmas song videos on Youtube and this video of Christmas lights flashing according to the music caught my eye. I decided to make one like that at that moment itself :p but I searched how he did it. I found out how he did it from his channel but it required some special controllers and software which were expensive. So I had to make it with some non expensive things. The first thing that came into my mind was an Arduino. But how would I control the timing of the lights according to a song and even if I could control it with delay(), how will I write a flashing lights program with so many lights!!

But today, something else came into my mind. While I was making a song in a DAW software (sound editing), I thought of making use of a MIDI channel to control the Arduino! The MIDI signals could be read with an Arduino, and the MIDI signal is in sync with a song file. I have played around with MIDI signals some years ago when I made an electric drum kit with piezo sensors and that is how I got this idea suddenly.

So my plan was to program the Arduino to control specific lights according to the notes received via MIDI. The midi could be sequenced according to the song. For instance, if I wanted to turn ON light 1, I would send a ‘C’ note via MIDI and ‘D’ for light 2, and so on.

I made the setup to test this and after a few tries, it worked. I had to use an extra serial port with software serial for debugging. The main serial port was not available to monitor while it communicated to the MIDI in the DAW software.
IMG_20161205_222731.jpgThis was the setup that I used. I even recorded a sample and played back and it worked as expected. The LED on pin13 blinked according to the MIDI signals according to the code. My next day’s task wass to find out how to extent the output pins because I need many more pins.

Day 2:

I successfully added many output pins with a shift register (74HC595). It was easy to program and I attached a total of 3 shift registers to the Arduino, so I got 24 output pins. Then I hooked up three 8-channel (24 relay channels in total) relay boards to those outputs. I programmed to Arduino to turn on the first relay for the note C3, second relay for D3 and so on all the way up to E6 (I did not use sharp notes). I wrote a test MIDI song using StudioOne free version. I used loopMIDI for a virtual MIDI port for StudioOne to transmit to, and used Hairless MIDI to Serial Bridge for sending the MIDI signals to the Arduino. It just worked! 🙂Untitled.pngSo, everything was fine and all I had to do was to create the MIDI file for the song and move everything from breadboard to line PCB.

Day 3:

Made the Christmas Lights controller on the line PCB and attached berg strips so it was nice and clean. I also made some connection cables for connecting it to the relay boards and the Arduino. All that was left was to attach the real lights to the relay boards and make a MIDI track for the song. This was the final board that I used:IMG_20161224_115946.jpg

Day 4:

Made the MIDI track for the song and attached the lights to the relay board.
Here is the video of the output: https://www.youtube.com/watch?v=UYB8DvlqYI8

This project was inspired from a YouTube video by John Storms from his channel ListenToOurLights (http://www.youtube.com/user/listentoourlights). Thank you.

Tutorial of this project: techmusician.wordpress.com/2017/01/01/the-arduino-lights-project/

Playing Songs with Arduino

A malayalam song has become viral in my state and I thought of doing that song with an Arduino. I’ve already done a song like this earlier and made a tutorial and DIY  Hacking published it! (tutorial in this link)  In this post, I’ll be explaining what exactly I did when I made it.

Arduino speaker

One day I saw the toneMelody example file in Arduino and I tried it and found it interesting. A short melody was coming out of the speaker. The program created tones with a function, ‘tone( )’. It generated a square wave of the specified frequency on a pin. A duration could be specified for this. The Arduino pin was connected to a speaker to play the tones. And I thought, why couldn’t I make a full song? So I modified the code and made a song and showed everyone and they liked it and asked me how I made ‘that particular song’. So I made a tutorial of how I made it.

Here’s what I did. I changed the melody[] and noteDurations[] arrays in that file to play that song.  It is similar to how ringtones were written in old Nokia cell phones. So how did I get all the notes? I played the song on the guitar and I wrote the notes of the song and created the the melody[array with those.  I also created noteDurations[ ] according to the length of each music note. Then I connected the Speaker to PIN3 and GND and uploaded the code.

Arduino speaker

That’s it. The song was being played on the speaker. In this new song video that I made, I also played chords of the song on my guitar along with the Arduino music. Here’s the link to my video: https://www.youtube.com/watch?v=sS5XwNt3K3c

Arduino file link (Download & extract the zip file and run it.)

It was just a fun project and I’ll be posting new projects soon and also writing about my old projects that I did. Stay tuned.

First blog post

Hello everyone. This is my very first post. My name is Akshay James and I’m a DIY techie and also a musician. I’m new to wordpress and I started this blog to share my DIY stuff that I do. I think the wordpress interface is so nice and I like it. I had a blog earlier (but it wasn’t very active) and I thought I’d really start blogging since my holidays have started. So stay tuned!