Intro: Capacitive-Touch Arduino Keyboard Piano
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
• 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.