Capacitive-Touch Arduino Keyboard Piano





Introduction: Capacitive-Touch Arduino Keyboard Piano

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

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!


  • Oil Contest

    Oil Contest
  • Woodworking Contest

    Woodworking Contest
  • Casting Contest

    Casting Contest

We have a be nice policy.
Please be positive and constructive.



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


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:

Wiring Diagram-01.jpg
5 replies

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

Wonderful, thanks, Megan! I would love to see some pictures of the project!

Hi Tyler,

Here are some pics from when I did the project and a video of me playing Ode To Joy on it... worked pretty well!

Thanks for the comment!


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

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

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

You must add the time 250 in line "

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



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!


3 replies

You need to add a notone line

where do i add the no tone line

thanx..that helped

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 how is the sound produced when I touch the key...

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

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

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

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


Arduino: 1.6.8 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Admin\AppData\Local\Temp\Rar$DIa0.942\CapSensePiano\CapSensePiano.ino:14:30: fatal error: CapacitiveSensor.h: No such file or directory

#include <CapacitiveSensor.h>


compilation terminated.

exit status 1

Error compiling for board Arduino/Genuino Uno.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.


I need some help.

1. My keyboard is playing only 1 note. I cant make out the difference.

2. How can I print the capacitance reading onto serial monitor so I know what values the arduino is picking and calculating.

3. What do the Number of samples mean.

I am using only 5 keys.