Piano Stairs With Arduino and Raspberry Pi

83,273

459

46

About: 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 at http://blog.bonnieeisenman.com.

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

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

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.

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

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):
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)

Step 6: 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 ohboymusic.py!

https://github.com/bonniee/piano-stairs

Image from raspberypi.org


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!

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.



Raspberry Pi Contest

Finalist in the
Raspberry Pi Contest

4 People Made This Project!

Recommendations

  • Tape Contest

    Tape Contest
  • Arduino Contest 2019

    Arduino Contest 2019
  • Trash to Treasure

    Trash to Treasure

46 Discussions

0
None
Idea_Lab

Question 10 months ago

Hi Bonniee!

I'm Jeff, I work at a public library in Michigan, and I'm trying to build your Piano Stairs for our library! I'm pretty new to this sort of project, but I've had pretty good luck so far! I've whipped up the circuits you describe, and I've installed the correct program onto the Arduino (I'm using a Mega 2560, since it has enough analog pins), and it appears to be outputting the correct serial information. However, when I plug the arduino in the the Raspberry Pi, and run your included software, two unusual things happen! First, when I initially run the software, I'm told to add a couple parenthesis around a certain "call to print". After I add the parenthesis, the program will actually run. Once running, however, the software seems to simply play the samples in chromatic order, then stop. No samples are triggered by any interaction with the arduino's photocells. I know it's been a VERY long time since you posted this project, but I sure would appreciate if you can provide me with any advice or assistance.

Thanks!

- Jeff

1 answer
0
None
SannanFIdea_Lab

Answer 5 months ago

Hi,
I am having the same problem... I wanted to ask you, If you figured out the solution? Have you solved the problem? Please share as I am learning the raspberry pi and this project will help me a lot..!!

1
None
Idea_Lab

10 months ago

Hi Bonniee!

I'm Jeff, I work at a public library in Michigan, and I'm trying to build your Piano Stairs for our library! I'm pretty new to this sort of project, but I've had pretty good luck so far! I've whipped up the circuits you describe, and I've installed the correct program onto the Arduino (I'm using a Mega 2560, since it has enough analog pins), and it appears to be outputting the correct serial information. However, when I plug the arduino in the the Raspberry Pi, and run your included software, two unusual things happen! First, when I initially run the software, I'm told to add a couple parenthesis around a certain "call to print". After I add the parenthesis, the program will actually run. Once running, however, the software seems to simply play the samples in chromatic order, then stop. No samples are triggered by any interaction with the arduino's photocells. I know it's been a VERY long time since you posted this project, but I sure would appreciate if you can provide me with any advice or assistance.

Thanks!

- Jeff

1 reply
0
None
SannanFIdea_Lab

Reply 5 months ago

Hi,
I am having the same problem... I wanted to ask you, If you figured out the solution? Have you solved the problem? Please share as I am learning the raspberry pi and this project will help me a lot..!!

0
None
JuanO106

Question 7 months ago on Introduction

Hola bonnie.

Soy Juan Pablo Molina Soy Docente en Colombia y trato de hacer tu piano con algunos estudiantes, pero no tengo experiencia con Arduino y mucho menos con Raspberr, ,i pregunta es:

1.¿solo debo subir el código al arduino?

2.¿instalo en el raspberry para que funcione?

3.¿solo debo subir los codigos o como los vinculo par que funcionen?

0
None
Froggit37

Question 1 year ago

Hi there! I've already tried the project and it seems to be working well. Just one concern, there's some latency when the arduino communicates to the raspberry pi to create the sound. I'm open to ANY solutions at the moment. Please help.. thanks!

0
None
EdrickK

1 year ago

Also, can the code be used on Arduino Due

0
None
EdrickK

1 year ago

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

0
None
ValentinaT6

1 year ago

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

0
None
berlingozzo

2 years ago

lovely project :)

I may add the piano effects to this other project:

https://www.instructables.com/id/Automatic-IoT-Staircase-Glowing-Lighting/#

0
None
SonnyM9

2 years ago

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

0
None
SonnyM9

2 years ago

How many K has the ldr's?

0
None
TomX2

2 years ago

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!!!

1 reply
0
None
AlT31TomX2

Reply 2 years ago

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)

0
None
EspenT2

3 years ago

Hi!
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!

DSC_0351.JPG
0
None
aann7

3 years ago

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. :(

0
None
MaryB43

3 years ago

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 :)

0
None
miltono

3 years ago on Introduction

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