written on March 26th, 2012 at 2:12 am by


The piano box is a (somewhat polyphonic) paper toy synthesizer with 12 keys, each triggering a tone and an LED. The keys are a set of capacitive sensors, made of copper tape, controlled by an Arduino Mega running the CapSense and Tone libraries.

The code for this project, written by Will Byrd and Catarina Mota, can be downloaded here. Please note that the current version of the Tone library has some problems on Arduino 1.0. so it’s best to use version 23 or earlier.

Raphael plays the piano box!

To make your own, simply follow the CapSense instructions to create a capacitive sensor for each key:

Capsense wiring illustration

The capSense method toggles a microcontroller send pin to a new state and then waits for the receive pin to change to the same state as the send pin. A variable is incremented inside a while loop to time the receive pin’s state change. The method then reports the variable’s value, which is in arbitrary units.

The physical setup includes a medium to high value (100 kilohm – 50 megohm) resistor between the send pin and the receive (sensor) pin. The receive pin is the sensor terminal. A wire connected to this pin with a piece of foil at the end makes a good sensor. For many applications, a more useful range of values is obtained if the sensor is covered with paper, plastic, or another insulating material, so that users do not actually touch the metal foil. Research has shown that a small capacitor (100 pF) or so from sensor pin to ground improves stability and repeatability.

When the send pin changes state, it will eventually change the state of the receive pin. The delay between the send pin changing and the receive pin changing is determined by an RC time constant, defined by R * C, where R is the value of the resistor and C is the capacitance at the receive pin, plus any other capacitance (e.g. human body interaction) present at the sensor (receive) pin. Adding small capacitor (20 – 400 pF) in parallel with the body capacitance, is highly desirable too, as it stabilizes the sensed readings.

I used copper tape for the capacitive sensors/keys but any conductive material will work.

And then follow the Tone library instructions to connect your microcontroller to the speakers. You can use just one speaker, but you’ll need one pin + resistor per ‘player’. The number of players determines how many tones you can play at once and depends on the number of hardware timers available on your microcontroller. On the Piano Box we are using five of the Arduino Mega’s six hardware timers, which allows us to play five tones simultaneously.

Tone library wiring illustration


4 Responses to “piano box”

  1. Richard Ross

    4 years ago

    Catarina Moto &/or NYCR, We’re having our first “Maker Faire” here in
    Tampa, Fla., Also called “Tampa Bay Mini Maker Faire”, at University Area Community Center Complex, 14013 N. 22nd St, Tampa. Its a gathering of inventors, tech whizzes, artists & even hackers. Event organizer is Terri Willingham, president of nonprofit Learning is for Everyone. University of South Florida’s Robotics Interest group, marine scientist
    Erica Moulton, Sarah Thee Campagna & 20 others will be showing at event.
    Tampa Bay Inventors Council will also be there.
    Why don’t you look into coming on down? Contact Susan Thurston:
    sthurston@tampabay.com. Regards Richard Ross

  2. admin

    4 years ago

    Hi Richard. That’s great! I’m afraid I can’t make it down to Tampa this year, but I’ll pass it along to NYCR.

2 Trackbacks For This Post

  1. The Piano Box « adafruit industries blog Says:

    [...] music in the video is a bit high, so you’ll have to listen carefully. I suggest you run through the code at her site to get an idea of how this works too. From the NYCR blog: The piano box is a (somewhat [...]

  2. Cool Arduino Mega images | Arduino collector blog Says:

    [...] More info @ http://www.openmaterials.org/catarina [...]

leave a reply