The infraHarp is an Arduino-powered eight-tone arpeggiator that uses infrared emitters and detectors and Sparkfun's Musical Instrument Shield. This page gives a detailed description on how to build the prototype, which plays in the keys of A, B, C, D, E, F, G in major, minor melodic and harmonic scales, with two octave choices. Click the link below to download the sketch!
Download the sketch.
To build the prototype you will need the following software and hardware:
- Arduino IDE Software
- 1x Arduino Mega 2560 - R3
- 1x Musical Instrument Shield
- 1x Large Breadboard
- 1x Half-Size Breadboard
- 8x Infrared Emitter Detector Pair
- 4x Push Button
- 2x 10k Potentiometer
- 8x 220 ohm Resistor
- 12x 10k ohm Resistor
- Jumper Wires
- 1x 1/8" input Speakers.
The first thing you need to do is solder the headers onto the Musical Instrument Shield. If you have no experience soldering see our Beginners page for guidance. Once you've done your soldering you are ready to hook up the rest of the hardware.
Next you're going to want to wire all of the infrared emitters/detectors. We'll start with the emitters. If you bought the IR-pair from SparkFun the emitter is the diode with the yellow-dot. First connect two wires, red and black, to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground.
Then connect the longer, positive legs of (anodes) 8 IR-emitters to digital pins 46-53 through 220 ohm current limiting resistors. Connect the shorter, negative legs (cathodes) to ground. (Shown Below)
Next the detectors (red dot).
Connect the longer, positive legs of the (anodes) 8 IR-detectors to 5V through 10k ohm current limiting resistors. Connect the shorter, negative legs (cathodes) to ground. We want to draw our signal right between the power and the detectors positive leg. Connect wire from here into analog pins 8-15.
When all the emitters and detectors are hooked up it should look like this.
The next thing we'll want to do is hook up the buttons and potentiometers for the infraHarp.
The way the instrument is designed is there are four buttons:
- A button to toggle instruments. (pin 11)
- A button to toggle the key you're playing in (A, B, C, D, E, F, G). (pin 10)
- A button to toggle the scale (Major, Minor Melodic, Minor Harmonic). (pin 9)
- A button to toggle the octaves (Only two octaves in the code, but you could add as many as you like!). (pin 8)
And two potentiometers that:
- Control Master Volume. (analog pin 1)
- Control the tempo of the appegiator. (analog pin 0)
This is where the half-breadboard comes in. For the pushbottons: Connect pins 8-11 to one leg of each pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply. (As seen below).
For each potentiometer you will need 3 wires: Connect one wire to ground from one of the outer pins of the potentiometer. Connect a second from 5 volts to the other outer pin of the potentiometer. Connect the middle pin to analog pin 0 (and the second potentiometer to analog pin 1).
When all 4 buttons and 2 potentiometers are hooked up, it should look like this.
The hardwiring is done! Make sure that everything is in the correct order. And we can move onto the sketch.
Download the sketch. It's a good idea to become familliar with how the Musical Instrument Shield works. Check out Sparkfun's Quickstart Quide for an example code and a brief explanation on the general principles. The MIDI statements use the NewSoftSerial library to communicate with the Arduino.
The code is pretty straight-forward. It starts by defines all the variables for the inputs and outputs (i.e. LEDs and sensors). Arrays are used for the IR emitters and detectors, which will correspond to the arrays of notes the program will call upon given the state of each buttons count (We will discuss that in a bit). The setup function declares what time of pin (pinMode) each of the ports on the Arduino are. Arduino code at its core has two functions. The "setup" (void setup()) is quite literally what it sounds like: it runs through a list of commands that set the board up properly. The "loop" (void loop()) is what happens continuously. The next part of the setup the shield is initialized (i.e. told to listen to the code), and then it tells all of the IR-emitters to turn on (digitalWrite()). We want to have a steady beam of infrared light coming from the emitter into the detector. So that means we never want the IR-emitters to turn off, which is why we declare them on in the setup.
The program reads the amount of infrared light coming into the detector and triggers a function (noteOn) if the detectors input goes above a certain threshold (which is caused when you block the detector with your finger). After a certain amount of time (tempo) the program checks again to see if the detector's value is still greater than the threshold and, if it is still greater than the threshold, triggers another function (noteOff). The amount of time between each "check" (tempo) can be manipulated by one of the potentiometers. The second potentiometer is what controls the function for the master volume.
Each of the 4 buttons keep a count every time they are clicked, and reset back to 0 after they've reached their limit. Each button has a different limit, which corresponds with a different function. The first button controls the function for the instrument you want to play. In this sketch their four selections to choose from. The Musical Instrument Shield comes equipped with General MIDI - which comes with 128 unique instrument sounds. This sketch only uses four unique sounds, but you can change that within the sketch.
If you look at line 49 of the sketch you will see:
// INSTRUMENT INFORMATION:
const int instrument0 = 79; // Ocarina
const int instrument1 = 107; // Koto
const int instrument2 = 104; // Sitar
const int instrument3 = 53; // Voice Oohs
By change the values of each of these you can load new sounds. To learn each sound's number reference page 32 of the MIS Datasheet, or the image below.
The next button controls the count of the key. In this sketch there are seven key choices (A, B, C, D, E, F, G). The count starts at the key of A. The next button controls the scale. In this sketch you can choose between Major, Minor Melodic, and Minor Harmonic. The last button controls the octaves, of which you have two choices.
Housing the Prototype:
I bought this box on Amazon to house the project, but there are a wide variety of options. I picked up these Panel Mounted Pushbuttons and LED Holders on Sparkfun for the casing and they worked great. (mounting diameters on Sparkfun).
On the top plate I drilled a hole for a push button, and holes for 4 lights and a potentiometer. This button controls the instrument bank, and uses the LED's to visual represent the count of the button. The potentiometer controls the tempo.
I secured the top plate into the casing, and prepped the wiring. I used two half-sized breadboards which did the job, but it does make the instrument more fragile (A Solderable Breadboard could be a better option). I then plugged the button, LEDs, and potentiometer into the proper places on the breadboard.
On the bottom plate I drilled a hole for a potentiometer, and a bunch more holes for buttons and LEDs. The first group is a button and 3 LEDs. This button controls the key and the LEDs visual represent the count of that button (as discussed in The Sketch ^).
The LEDs for these three buttons counts in binary. If the lights on add that number. (i.e. If light 1 and 3 are on (1 + 4) the count is equal to 5. Remember the count for the button that controls the key starts in the key of A. so 5 would = E. The next group is 1 button and only 2 LEDs. This button controls the scale. If you remember from reading The Sketch, the infraHarp can play in major and both minor melodic and minor harmonic (i.e. 3 choices). If the first light is on it's playing a major scale. If the second light is on it's playing a minor melodic scale. If both lights are on it it's playing in a minor harmonic.
The last group is 1 button and 2 LEDs. You may have guessed it, but this button controls the octave. The infraHarp only has 2 octave choices (Why not add more?) so that button just switches between a higher and lower octave.
Mounting in infrared pairs was the most challenging part. I cut two strips from a piece of metal typically used for a shower and bolted them on. I drilled parrallel holes in the bottom plate so that the infrared pairs could fit through securely.Save the headache and remember to label everything! Though if you remember, we turned all eight ir-emitters on in the setup and never want any of them to turn off, so the order you place the emitters into the breadboard doesn't matter.
All of the wiring made it a bit tricky to fit into the housing, but I managed to make it all fit. It's a good idea to have your wire a bit too long to start and then trim them all to their appropriate heights. I will admit this was the one hair grabbing part. Goodluck.
Hope you enjoyed learning about this project, and I hope to see some variations of this project on the Internet! By Connor Hubeny