Maker Pro
Arduino

How to Make a 'BIG' Push-Button-Activated Piano With Arduino Uno

June 30, 2017 by Ryan Jones
Share
banner

Make a "Big" piano you can play with your feet with an Arduino Uno, pushbuttons, resistors, and some foam board.

Ever wanted to make a giant piano that you can play with your feet? Now you can with an Arduino UNO, some pushbuttons, some resistors, and some foam board!

Why?

I was watching the Tom Hanks movie "Big" the other day, and I realized I really wanted to dance on a giant keyboard. There weren't any fortune tellers or genies nearby to help make this keyboard big, so I needed to get to thinking. I had some quality foamcore board lying around along with some other miscellaneous art supplies, so I got to prototyping and came up with an easy-to-follow recipe for a BIG, pushbutton-activated piano!

I wanted this project to be as easy to recreate as possible, so I figured that most viewers were more likely to have pushbuttons lying around than force-sensitive-resistors, so I glued my extra buttons to the bottom of the keys. Adding FSRs to the keys instead would make for a softer touch, but I'll leave it to you to improve my design!

A closer look at our components

How Does the Big Arduino Piano Work?

The video covers everything you need to know to make the keyboard and attach the pushbuttons, so I'll just stick to the technical details here. If you don't have enough pushbuttons, you can still follow along with just one pushbutton, some resistors, and a speaker.


If you've used an Arduino before, you've probably used a pushbutton and understand how important a pulldown resistor is. A pulldown resistor "holds the logic signal near zero volts when no other active device is connected", (Arduino Playground). This helps to ensure that we get reliable and accurate readings from our pushbuttons.

We have eight pushbuttons connected to pins 2-9. Each button requires 5V power, a 10k pulldown resistor, and a signal line to the input pins. Each of these buttons can be assigned a specific square-wave frequency to play whenever the button is pressed (logic HIGH) within our program. These are specific frequencies that help create musical scale.

A basic look at our inputs and output

There are many different types of electrical waves, including sine waves, square waves (which we will be using), triangle waves, and sawtooth waves. To create sound from these buttons, our speaker needs to be driven by an Arduino pin that can handle pulse-width modulation (PWM). Square waves of varying frequency are generated by the Arduino pins that can produce pulse-width modulation.

We don’t actually need to vary the pulse width of our signals. All our speaker signals will be 50% duty cycle. But we will use an Arduino PWM pin because the PWM functionality provides an easy way to set the frequency.

Our eight buttons represent eight notes on a musical keyboard/piano, a full octave scale—specifically, the C major scale. These notes include C5, D5, E5, F5, G5, A5, B5, and C6.

You probably notice that there are two different C notes, C5 and C6. Note C6 is simply twice the frequency of C5, an interval known as an octave, and is still considered a C note. While C5's frequency is 523Hz, C6 is 1047Hz. Though not perfectly "in tune", this is as close to a proper signal that the Arduino can produce.

Pianos and other musical instruments can be intimidating, but they're just the same notes repeating over and over again in different "octaves". For example, the note G7 would be triple the frequency of G5.

A waveform comparison of an octave

That concludes the music lesson! The speaker's positive lead will need a 220 ohm resistor in series with pin 10 (pin 10 can produce PWM). The other lead should be tied to ground. Because we are using square waves, the signal has harmonic frequencies in addition to the fundamental frequency. Ideally, we would use a sine wave for better sound quality but the square wave is good enough for our purposes.

Looking at our code, we use simple statements to produce specific frequencies within the "pitches.h" library each time a certain button reads logic HIGH. For example, you'll notice that note F5 is 698Hz while F6 is about double in frequency, 1397Hz.

Just repeat these steps with all of the buttons you own and you'll have the world's biggest keyboard! You can find a downloadable version of the code at the bottom of this tutorial.

if (buttonCState == HIGH) {
tone(10, NOTE_C5);
}


if (buttonDState == HIGH) {
tone(10, NOTE_D5);
}

if (buttonEState == HIGH) {
tone(10, NOTE_E5);
}

if (buttonFState == HIGH) {
tone(10, NOTE_F5);
}
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397

Author

Avatar
Ryan Jones

Start my career as an Audio Engineer, now turned professional maker!

Related Content

Comments


You May Also Like