piano box

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



Leave a Reply

Your email address will not be published. Required fields are marked *