Instructables

Capacitive-Touch Arduino Keyboard Piano

Featured
Picture of 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.

 
 
Remove these adsRemove these ads by Signing Up

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
Can you please tell me how to hook this up to an external powers (meaning no laptop involved for portability purposes)
tylercrumpton (author)  jordanguy1231 month ago

You've got a few options available that should work!

1) Search eBay/Amazon for "9v arduino" and find a battery clip that lets you hook up a 9V battery to power the Arduino through the barrel jack connect on the board, or

2) Use a rechargeable USB battery pack (can also be found on eBay/Amazon) to power the Arduino over the USB port.

Note: I've never tried to power this particular project off of battery power, so it's possible that the grounding may be a little strange for the sensor pads. If you try it out, please let us know how it goes!

tylercrumpton (author)  jordanguy1231 month ago

You've got a few options available that should work!

1) Search eBay/Amazon for "9v arduino" and find a battery clip that lets you hook up a 9V battery to power the Arduino through the barrel jack connect on the board, or

2) Use a rechargeable USB battery pack (can also be found on eBay/Amazon) to power the Arduino over the USB port.

Note: I've never tried to power this particular project off of battery power, so it's possible that the grounding may be a little strange for the sensor pads. If you try it out, please let us know how it goes!

mrizkalla2 months ago

Thanks. Very cool. Here is how I changed the loop() function to make it so the sound stops playing when the finger has been lifted off the keys.

void loop() {

unsigned int keysPlaying = 0;

// Loop through each key:

for (int i = 0; i < NUM_OF_KEYS; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

int c = keys[i].capacitiveSensor(NUM_OF_SAMPLES);

if(c > CAP_THRESHOLD) {

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

keysPlaying++;

}

}

if (keysPlaying == 0) {

noTone(BUZZER_PIN);

}

}

ccronkhite5 months ago
I'm also getting the error codes with the Uno. Mine are slightly different though.


sketch_nov14a:32: error: 'CapacitiveSensor' does not name a type
sketch_nov14a.ino: In function 'void setup()':
sketch_nov14a:39: error: 'keys' was not declared in this scope
sketch_nov14a.ino: In function 'void loop()':
sketch_nov14a:50: error: 'keys' was not declared in this scope
tylercrumpton (author)  ccronkhite2 months ago

Hello! Sorry for taking so long to get back to you; do you have the Capacitive Sense Arduino library properly installed? Make sure that this library is installed before trying to run the sketch.

edevane9 months ago
hi, thanks for this instructable! I'm trying to make something based on these instructions using 2.5m ohm (1+1.5m ohm resistors), copper pads about 2x2 inches and a capacitance threshold of anywhere up to 4000. The notes do play but it's outputting a constant tone or arpeggio of the scale when I don't touch anything. What is the range of the cap_threshold? Can you recommend any other alterations? I'm currently making the pads bigger by adding more copper tape to see if that works.

If not I'll try the WWC's suggestion about having a ground plane below the pads, although I've read contradictory information which specifically says to keep ground or other connections away from the cap sensors: http://ww1.microchip.com/downloads/en/AppNotes/01101a.pdf
gower edevane3 months ago

We are having the same problem. It continuously plays the last note touched.

tylercrumpton (author)  gower2 months ago
Hi! That sustained last note might have been caused by a line that was accidentally removed when I was fixing up the code for uploading. Can you try adding the following line to the beginning of the loop()?

noTone(BUZZER_PIN);

Let me know if that helps!

tylercrumpton (author)  edevane9 months ago
Hm, with those pad-sizes and resistor values, you shouldn't be having any issues with constant tones, especially when you crank the threshold that high. Is it just one note a just a few notes that seem to ring, or does it seems like every note is ringing? Here is some code to try that will display the values from the capacitance sensors in the Serial Monitor. What do you see when you run this code found in the pastebin link below?

http://pastebin.com/dP8AUPe7
omadison8 months ago
The code doesn't work. I have installed the library correctly (I think, because it shows on my libraries when the arduino program is opened) and I cannot get the code to verify without this error :
CapSensePiano:32: error: 'CapacitiveSensor' does not name a type
CapSensePiano.ino: In function 'void setup()':
CapSensePiano:37: error: 'keys' was not declared in this scope
CapSensePiano.ino: In function 'void loop()':
CapSensePiano:47: error: 'keys' was not declared in this scope

I really suck with code. That's why I use this site to make cool things without a lot of coding. Can you help me out?
tylercrumpton (author)  omadison8 months ago
Hello! Which Arduino are you using? It looks like there is a separate version of the library for the Arduino Due (which is included in the library .zip file).

Does the sample "CapacitiveSensorSketch" Arduino code that came with the library verify correctly for you? If not, then there may be something wrong with the way the library is set up on your computer.
i am using arduino uno but am experiencing the same problem as omadison
12
tylercrumpton (author)  amore22 months ago

Hi! Sorry for the delayed response; do you have the Capacitive Sense Arduino library properly installed? Make sure that this library is installed before trying to run the sketch.

Hi! Great project! This is my first time using capacitive touch keys and I didn't really understand how they are supposed to be made. The aluminum foil doesn't have to be folded, right?
I tried to tape them just like shown in the pics but they don't seem to work! Any idea why?? Thanks!
Make sure the code on your Arduino Uno/Duemilanove is properly uploaded, I personally found MANY errors within the programming!
akinich4 months ago
Hey this project is awesome
I seem to get confused a bit when you are describing the circuit , is it possible for you to put up a simple circuit diagram ?
Thanks
igneonumous5 months ago
what should i change from the sketch for use it on fl studio via serial midi converter?
Please, any idea? Thanks
omadison8 months ago
And of course right after I ask for help it verifies. lol. Thank you very much for replying so soon and sorry for the stupid question. I am a beginner at this stuff :D I'm interested a lot in making and building electrical devices but i can't stand programming which kinda sucks. But I will get it soon after practicing and mastering circuitry.
tylercrumpton (author)  omadison8 months ago
Awesome, I'm glad it works for you now! No question is a stupid question, especially if you're trying to learn. Feel free to ask for help if you get stuck on anything else!
WWC10 months ago
I have experimented with capacitive touch using the similar method. I had found that at least in my circuit, i needed to make another foil the same size as the key foil and place it under as a grounding plate. Separated by thin card stock.
Nice work.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!