Capacitive-Touch Arduino Keyboard Piano

217,640

437

90

Using only an Arduino, a few resistors, a buzzer, and some bits of aluminum foil, you can create your own touch-sensor piano keyboard in just a few minutes! Using an Arduino Uno, you can create a piano with up to 18 keys; or with an Arduino Mega, you can get over 60 keys! Other Arduino boards should work with this project with little to no modification to the code.

 

Step 1: Parts and Material

You'll first want to collect all of the parts you will need for the project:

• An Arduino (or Arduino-compatible) microcontroller board.
    • Any Arduino board should work: Uno, Leonardo, Mega, Pro Mini, etc.
• Eight 2.2 Megaohm (2.2 MΩ) resistors
    • Anywhere between 1 MΩ and 4.7 MΩ should work
    • You need one resistor per piano key
    • A 2.2 MΩ resistor has a color code of Red-Red-Green or Red-Red-Black-Yellow
• A piezo buzzer
• Some spare wires or jumper cables
• Aluminum foil
    • A foot or two should do
• Tape
• A surface to tape your keys to
    • We used a scrap piece of cardboard, but it can be anything you like, even the tabletop itself!

Equipment that you may need:

• Soldering iron and solder
    • You can probably get by without an iron by wrapping wires together instead of soldering, but the connection will not be as reliable
• Scissors to cut aluminum foil and tape

Step 2: The Idea and Design

The basic principle behind our method of touch sensing is that each piano "key" is sensor that can measure the electrical capacitance of a person's body. The measurement will change as the user gets closer to the sensor and will spike dramatically when the user touches the sensor. The Arduino will be looking for these spikes in order to detect when the user has touched the key.

We will need to use one pin an the Arduino for each key as an "input pin", and we'll need one pin total to be used as the "common send" pin. We will also need one pin for the buzzer that will be used to generate a tone. This means that since an Arduino one has 20 input pins (14 digital and 6 analog), we can have up to 18 keys on our keyboard! If you have an Arduino Mega or any other board with more pins, that number can be even higher!

Step 3: Create Your "Keys"

Out of your aluminum foil, cut a few shapes to be your piano "keys". Any shape will do, but we took the simple route and made squares. Each key should be somewhere between 2"x2" and 4"x4", but most other sizes will work as well.

Step 4: Assemble the Key Circuitry

Each touch-sensitive "key" on the piano is going to require one resistor and two wires/cables. Solder one wire to each leg of the resistor, but make sure to leave part of the leg sticking out. The leg will be used to connect to the foil in the next step. Make as many of these as you plan on having piano keys.

Step 5: Connect the Foil "Key"

Remember the extra bit of leg we saved? Take it and poke it through a corner or side of one of your aluminum foil squares. Fold the leg over the edge back towards itself to make the connect hold more strongly. Go ahead and assemble all of your keys.

Step 6: Attach the Keys

Using your tape, attach each key to your surface, making sure to leave some of the foil exposed. It's okay to tape over the resistor, but be sure to remember which wire is attached to the side of the resistor that is touching the foil and which wire is not.

Step 7: Finish the Wiring

After attaching all of your keys to the surface, take the wire that is connected to the resistor (but not on the side connected to the foil) and connect to the the same side of the resistor on the adjacent key. Basically, we want to connect all of the non-foil-sides of the resistors together. These can be soldered are just connected with tape.

You will have one wire left over that is not connected to anything; this will be our "common send" wire.

Step 8: Hook Up the Arduino

Connect the "common send" wire left over from the previous step to Pin 2 on the Arduino. Then, connect the "key" wires to Pins 3-10, starting with the left-most key on Pin 2 and ending with the right-most key on Pin 10.

Take your buzzer and connect the pin marked negative (-) to a ground (GND) pin on the Arduino. Connect the pin marked positive (+) to Pin A4 on the Arduino. (NOTE: Depending on your buzzer, you may need connect a resistor between the A4 Pin and the positive side of the buzzer. This is to prevent the buzzer from drawing too much current from the Arduino pin and possibly damaging it. A 220 Ohm resistor or greater should work fine for most buzzers.)

Step 9: The Code

Before you can start playing your newly-built piano, you will need to obtain and install the CapSense Arduino library if it is not already installed. This can be downloaded from Github here. If you do not know how to install third-party Arduino libraries in you version of the Arduino IDE, reference this guide on Arduino.cc.

Attached below, uou will find a zip file that contains the Arduino code for the Capacitive-Touch Arduino Keyboard Piano. Download it and unzip it somewhere on your computer. Open CapSensePiano.ino in the Arduino IDE and upload the code to your Arduino.

Step 10: Play!

And that's it! You should now be able to tap on the foil keys and hear the corresponding notes played through the buzzer. If the keys are not very responsive, or are trigger without being touch, you can adjust the CAP_THRESHOLD value in the Arduino sketch to set what value that the keys are triggered at. Lower values will cause the keys to be easier to trigger, and higher values will reduce the number of keys that are mistakenly triggered.

You can also change the scale that is played by uncommenting one of the few scales included, or make your own scale! If you make your own piano, please comment and show us some pictures and videos. We'd love to see some creative instruments!

Thanks for reading!

Credit for this project goes to Nicholas Jones and Tyler Crumpton.

4 People Made This Project!

Recommendations

  • Plastics Contest

    Plastics Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Optics Contest

    Optics Contest

90 Discussions

Hi there,

I made this the other day but I used a breadboard instead of directly wiring the pieces to each other. I thought I should upload a diagram of the wiring I used just in case anybody else wants to make this using a breadboard. I also made some adjustments in the code to work for the amount and size of keys I had (about 1" wide by 2" long), including mrizkalla's adjustments to stop the loop effect. I've uploaded it to my Google Drive and it can be found by clicking here: https://drive.google.com/folderview?id=0B53IAtyS3-7NbF9jTmFMd1U4eU0&usp=sharing

Wiring Diagram-01.jpg
5 replies
0
None
Naz Cmegantissington

Reply 1 year ago

Hey there! I made a keyboard piano today using your schematic. It worked amazingly! Thank you =)

0
None
gjuyalmegantissington

Reply 2 years ago

Where can I see the video of this working circuit . I am having a little problem. Cant hear the change in notes.??

0
None
DejfM

Question 22 days ago

Hi, really nice project, i made it too, but with 17 keys, and not working perfectly, if i setup to 1-10 keys, everything works good, bud if i add one more key then go ..ergh. random delay time, repeating tones, and other bug.
Have you any idea? Thank you very much

code is modified to:

#include
#include "pitches.h"
#define COMMON_PIN 2 // The common 'send' pin for all keys
#define BUZZER_PIN A4 // The output pin for the piezo buzzer
#define NUM_OF_SAMPLES 17 // Higher number whens more delay but more consistent readings
#define CAP_THRESHOLD 80 // Capactive reading that triggers a note (adjust to fit your needs)
#define NUM_OF_KEYS 17 // Number of keys that are on the keyboard
// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:
#define CS(Y) CapacitiveSensor(2, Y)
// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:
//int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale
//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale
int notes[]={NOTE_C4,NOTE_CS4,NOTE_D4,NOTE_DS4,NOTE_E4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_GS4,NOTE_A4,NOTE_AS4,NOTE_B4,NOTE_C5,NOTE_CS5,NOTE_D5,NOTE_DS5,NOTE_E5};
// Defines the pins that the keys are connected to:
CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10), CS(11), CS(12), CS(13), CS(A0), CS(A1), CS(A2), CS(A3), CS(A5), CS(A6)};
void setup() {
// Turn off autocalibrate on all channels:
for(int i=0; i<4; ++i) {
keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
}
// Set the buzzer as an output:
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// Loop through each key:
for (int i = 0; i < 10; ++i) {
// If the capacitance reading is greater than the threshold, play a note:
if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {
tone(BUZZER_PIN, notes[i],250); // Plays the note corresponding to the key pressed
}
}
}

IMG-2493.JPGIMG-2494.JPG
0
None
MohammedA534

Question 9 months ago on Step 9

where did you create the piano.h file? and how?

0
None
sososolame

2 years ago

Our project almost worked! But, the buzzer won't stop playing until next key is pressed or unplugging Arduino. We tried to add a ELSE statement, to add delay, to remove for loop but none of these methods worked. Do you have any advice? We assemble circuits exactly like yours and used your code.

3 replies
0
None
pgr23sososolame

Reply 2 years ago

Tyler, i have the same problem, please tell us how to repair it

0
None
FernandoS116sososolame

Reply 2 years ago

You must add the time 250 in line "

tone(BUZZER_PIN, notes[i], 250); // Plays the note corresponding to the key pressed

"

0
None
TimmdB

2 years ago

Hello,

I'm trying to rebuild this for a school project, however I've encountered a problem. I hae completely recreated the circuit and used the same code but somehow when the buzzer doesn't stop making a sound. When I touch a different key it will change the tone but when I release the key it will keep on going in that tone. Please can someone help me!

Tim

3 replies
0
None
Maik 234TimmdB

Reply 1 year ago

You need to add a notone line

0
None
nishthiMaik 234

Reply 1 year ago

where do i add the no tone line

0
None
nishthi

1 year ago

it's an amazing project.. got it all right ...just exchanged the buzzer to a speaker..clearer and better sound..and it was not working for me and I switched over the buzzer connections..attach the positive to GND n negative to A4...and it works perfectly.

all I didn't get is how it works...like how is the sound produced when I touch the key...

can someone help me I need to explain my project..

0
None
Lokesh kumar08

1 year ago

I have some problems in making the key can anyone help me out in making one

0
None
circumlocutus

2 years ago

i had a bunch of students make this as a crash course in soldering and programming, it was a hit.

0
None
NishthaY

2 years ago

Please tell me how you connected the buzzer.
I made the same as you did but the buzzer is continuously making sound.