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?

screen1.PNG

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:

bd.PNG

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.

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 IN MOST RELAY BOARDS)
IF THERE IS ANY CONNECTION, IT CAN DESTROY THE ARDUINO AND ICs.

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

studio.PNG

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

click.PNG

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


#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 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.

sett.PNG

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.

img_20161224_115946.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:

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.

Advertisements

3 thoughts on “Tutorial: The Music Light Show

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s