Maker.io main logo

Dance on Your Own BIG Keyboard with Arduino

2017-03-29 | By All About Circuits

License: See Original Project Arduino

 

Courtesy of All About Circuits

This BIG piano will help exercise the mind and body! All you need is a few buttons, a speaker, and some dancing shoes.

 

Bill of Materials

Why?

Ryan was watching the movie Big when and he was overcome with the urge to dance on a giant keyboard like Tom Hanks. With no genie or fortune teller nearby to help make this keyboard big, he decided to make his own. With some foamcore board and other miscellaneous art supplies lying around, he got to prototyping and came up with an easy-to-follow recipe for makers!

He wanted to keep this project simple, so he figured most viewers were more likely to have pushbuttons lying around than force-sensitive-resistors. He glued his extra buttons to the bottoms of the giant piano keys. FSRs can used for the keys instead, which makes for a softer touch, but we’re sticking with the pushbuttons for this project.

The Arduino, breadboard circuit, and speaker

The Arduino, breadboard circuit, and speaker

How Does it Work?

This project can be simply assembled on a breadboard, so the foamcore board isn't necessary. The video covers the basics of measuring, cutting, and attaching the pushbuttons, so we'll stick to the technical details here. If you don't have enough buttons for a whole octave, you can 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 the importance of a pulldown resistor. A pulldown resistor "holds the logic signal near zero volts when no other active device is connected," (Arduino Playground). This helps to ensure accurate and reliable readings from our pushbuttons.

Basically, there are 8 pushbuttons connected to pins 2-9 respectively. Each button needs 5v power, a 10k pulldown resistor, and a signal line to the input pins. In our program, each of these buttons is assigned a specific square-wave frequency to play whenever the button is pressed (logic HIGH). These are specific frequencies are used to create a musical scale.

Scheme-it: A basic look at our inputs and output

A basic look at our inputs and output

There are many different types of electrical waves, such as sine waves, sawtooth waves, and triangle waves. For this project, our Arduino uses square waves. To create sound from these buttons, our speaker needs to be driven by an Arduino pin that can handle pulse-width modulation (PWM). Arduino pins that can produce PWM generate square waves of varying frequency.

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

The 8 buttons represent 8 notes on a musical keyboard/piano, or a full octave scale, in this case, a C Major scale. These notes include C5, D5, E5, F5, G5, A5, B5, and C6. You’ll notice that there are two different C notes, C5 and C6.

C6 is twice the frequency of C5, also known as an octave, but is still considered note C. C5's frequency is 523Hz and C6 is 1047Hz. It isn’t perfectly "in tune", but this is as close to a proper signal that the Arduino can produce.

Pianos and musical instruments may seem intimidating, they are just the same notes repeating over and over again in different "octaves." For example, G7 would be triple the frequency of G5.

A waveform comparison of an octave

A waveform comparison of an octave

That’s enough music lessons for today. The speaker’s positive lead should have a 220 ohm resistor in series with pin 10, which can produce PWM, the other lead should be tied to ground. Since we’re using square waves, the signal has harmonic frequencies in addition to the fundamental frequency. Ideally, we’d use a sine wave for better sound quality but the square wave will get the job done for this project.

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

Repeat these steps with all of the buttons you own and you'll have your own giant keyboard!

Arduino Code

Copy Code
                  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

Now let's get to dancing!

Other MIT-i Innovations

制造商零件编号 A000066
ARDUINO UNO R3 ATMEGA328P BOARD
Arduino
制造商零件编号 GF0666M
SPEAKER 8OHM 500MW TOP PORT 88DB
Same Sky (Formerly CUI Devices)
制造商零件编号 MJTP1230
SWITCH TACTILE SPST-NO 0.05A 12V
APEM Inc.
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum