Introduction: Light Show Jacket That Reacts to Music
This tutorial has been produced as part of my final year project for my degree in Music Technology and Applied Electronics at the University of York. It is aimed at musicians with an interest in electronics. The finished product will be an LED matrix on the back of a jacket that can produce a light show in accordance to music. This will be done by analysing audio inputs using Pure Data and Arduino. The jacket will have two settings that can be controlled by a switch. One setting will control the LEDs according to the amplitude of the music and the other will have the LEDs twinkling one at a time and changing colour according to the pitch.
How It Will Work
This device will be made up of two separate circuits. One will be based around an Arduino Mega connected directly to a computer. The other circuit will be based around a LilyPad Arduino and will be completely contained within the jacket and powered via a 9V battery. Both of these circuits will communicate with each other wirelessly using XBee modules.
Audio signals will be received by the computers inbuilt microphone and analysed in Pure Data to obtain amplitude and frequency data. This information will be transferred to the Arduino Mega using a MIDI input circuit and this will then be transmitted to the LilyPad using the XBees. The LilyPad will then determine how the LEDs on the jacket will react.
What You Will Need
For the Mega Circuit
- Arduino Mega 2560
- XBee Explorer Regulated
- XBee 1mW Trace Antenna - Series 1
- Prototyping Shield for the Mega
- USB Type A to B
- USB to MIDI Cable
- MIDI Socket
- 1 x 220Ω Resistor
- 1 x 270Ω Resistor
- 1 x 1N4148 Diode
- 1 x 6N138 Optocoupler
For the LilyPad Circuit
- LilyPad Arduino 328 Main Board
- LilyPad XBee Breakout Board
- XBee 1mW Trace Antenna - Series 1
- LilyPad FTDI Basic Breakout Board
- 72 x LilyPad LEDs (a range of all colours available including white, blue, red, yellow, green, pink, and purple)
- LilyPad Slide Switch
- USB 2.0 A-Male to Mini-B Cable
- 9V Battery
- 9V Battery Clip
- Computer with Pure Data and the Arduino IDE installed
- Equipment Wire
- Soldering Equipment
- Wire Cutters
- Wire Strippers
- Needle with a large eye
- Conductive Thread
- Tape Measure
- Fabric Glue or Clear Nail Varnish
- Chalk or White Eyeliner
- Fabric for a lining or an old t-shirt
- Drill (possibly)
- Standard LED (for testing)
- Breadboard (for testing)
- Another 220Ω resistor (for testing)
- Multimeter (for testing)
The cost of this project will very much depend on how much of the above equipment you already own. However, it is likely to be somewhere between £150 - £200.
A quick note - the LilyPad boards are designed to be sewn directly to textiles and therefore soldering a 9V battery clip to one may cause issues. The connection can be delicate and easily broken. You can get specifically designed LilyPad boards for AAA or LiPo batteries which you may decide you would rather use. However, I still chose to go down the 9V route as their battery life is greater than AAAs and my University has restrictions on the use of LiPo batteries.
Step 1: Creating the MIDI Input Circuit
First of all, let’s consider the MIDI Input circuit. This will need to be constructed on the prototyping board which will slot into the Arduino Mega. This will be used to send MIDI messages from the Pure Data patch to the Mega via its ‘COMMUNICATION RX0’ pin. See above for a circuit diagram and a photo. Depending on your prototyping board, your layout might be slightly different but I chose to place the MIDI socket in the bottom left-hand corner. A drill may need to be used here to make the holes on the shield larger in order to fit the socket. The red wires in the photo are connected to 5V, the brown are connected to ground, the black wire is connected to pin 3 on the 6N138, the blue wire is connected to pin 2 on the 6N138 and the yellow wires are connected to the RX0 pin. Space is left on the right-hand side of the prototyping board to allow room for the XBee later. Breaks will probably need to be made in the tracks on the board. For this example, they had to be made between the pins on the 6N138.
Testing the MIDI Input Circuit
To test the circuit, upload the code below to the Arduino Mega using the USB Type A to B cable. Make sure the shield is not inserted when you do this as the code cannot be uploaded if anything is connected to the RX or TX pins. Also, the code includes the MIDI.h library which you may need to download, available at the link below.
Next, insert the shield into the mega and connect it to another USB port on your computer via the MIDI to USB cable. The MIDI end that you will need to use will be labeled 'out'. Create a simple circuit on a breadboard connecting pin 2 to a 220Ω resistor and then connecting this to the anode of a standard LED. Connect the LEDs cathode to ground.
Then, create a simple Pure Data patch with a [60 100] message and a [0 0] message both connected to a noteout object via its left inlet. Ensure that this patch is connected to the MIDI Input circuit by opening the MIDI settings and changing the output device. If this is not available make sure that you connected the MIDI circuit to your computer before you opened Pure Data. Now, if your circuit is correct, the LED should light up when the [60 100] message is pressed and it should turn off when the [0 0] message is pressed.
Step 2: Designing the LED Matrix
Next, the LED matrix for the back of the jacket needs to be considered. This will be directly connected to the main LilyPad board. Normally, to control LEDs using a microcontroller they would each be assigned to their own individual pins. However, with only one Arduino LilyPad this would be very limiting. In total, the LilyPad has 12 digital pins and 6 analogue, so potentially 18 output pins. However, as one of these pins will be used later to control a slide switch, this will leave only 17 remaining.
A technique can be used in this situation called multiplexing to maximise the potential of the LilyPad’s control pins. This takes advantage of two facts:
- LEDs are diodes and only allow current to flow in one direction.
- Human eyes and brains process images much slower than light can travel so if LEDs flash fast enough, we will not notice. This is a concept known as “Persistence of Vision”.
By using this technique the number of LEDs that can be controlled is (n/2) x (n-(n/2)) where n is the number of available control pins. Therefore, with 17 pins available it should be possible to control 72 LEDs in a 9x8 matrix.
A diagram for the layout of LEDs in a 9x8 matrix can be seen above, including suggestions for the pins that each row and column should be connected to. It is important to note that the rows and columns must not touch. Also, no resistors are required due to the fact that each LED has its own built in with a resistance of 100Ω.
Before you begin sewing you should plan the layout of the circuit on the jacket. A good place to start here is by marking on the jacket where the LEDs are going to go with small dots, using a tape measure to ensure that they are evenly spaced out. For a black leather jacket, white eyeliner works very well and can be easily wiped off if a mistake is made. However, other mediums such as chalk may also work depending on the material and the colour of your jacket. The arrangement of the LED colours that I used can be seen above which will work with the code provided later. You are welcome to use a different layout although this will need to be altered in the code.
The next thing to think about is where the LilyPad, LilyPad XBee and power supply will go. For the jacket I used, the most sensible and discreet place seemed to be on the back of the jacket, at the bottom and on the inside lining. This is because it is unlikely to get knocked by the wearers arms here and it can easily access the LED matrix. Also, as the jacket I used was loose at the bottom, it was still comfortable.
Step 3: Sewing the LED Matrix
At this point you can begin sewing. Conductive thread can be tricky to work with so here are a few useful tips:
- Glueing a component into place using fabric glue will make it much easier to sew.
- Different types of stitches will have different aesthetic and functional properties so it is worth looking into these before you get started. A basic running stitch, however, should be fine for this project.
- The knots tend to come loose quite easily with conductive thread as it is “springier” than normal. A solution to this is using a small amount of clear nail varnish or fabric glue to seal them. Allow them time to dry before cutting off their tails.
- When creating connections to circuit components or joining together two lines of conductive thread, it is a good idea to sew over these multiple times to ensure that a good mechanical and electrical connection has been made.
- Make sure that your needle is sharp and has a large eye. Getting through the jacket can be tough and conductive thread is thicker than normal.
- Be careful of loose hairs on the thread. These can create shorts in the circuit if they happen to touch other lines of sewing. If these become a major issue, all of the lines can be sealed with the clear nail varnish or fabric glue once testing has taken place and everything is definitely working correctly.
A good place to start sewing is with the rows. To make them as straight as possible you could draw faint lines to sew along using a ruler. Once you have sewn these, move onto the columns. Great care will need to be taken each time a row is reached because it is essential that the two do not cross. This can be achieved by creating the stitch for the column on the inside of the jacket for this junction, as seen in the photo above. When you have completed all of the rows and columns a multimeter could be used to check that there are no shorts.
Once you are satisfied start sewing the LEDs for the column on the far right of the jacket. Ensure that each anode is attached to its own row and each cathode is attached to the column to the left. Then, put the LilyPad Arduino in place using fabric glue somewhere roughly below this column, making sure that the pins for the FTDI breakout board are facing down. Sew pin 11 of the LilyPad to row 1, pin 12 to row 2 and so on until pin A5 is sewn to row 9. Then, sew pin 10 to the far right column. To test this first column you can use the code below. Upload the code and power the LilyPad by connecting it to your computer using the FTDI breakout board and the USB 2.0 A-Male to Mini-B cable.
If the correct port is not available when you plug in the LilyPad, you may need to install an FTDI driver available from the link below.
Once you have this first column of LEDs lighting up, it is time to sew the rest onto the jacket. This is quite a time consuming process and so is probably best to be spaced out over a few days. Make sure to test each column as you go along. You can do this by adapting the code above so that the pin for the column you want to test is declared as an output in the setup and then it is set LOW in the loop. Make sure that the other column pins are set as HIGH as this will ensure that they are switched off.
Step 4: Adding a Switch
Next, you can add a switch which will be used to change the settings on the jacket. It needs to be sewn onto the inside of the jacket underneath the LilyPad Arduino board. Using conductive thread, the end labelled “off” should be connected to ground and the end labelled “on” should be connected to pin 2.
You can test the switch using the code below. This is very simple and turns on the bottom right-hand LED if the switch is open and turns it off if the switch is closed.
Step 5: Making the Device Wireless
Preparing the LilyPad XBee and XBee Explorer
Prepare the LilyPad XBee for configuration by soldering on a 6-pin right-angle Male Header. This will later allow it to be connected to a computer via the LilyPad FTDI Basic Breakout board and the USB Mini cable. Also, solder the 9V battery clip to the LilyPad XBee with the red wire going to the “+” pin and the black wire going the the “-” pin.
Connect the Explorer board to the prototyping shield for the Arduino Mega. 5V and Ground on the Explorer board will need connecting to 5V and Ground on the Mega, the output pin on the Explorer will need connecting to RX1 on the Mega and the input on the Explorer will need connecting to TX1 on the Mega.
Configuring the XBees
Next the XBees need to be configured. First of all, you will need to install the CoolTerm software for free which is available from the link below.
Make sure to distinguish between the two XBees in some way as it is important that you do not get them mixed up.
First, configure the XBee for the computer. Insert it into the LilyPad XBee Breakout board and connect this to the computer using the FTDI basic breakout board and USB Mini cable. Open up CoolTerm and in the Options, select the correct serial port. If you cannot see it, try pressing 'Re-Scan Serial Ports'. Then, make sure the baud rate is set to 9600, turn on Local Echo and set the Key Emulation to CR. CoolTerm can now be connected to the XBee.
Type “+++” into the main window to put the XBee into command mode. Do not press return. This will allow it to be configured using AT commands. If this has been successful, after a very short pause there should be an “OK” message response. If there is a delay of more than 30 seconds before the next line, command mode will exit and this will need to be repeated. Numerous AT commands need to be entered to set the PAN ID, MY ID, Destination ID and to save the changes. Return does need to be hit after each of these commands and these can be seen in the table above. Once this had been completed for the computer XBee, it needs to be disconnected and the same process has to be carried out for the jacket XBee.
You can check the new XBee settings by typing in each AT command without the value at the end. For example, if you type in “ATID” and hit return, “1234” should be echoed back.
Testing the XBees
At this point, sew the LilyPad XBee onto the jacket next to to LilyPad Arduino. The following connections need to be made with conductive thread:
- 3.3V on the LilyPad XBee to '+' on the LilyPad
- Ground on the LilyPad XBee to Ground on the LilyPad
- RX on the LilyPad XBee to TX on the LilyPad
- TX on the LilyPad XBee to RX on the LilyPad
Now the device can be tested to ensure that the XBees were working correctly. The code below called 'Wireless_Test_Mega' needs to be uploaded to the Arduino Mega and its main purpose is to receive MIDI messages from the simple Pure Data patch created earlier, and transmit different values via the XBee. If a MIDI note with a pitch of 60 is received, the message ‘a’ will be transmitted. Alternatively, if a noteoff message is received, ‘b’ will be transmitted.
In addition to this, the code below called 'Wireless_Test_LilyPad' needs to be uploaded to the LilyPad. This receives the messages from the Mega via the XBees and controls the bottom-right LED accordingly. If the message ‘a’ is received, meaning that a MIDI note with a pitch of 60 had been received by the Mega, the LED will switch on. On the other hand, if ‘a’ is not received, the LED will switch off.
Once the code has been uploaded to both boards, ensure that the shield has been reinserted into the Mega and that it is connected to the computer via both cables. Insert the computer XBee into the Explorer board. Then, make sure that the FTDI Breakout board is disconnected from the jacket and insert the jacket XBee into the LilyPad XBee. Connect the 9V battery and try pressing the different messages in Pure Data. The bottom-right LED on the jacket should switch on and off.
Step 6: Final Touches
The Code and Pure Data Patch
When you are happy that the jacket is working wirelessly, upload the 'MegaCode' sketch below to the Arduino Mega and the 'LilyPadCode' sketch to the LilyPad. Open the Pure Data patch ensuring that DSP is on and the audio input is set to your computers inbuilt microphone. Try playing some music and moving the switch. You may need to adjust the thresholds in Pure Data slightly depending on how much or little the LEDs are reacting to the audio.
Adding a New Lining
Finally, to make the jacket more aesthetically pleasing and more comfortable to wear, another lining can be added to the inside of the jacket to cover up the sewing and the components. This should be done using velcro to allow easy access to the circuit incase any alterations need to be made.
First of all, sew the 'loop' strips (the softer part) to the jacket on the inside, along the top and down both sides. It is good idea to leave the bottom free as this will allow air to get to the components. Then, cut a piece of fabric the same size and sew to this the 'hook' strips of the velcro, along the top and down both sides. Also, on the same side as the velcro and in the most convenient location, sew on a pocket that the battery will be able to sit in. See the pictures above for examples.
Step 7: You're Done!
Your wireless Light Show Jacket should now be complete and successfully reacting to audio! One setting should create an effect like an amplitude bar and the other should have individual LEDs twinkling to the music with their colours depending on the pitch. See above for video examples. Incase you were wondering, the colour and pitch are related via the Rosicrucian Order which is based on just intonation. I hope you enjoyed this project!
We have a be nice policy.
Please be positive and constructive.