Introduction: MIDI2LED - a MIDI Controlled LED Strip Light Effect

About: I'm 47 years old, love making music, handicraft, cooking, tinkering with electronics ... and would need much more time for all of that.

This is my first instructable, so bear with me.

I love making music, and in live situations like living-room concerts, I like it when there's light effects in synch with what I play. So I built an Arduino-based box that makes an LED strip light up in a random color when I hit a note on my MIDI keyboard, and where I hit the note.

Supplies

  • Arduino Uno
  • Arduino protoshield
  • MIDI jack
  • 1N4148 diode
  • 6N138 opto coupler
  • resistors: 2x 220 Ohm, 1x 10kOhm, 1x 470Ohm
  • WS2812B LED strip (60 LEDs)
  • some leftover wires
  • heat shrink tubing
  • suitable casing for the Arduino (I use a plastic junction box)

You'll also need

  • soldering iron and solder
  • MIDI keyboard and MIDI cable

Step 1: The Electronics

The circuit is pretty straightforward. It consists of a standard MIDI input (left of the Arduino) and the connection to the LED strip (right of the Arduino). Place all the parts on the protoshield, there's lots of space.
It is generally recommended to use an external power supply to power the LED strip, but I found that when you play, only few LEDs are on at the same time, so there was no problem in using the Arduino +5V / GND as power output. (Try to avoid hitting all keys at the same time, and with full velocity. ;-) ) If you decide to use an external power supply, simply connect it to the Arduino +5V and GND pins. Some people recommend inserting a 100uF capacitor (not shown in schematic) between these two lines.

Solder the parts to the protoshield and connect the LED strip as shown in the schematic.

Step 2: Connecting the LED Strip

It is important to connect the right end - the input end - of the LED strip to the circuit. My strip has a female connector as an input, and has little triangles all along pointing away from the input. At the output, there was a male connector (to be able to connect it to another strip, which we don't need), so I cut that off and soldered it to the three cables coming from the Arduino. Use heat shrink tubing to tie the three cables to the LED strip together, and to make them less visible.

The LED strip I used comes with adhesive tape at its back, so it can easily be glued to the back of the MIDI keyboard.

Step 3: Adapting the Project to Your Keyboard

You may have to adapt the LED strip and the Arduino code to your keyboard. Mine has 76 keys, and the length of the strip is almost exactly the width of the keyboard. If you have e.g. 61 keys, you may need a shorter strip. The LED strip can be cut between any two LEDs. Just make sure you're cutting off the correct part, it has an input end (with a female connector) and an output end (with a male connector), you need to keep the input end.
In the code, change the #defines for

  • NUMBER_OF_LEDS to the number of LEDs left in your strip after cutting off the end,
  • NUMBER_OF_KEYS to the number of keys on your keyboard, and
  • MIN_KEY to the MIDI pitch number of your lowest key. You may find this in the keyboard's user manual; or use a tool that displays the MIDI note number, like KMidiMon for Linux, or Pocket MIDI for windows or Mac; or try out different values until the device responds to all of the keys on your keyboard

Step 4: The Arduino Code

The Arduino code uses the MIDI library (v4.3.1) by Forty Seven Effects and the Adafruit NeoPixel library (v1.3.4) by Adafruit. Install these libraries using the Arduino IDE. Then compile the code and upload it to the Arduino without the shield connected (the optocoupler is connected to the RX pin, which impedes the upload). Power the Arduino via USB cable (I use a USB wall wart).

If you'd like to modify the code to your liking, here's a brief overview how it works: In every loop, the MIDI input is read out. If a Note On or Note Off event have been received, the MyHandleNoteOn or MyHandleNoteOff functions are called. They both call the updateVelocityArray function, which stores the velocity (i.e. how hard you have hit the key) of the key number. If the velocity is higher than what was stored before , the color of the corresponding LED is set to the "current color". After the MIDI events have been handled, the function updateLedArray is called. This updates the "current color" (the red, green and blue values of which change independently in a linear way, until the lower or upper end is reached, at which point the speed for the linear change is set to a random number), slowly reduces the velocity of the pressed notes, and updates the color values of each LED that has to change its color (due to new note hit, or reduction of velocity). Function showLedArray transfers the colors to the Adafruit_NeoPixel structure called "pixels" and makes the actual LEDs show the colors in the pixels structure.

Step 5: Possible Enhancements ...

A project is never finished. There's always something that can be done to improve it:

  • The protoshield contains so few parts it's really a waste; one could easily achieve the same effect with an Arduino Nano and a 15x7 holes PCB plus some female pin headers.
  • Some of the MIDI signals get lost. If it's a NoteOn, the corresponding LED will not light up; if it's a NoteOff, it will not go out (that's why I introduced the reduction of velocity, which ensures that LEDs will not stay on indefinitely). I'm still trying to figure out the reason. Possibly it's a timing issue, and MIDI.read() should be called more often.
  • Some of the MIDI signals are misread, i.e. the wrong LEDs light up. Could be connected with the point above. Needs some investigation.
  • The circuit is designed to give a pleasant visual effect without much user interaction (apart from playing the keyboard). However, I could imagine adding a potentiometer that is read out (using one of the Arduino's analog inputs) with which you can change the maximum speed at which the colors change (currently #define'd as MAX_COLOR_CHANGE_SPEED = 20). Or measure the average time between two NoteOn events, and change MAX_COLOR_CHANGE_SPEED accordingly - in slow songs, the color should change more slowly.

Step 6: Done!

Power the Arduino via USB cable (I use a USB wall wart). Connect your MIDI keyboard to the MIDI jack, and start rockin'.
Watch me play a little light music (pun, as bad as it is, intended).

LED Strip Speed Challenge

Participated in the
LED Strip Speed Challenge