Floating Keyboard

My overall goal was to create a keyboard painted on a piece of acrylic that was suspended between two boxes.

I created two boxes that would hold the speakers to allow for audio output along with a slit for the acrylic to slide into.

Between my two 8″x8″ boxes, I have a piece of acrylic with conductive paint this time painted with a different pattern.
The box on the left hand side houses the arduino, breadboard, wires, and one of the speakers.
I had to hunt through several pieces of code to find something that would work and I came across using conductive paint as a capacitance sensor. Now, I was wanting to use it so that every time the sensor received a signal it would play a piano note but I had no idea how to transfer that into Processing. I eventually came across a game on the internet that transferred arduino signal into Processing so I went off that a little but not a whole lot. What I did find I could do was serial write a number from the arduino into the serial port and have processing read a number and then, based on that number, it would play a piano note. I eventually had to accept that the Arduino would not create the effect that I wanted so I ended up using a MaKey MaKey as seen in my video. The MaKey MaKey provides a touch based keyboard which was my original goal, but I have gone ahead and posted my original code using an Arduino.
Arduino Sketch 

FYI you will need the capacitive sensor library which can be found on the arduino website.


* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10M between send pin and 
* receive pin. Resistor effects sensitivity, experiment 
* with values, 50K - 50M. Larger resistor values yield 
* larger sensor values. Receive pin is the sensor pin 
* - try different amounts of foil/metal on this pin

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);       
//CapacitiveSensor   cs_4_10 = CapacitiveSensor(4,10);
CapacitiveSensor   cs_5_3 = CapacitiveSensor(5,3);
CapacitiveSensor   cs_5_7 = CapacitiveSensor(5,7);
CapacitiveSensor   cs_5_9 = CapacitiveSensor(5,9);
void setup()
    // turn off autocalibrate on channel 1 - just as an example

void loop()
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_4_6.capacitiveSensor(30);
    long total3 =  cs_4_8.capacitiveSensor(30);
    long total4 = cs_5_3.capacitiveSensor(30);
    long total5 = cs_5_7.capacitiveSensor(30);
    long total6 = cs_5_9.capacitiveSensor(30);

if(total1 > 100){
else if(total2 > 100)
else if(total3>100)
else if(total4 > 100)
else if(total5 > 100)
else if(total6>100)
    // arbitrary delay to limit data to serial port

Here is the processing code:

* Simple Read
* Read data from the serial port and change the color of a 
* rectangle when a switch connected to a Wiring or Arduino 
* board is pressed and released.This example works with 
* the Wiring / Arduino program that follows below.

import ddf.minim.*; //import the minim library
import processing.serial.*;

Minim minim; //minim object
AudioInput in; //audio object

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

AudioPlayer keyG;
AudioPlayer keyF;
AudioPlayer keyE;
AudioPlayer keyD;
AudioPlayer keyC;
AudioPlayer keyB;
AudioPlayer keyA;

int count1;
int count2;
int count3;
int count4;
int count5;
int count6;
int count7;

Boolean[] keys;

void setup()
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my  FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[4];
myPort = new Serial(this, portName, 9600);

minim = new Minim(this);
keyG = minim.loadFile("68448__pinkyfinger__piano-g.mp3");
keyF = minim.loadFile("68446__pinkyfinger__piano-f.mp3");
keyE = minim.loadFile("68443__pinkyfinger__piano-e.mp3");
keyD = minim.loadFile("68442__pinkyfinger__piano-d.mp3");
keyC = minim.loadFile("68441__pinkyfinger__piano-c.mp3");
keyB = minim.loadFile("68438__pinkyfinger__piano-b.mp3");
keyA = minim.loadFile("68437__pinkyfinger__piano-a.mp3");

in = minim.getLineIn(Minim.STEREO, displayWidth);

keys = new Boolean[7];
keys[0] = false;
keys[1] = false;
keys[2] = false;
keys[3] = false;
keys[4] = false;
keys[5] = false;
keys[6] = false;

void draw()
    if ( myPort.available() > 0) {  // If data is available,
        val = myPort.read();    // read it and store it in val
    background(255);             // Set background to white
    if (val == 0) {              // If the serial value is 0,
        fill(0);                   // set fill to black
    else {
        // If the serial value is not 0,
        fill(204);                 // set fill to light gray
    rect(50, 50, 100, 100);

void audioPlayer(int dataVal){

if(dataVal == 1)
    keys[0] = true;
if(dataVal == 2)
    keys[1] = true;
if(dataVal == 3)
    keys[2] = true;
if(dataVal == 4)
    keys[3] = true;
if(dataVal == 5)
    keys[4] = true;
if(dataVal == 6)
    keys[5] = true;
if(dataVal == 7)
    keys[6] = true;
    for(int i = 0; i < 7; i++){
        keys[i] = false;


void stop()


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s