Introduction: Piano Stairs With Arduino and Raspberry Pi

Picture of 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.

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
Soldering iron
1 Arduino Uno
1 Raspberry Pi

Step 1: Learn to Read a Light Sensor From the Arduino

Picture of Learn to Read a Light Sensor From the Arduino

You’ll want to follow Adafruit’s photocell tutorial for this.

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

Picture of Solder Your Photoresistor Circuits

OK, now that you understand the basic idea, we need to solder 1 photoresistor circuit per step of the staircase. I’m assuming 6 steps here. You’ll want 1 sensor per step, with them all connecting at the bottom of the stairs.

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.

Picture of Solder the Ground Wire, Connect Everything to the Arduino.

Now, take a really long wire, strip it in appropriate places, and solder each short ground wire to the long ground wire. Plug this into your Arduino’s ground pin (labeled GND).

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

Picture of Setup the Staircase

Masking tap, twist ties, flashlights; this is when you can actually set stuff up. Tape each piece of cardboard to one stair. Across from it, position a flashlight so that the light beam falls directly on the photoresistor.

Step 5: Upload the Arduino Code

The provided Arduino code is designed to print out a stream of numbers to Serial. It auto-calibrates itself. Upload the provided code, let it calibrate, then test it by reading the Serial output.

It prints out lines of 6 digits (ones and zeros):

..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:
(Look in the piano directory for piano.ino)

Step 6: Connect to Raspberry Pi

Picture of Connect to Raspberry Pi

Plug the Arduino into the Raspberry Pi via the USB cable. Then, plug your speakers into the Raspberry Pi's audio jack.

Download the github repo onto your Raspberry Pi and run python!

Image from

Step 7: Enjoy, Tweak, Tinker

Congratulations! You should have a working set of piano stairs.

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!


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.


caixinhadeleite made it! (author)2015-03-03

very nice! awesome calibration algorithm. i made my version with breakout infrared sensors, worked perfectly. thank you.

bonniee (author)caixinhadeleite2015-03-03

Very cool, thanks for commenting! I've been meaning to redo this with infrared sensors, definitely seems like a better long-term solution.

alyssa.zachariah made it! (author)2014-11-01

Thanks for the tutorial! This was my first time using an Arduino and Raspberry Pi, and your instructable made for an awesome introduction.

Here's a picture of my breadboard and Arduino all wired up! (sorry if it's upside down)

bonniee (author)alyssa.zachariah2014-11-01

Hi! I am so glad you liked it -- and thank you for sending me the video + photo! It looks like it came out great. :)

wck86 made it! (author)2014-02-02

We did it!

This could probably be done without soldering using wire nuts for some solder joints. For example, instead of the long ground wire, you could probably do smaller pieces and wire nut them together at each stair step. I don't think you could do that with the photoresistor legs, but you could try just wrapping stripped wire around it and taping it with electrical tape or using small gauge heat shrink tubing.

Be sure you get all the python prerequisites in order, in terminal on your RPi do:

sudo apt-get install pygame

sudo apt-get install python-serial

Also make sure your configured to output audio the right way for your setup.

bonniee (author)wck862014-02-02

This is awesome! Thanks for posting this. Cute video!

And yeah, soldering probably isn't necessary -- it just made things simpler for my group. You could also just plug each photoresistor into a mini-breadboard hot glue stuff in place, if they give you trouble.

EdrickK (author)2017-10-28

Also, can the code be used on Arduino Due

EdrickK (author)2017-10-28

Do I need 2 arduinos and 2 raspberry pis to create 12 of these?

ValentinaT6 (author)2017-06-20

I am teacher and make your project with my students at University Central in Chile. Very cool, awesome calibration algorithm. Thank for shared

berlingozzo (author)2017-01-05

lovely project :)

I may add the piano effects to this other project:

SonnyM9 (author)2016-10-05

I mean, i need to know the details of the ldr :c

SonnyM9 (author)2016-10-05

How many K has the ldr's?

TomX2 (author)2016-05-19

There's something wrong with the Raspberry Pi code that it does not work. PLEASE HELP ME CUZ I AM DOING THIS FOR MY PASSION PROJECT AND IT IS DUE IN TWO WEEKS!!!

AlT31 (author)TomX22016-08-30

I'm very new at this, but I'm fairly sure you need to place your code files in the "home/pi" directory(actually all files) & then when you compile it, it will build the executable file for you & place it in the same directory(home/pi) so when you give it the run command, it will go to that file & run it until you give it the stop command(ctrl/c)

EspenT2 (author)2015-12-19

This is a great project! I'm hoping to do this with my students verry soon. However, I'm having problems running the code in python. Do I have to save the github repo in a certain directory? For now I just unpacked the zip-file in "Downloads" on the Pi, but that isn't working very well. When I run the program there are a lot of "FileNotFoundError".

Please help!

melodylovesmiguel (author)2014-08-06

Hi, sorry. I'm just gonna leave another comment to ask if we can use light sensors instead as well :) Thanks!

PianoS (author)melodylovesmiguel2015-11-14

Our company is manufacturing piano stairs (You may visit ). Light sensors will not work for a permenant installation. You should have industrial sensors.

aann7 (author)2015-09-24

Hi. I'm new to raspberry pi. I don't know where I'm supposed to put the piano keys. All you tell me is to put the code. Where do I put the .wav files. I'm obviously new to pi bc everyone else gets it and I don't. :(

MaryB43 (author)2015-08-28

If I used an arduino mega...would I have to change too much of the code and gain more stairs? I can do a bit of coding but I'm no expert yet :)

miltono (author)2015-07-17

i wonder....if i have 30 stairs??? how can i do it?? using 2 arduinos?

bonniee (author)miltono2015-07-19

That's one option, or you can use a pin expander. More info here:

Full disclaimer, using a pin expander is a bit more complicated, and you'll need to alter the code to use it. But it's a cheap way to get extra pins.

GabeE1 (author)2015-05-19

If I have 10 stairs can I use the 6 analog pins and then the PWM pins? also how are the smaller ground wires connected to the large ground wire? Thank you in advance

mswope (author)2015-04-24

I think that this is a great project! I love that it uses a real piano sound and that it's polyphonic - I didn't expect that. Thanks for sharing this!

bonniee (author)mswope2015-04-24

Thanks -- glad to hear that you liked it!

Giorgio Aresu (author)2015-01-10

Would it be possible to use only an Arduino generating sounds through PWM?

bonniee (author)Giorgio Aresu2015-04-24

Sure. Check out the Mozzi library. It just takes some more work (and knowledge of sound synthesis, to make it sound not-terrible).

sweetbear_sho (author)2015-03-14

when I run the py file on python, this window show that the port could not open.

Why it is happened, is it some wrong on the connection with the Arduino and Raspberry Pi?

sweetbear_sho (author)2015-03-09

One things I want to ask, May I plug 2 Arduino UNO board into the Raspberry Pi to make more stair, will it get problem when I do at this method?

bonniee (author)sweetbear_sho2015-03-09

You will need to modify the Python code in order to do so, and you will need to handle receiving communication over two separate Serial ports. It's certainly doable, but will require some programming knowledge of your own.

Alternatively, you can look up how to take in more Analog inputs from an Arduino.

sweetbear_sho (author)bonniee2015-03-10

Thanks for your opinion

Maybe I will try to use another Arduino board to get more analog inputs

And I may have some question about Raspberry
Pi later

charis.rumer (author)2015-01-20

If I use LEDs are you sure that the light is bright enough?

akvaal (author)2013-11-20

you also could replace the Raspberry pi with a wave shield for the arduino

Actually you can't use a Wave Shield like this. Wave Shields are bound to only playing one sound at a time. In this video, you can hear the sounds of each piano key overlapping as they ring out.

sarashabadaisglavo (author)2014-12-29

hello, can explain better the design of the circuit?

melodylovesmiguel (author)2014-08-06

Hey there! May I know if the other models of Arduino or Raspberry Pi would work with this setup? If there a restriction on which types we can use?

And can I see the full setup of wires? Because I know almost next to nothing when it comes to circuits :(

awesnap (author)2013-11-30

How much would this cost

wck86 (author)awesnap2014-02-02

I already had the arduino, rpi, breadboard and some flashlights. I had to buy some photoresistors at radio shack for $5, a 3 pack of cheap flashlights for $5 and some wire for $10.

awesnap (author)2013-11-30

And could you do this without soldering

bonniee (author)awesnap2014-02-02

Yeah, soldering isn't really necessary. You could chain together a bunch of alligator clips, for example, and that would probably work fine. wck86 has some good ideas too. I prefer to solder because it results in a more reliable connection. We actually cheated...some of the ground wire bits are wrapped together, not soldered, because we misjudged the lengths!

wck86 (author)awesnap2014-02-02

It can probably be done without soldering, see my comment on the page for details. The cost is very low if you have an arduino, flashlights and raspberry pi on hand, everything can be bought at radio shack pretty cheap.

Ninzerbean (author)2013-11-22

Would small wiener dogs be able to set off the notes as well, assuming they only need to break the light beam? Can't you just make this for me to buy? I'm never going to understand breadboards and Arduinos.

bonniee (author)Ninzerbean2013-11-22

Small dogs would definitely be able to set off the notes! It would just depend on how wide the individual stairs are, and where you align the flashlights. But we had some dogs walk through that triggered them, actually. :)

traisjames (author)2013-11-21

I sense upcoming injuries

Penolopy Bulnick (author)2013-11-20

OMG! They have these at the Science Museum in MN, how awesome that you were able to make them! BRAVO!

bonniee (author)Penolopy Bulnick2013-11-21

Thanks! :)

truliwicked (author)2013-11-21

that's too sweet!!! Now if I only owned a house....

About This Instructable




Bio: Software engineer at Twitter, based in NYC. Member of NYC Resistor. I do stuff with Arduino, musical programming, and lasers. See more of my projects ... More »
More by bonniee:Internet of Dirt: a Texting PlantIllumaphone: Light-based Musical Instrument with ArduinoCaramelize Sugar onto Chocolate with a Laser Cutter
Add instructable to: