Now that you're up to speed on using Arduino's inputs and outputs, this Instructable will give you everything you need to get started using sensors to trigger MIDI notes from Arduino. This post is the last installment in a series of workshops I led at Women's Audio Mission. The first two classes are Intro to Arduino and Working with Arduino Inputs and Outputs.

Parts List:

(1x) Arduino Uno Amazon or you can pick one up at a local Radioshack

(1x) usb cable Amazon

(1x) breadboard (this one comes with jumper wires) Amazon

(1x) jumper wires Amazon

(1x) 220Ohm resistors Digikey CF14JT220RCT-ND

(1x) led Digikey C503B-RCN-CW0Z0AA1-ND

(1x) 10kOhm resistor Digikey CF14JT10K0CT-ND

(1x) tact button Digikey 450-1650-ND

(1x) tilt switch Adafruit 173

(1x) 10kOhm potentiometer Digikey PDB181-K420K-103B-ND

(1x) light sensitive resistor Digikey PDV-P8103-ND

(1x) 33kOhm resistor Digikey 33KQBK-ND

(1x) 1MOhm resistor Digikey 1.0MQBK-ND

(1x) piezo sensor Sparkfun SEN-10293

Step 1: Serial to MIDI Converter

In this class we'll be using the Ardiuno's USB connection to send Serial messages to you computer, then we'll run an app like Hairless MIDI to convert this the Serial messages to MIDI and route them to other applications on your computer (Ableton, Garageband, etc). I chose this software solution because it is easiest and cheapest to setup for an entire class, you could also use a 5 pin MIDI plug and a MIDI cable to plug directly into other MIDI instruments. There are a few things you will need to be aware of with this setup:

Be sure that the baud rate you specify in Serial.begin() in your Arduino sketch is the same number selected under Hairless MIDI >> Preferences >> Baud Rate (I used 9600 so I used the command Serial.begin(9600) in all example Arduino sketches, see the first two images above). If you choose to wire up a 5 pin MIDI plug you have to set the baud rate to 31250, but if you're connecting via USB to a Serial to MIDI application, you can use whatever baud rate you like.

To use Hairless MIDI you will need to select your board (something like usbmodemfd121) from the Serial Port menu and select the MIDI channel that you would like to send or receive MIDI to/from. Make sure you have the same MIDI channel selected in the preferences of whatever other MIDI applications you are running on your computer. I sent my MIDI to IAC Driver Bus 1, and then setup Garage Band or Ableton to receive MIDI on this same channel. If you do not see any MIDI output options in Hairless MIDI, scroll down to the FAQ and troubleshoot your setup.

You cannot program the Arduino while it is connected to Hairless MIDI, because the two applications are competing for the same port (see the error in the second image). A quick way to bypass this without needing to quit Hairless MIDI each time you want to change your code is to select a different Serial Port from the Hairless MIDI interface, upload your new Arduino code, and then set the Serial Port in Hairless MIDI back to the correct one.

<p>Hi! One problem I got:</p><p>When I write &quot;Serial.begin(9600);&quot;</p><p>I get no note. An error message in hairless says &quot;Error: got unexpected data byte&quot;</p><p>When I write &quot;Serial.begin(115200);&quot;</p><p>I get a note playing constantly, without pauses.</p><p>Anybody understands why this happens and how to make it work?</p>
<p>What a great idea!</p>
<p>Can you suggest some cases or demos to trigger music with flex sensor?</p>
<p>Really cool, kind of got it working but 2 problems: </p><p>1. only plays one midi note that the pontentiometer commands at the moment of uploading the code (ie no real time variation of notes when adjusting the potentiometer. </p><p>2. no note off command is given, the note is sustaining forever.</p>
<p>wht about if I have flex sensor with Arduino and i want to transfer the data to (MIDISPORT 1-in/1-out MIDI interface) than to Computer ?<br>which code i have to use ?<br></p>
<p>also Do i have to install MIDI library to Arduino ?<br>please help me <br>Thanks alot </p>
<p>my code doesn't require an external library, but you can use the MIDI library instead if you like. </p>
<p>does it matter if the flex sensors are smaller in lenght for example 5.5cm? is there a difference between the sensors that you used which i think there are 11cm in length and some sensors that are 5.5cm? or the only differenceis justt the length?</p>
<p>any length will work, they might have different output at different angles of bend, but you can adjust all that in code.</p>
<p>Cool. Trying to make this with the gmiller version. this is awesome.</p>
<p>Hey great tutorial!, I'm trying to get multiple buttons to trigger different notes but I can't seem to fathom it? Do I need to have multiple instances of the code for each pin I initialize? </p>
<p>Did you find a way to do that?</p>
Hey,yeah I did but I used a workaround and created a programme in Max that reads each of the pins, basically means that you have to load it everytime you use the midi interface you've built.
<p>Could you send me more detailed instructions or the code for Max to make the project work? I am very new to Arduino and only know basic programming. Thanks!</p>
<p>yeah you will, to organize it better you could take an object oriented approach to your code:</p><p>http://en.wikipedia.org/wiki/Object-oriented_programming</p>
Thanks :)
<p>Thanks for the tutorials, after some head scratching I now have my first 'strawberry synth'. Cheers!</p>
<p>cool! do you have a video?</p>
<p>You're an extremely awesome person and one day you'll see that some musician out there was able to step their performance game up to the next level starting with these tutorials</p>
<p>This has helped me a lot as I am building a MIDI controller. How would i add additional Piezo sensors to this script?</p>
<p>create more variables:</p><p>int piezo1 = A1;</p><p>int piezo2 = A2;</p><p>int piez3 = A3;</p><p>then copy the code below for each piezo:</p><p>int piezo1Val = analogRead(piezo1); </p><p> if (piezo1Val&gt;threshold){</p><p> int maxPiezoVal = getMaxVal(piezo1Val); </p><p> byte velocity = map(maxPiezoVal, 0, 1023, 50, 127);//velocity between 50 and 127 based on max val from piezo </p><p> MIDImessage(noteOn, 60, velocity); </p><p> delay(500); </p><p> MIDImessage(noteOn, 60, 0); </p><p> }</p>
<p>Hi, this is a great lesson. But how to combine 2 or more notes : e.g. : if I want to do a F and a A at the same time ? Thanks !</p>
<p>great information and links</p>
cool!! thanks also for all the other links and references

About This Instructable




Bio: I'm a grad student at the Center for Bits and Atoms at MIT Media Lab. Before that I worked at Instructables, writing code for ... More »
More by amandaghassaei:OTCA Metapixel - Conway's Game of Life "9 Degrees of Freedom" IMU Twitter Controlled Pet Feeder 
Add instructable to: