Introduction: Piano Stairs With Arduino and Raspberry Pi
Who doesn't love music? These Piano Stairs are an interactive, relatively portable, musical installation that can be applied to basically any stairwell. I built them for HackPrinceton along with my friends Erica Portnoy and Vincent Castaneda, and we won 2nd place in the hardware track. I've had requests to share my code and diagrams, so I decided to make an Instructable!
These piano stairs use a light-based “tripwire” for each stair. The light sources should be on one side of the stair, the photoresistors on the other. In this setup, the Arduino reads from the sensors and passes the values to the Raspberry Pi, which generates the sounds.
Materials
What you need, assuming six stairs:
6 photoresistors
6 resistors, 1000 ohms each
6 light sources: I used flashlights, you can use bright LEDs
1 standard speaker set, w/ audio cable
1 breadboard
Wire
Solder
Soldering iron
1 Arduino Uno
1 Raspberry Pi
Step 1: Learn to Read a Light Sensor From the Arduino
I suggest that you first get your basic light sensor circuit set up, using a breadboard and an Arduino, so that you understand how the basic light sensing works. The image for this step is the basic diagram you'll need. Come back once you can read a photoresistor using your Arduino!
Step 2: Solder Your Photoresistor Circuits
Now, for each photoresistor, you’ll want to do the following:
I found it useful to use cardboard backing to keep the photoresistors stable. Stick the legs of the sensor through and tape them in place with electrical tape.
Solder one short ground wire to one leg of the photoresistor.
Solder one “power” wire to the other leg. This wire should be long — based on the height of the stairs, and which stair this sensor is for. It should reach all the way to the bottom of the stairs.
Mark the stair number on the piece of cardboard, and tag the end of the power wire with the stair number as well (using masking tape and a marker). This will help you later.
Step 3: Solder the Ground Wire, Connect Everything to the Arduino.
Connect a wire from the power output pin of your Arduino (5V) to a power row of your breadboard.
For each “power” wire from a photoresistor circuit, connect it to some unused row n in the breadboard. Also to row n, connect a wire to analog pin n on the Arduino. Finally, connect a resistor from row n to the power row of your breadboard.
This should be practically identical to the basic photoresistor circuit you built earlier! It's just 6 of them on one breadboard.
Make sure to connect the wires in a logical order. E.g., stair 1 should go to Pin 1, stair 2 to pin 2, etc. Otherwise your notes will be out of order.
Step 4: Setup the Staircase
Step 5: Upload the Arduino Code
It prints out lines of 6 digits (ones and zeros):
100100
..this means that a footstep has been detected on steps #1 and #4 (if we’re counting with step #1 on the left-hand side of the output).
Get the code here:
https://github.com/bonniee/piano-stairs
(Look in the piano directory for piano.ino)
Attachments
Step 6: Connect to Raspberry Pi
Download the github repo onto your Raspberry Pi and run python ohboymusic.py!
https://github.com/bonniee/piano-stairs
Image from raspberypi.org
Attachments
Step 7: Enjoy, Tweak, Tinker
Troubleshooting tips:
You can hit the red “reset” button on your Arduino to recalibrate the light thresholds. Make sure nobody is on the stairs, and that the flashlights are turned on, when you do so!
FAQ
Isn’t it wasteful to use an Arduino and a Raspberry Pi? Why do you need both?
Yeah, it is, but I did this for a hackathon and this is what I had on hand! You could use an Analog to Digital Converter (ADC) and a Pi Cobbler Breakout Board in order to replace the Arduino entirely. (The RPi only has digital pins, alas, so you need an ADC — but that’s cheap.) Hopefully I’ll have an updated version posted soon, because I have an ADC coming in the mail.
This code is crap!
I’m supplying the code I used in the hackathon, so it’s a bit messy. I’m waiting to clean it up until I can switch to using an ADC and get rid of the Arduino entirely.
Can I expand the # of stairs?
Right now I’ve maxed out the number of analog pins on an Arduino. So yes, you could, and that would be awesome, but would require significant modifications.
Why flashlights?
You could also try using LEDs, or infrared sensors. But you need some kind of light source so that you can clearly differentiate, say, a sneaker, from just a shadow on the staircase.