November 16, 2005
Air Guitar (MIDI Lab)
Oren strumming the air guitar.
An image of the guitar with the breadboard. "No strings attached!" (A helluva lot of wires, tho').
For the MIDI lab, I decided to try out a beam-break detection system I had been wondering about for awhile. Creating an invisible "string" that could be "plucked" seemed to be a perfect applicaiton for MIDI.
The beam-break detection system is pretty simple: An infrared (IR) LED shines at an IR emitter/detector. If the IR LED isn't too far from the emitter/detector, you will pick up a signal. Indoor lighting gives off IR, too, so the values you get on the IR detector will vary depending on the lighting situation. To overcome this I created a "calibrate" routine where the PIC measures the initial value it reads off the IR detector and then compares subsequent readings against this "calibrated" value. If the new reading on the detector is off by a pre-determined amount (my "threshold variable"), we know the beam has been broken, and so we can do something (in this case, we send a MIDI note out).
A close-up of the IR emitter/detector
A close-up of the IR LED, which is situated facing the emitter/detector, about 6-8 inches away. You "strum" the guitar by interfering with the beam between this LED and the detector.
The reason I used an IR emitter/detector (note the emphasis) is that I wanted to be able to do some basic ranging. That is, I wanted to get more information about where the beam was broken, in addition to the fact that it was broken at all. When you break the beam with a finger, your finger reflects some of the IR from the emitter back to the detector (the emitter/detector combo is one unit, with both emitter and detector facing out. The IR LED is across from the emitter/detector module, about 6 inches away.). The idea (and this was born out when I looked at the data I was getting) is that there will be a range of values that the detector detects, going from low (finger breaks the beam far away from the emitter/detector) to high (finger breaks the beam right near the emitter/detector and a lot of IR light gets reflected off the finger into the detector), as well as the "calibrated" value (i.e., nothing breaking the beam).
In practice it worked out pretty well except for the fact that the range of values the detector read were not linear (they tend to be quite low for the furthest third of the length of the beam, and then jump up very quickly when you get less than a couple centimeters away). I don't think I got the correct code onto the PIC to translate those changing measurements into changing notes, though.
Here's a close-up of the breadboard, without the 20MHz clock.
I also drilled a hole in the guitar body and added a potentiometer with a knob on it (just like a real electric guitar). The values from the potentiometer are used to change the volume of the notes generated using the guitar.
You can download the PICBasic Pro Code (I commented it as well as I could).
One of the major problems I ran into was making sure that the PIC programmer was set for a high-speed oscillator (oscillator->HS). It was really frustrating before I realized I was forgetting to do that. Also, getting the hang of how to set up the hardware serial out (the HSEROUT command) was difficult.
I should point out that I didn't do this alone. Oren helped out a lot for the final stages, and Tikva helped me along when it was still an air harp. And Megan MacMurray gets special thanks for generously letting me use her 20MHz clock whenever I needed it.
Me jamming.
Me jamming harder.
There will be a movie coming soon (it's not the same without the audio).
Also, I'm planning on expanding the project to include a couple strings and Oren's suggestion which was to use photodetectors as "frets" to change chords. I am going to need to use lasers for the multiple strings (IR would diffuse and interfere with itself). I think I'll call it my Laser Air Guitar.
Tools used
- PicBasic Pro
- MIDI
Posted November 16, 2005 09:54 PM. Categories: Labs , Week 10 | Permalink