Introduction: Arduino Air Cap-Sense Piano

I recently got my shipment of 10 buzzers I ordered about a month ago, so as soon as I got them I was eager to make something fun with them, so I looked around a bit and searched for what to do with them, and by spending some time on www.arduino,cc and posting lots of questions on the forums, I figured out what I am going to make.

I decided to make an air piano which is based upon cap-sense and the arduino.

Materials;
  1.     Aluminum tape or aluminum foil
  2.     Some wires
  3.     8 10M Ohm resistors
  4.     Piezo buzzer
  5.     Arduino
  6.     9V battery or USB cable


Basically, there are square pieces of aluminum tape stuck onto a thick card which is attached to a jumper cable and a resistor, 8 replicas of this are made, then all the other ends of the resistors are attached together and to pin3 of the arduino, this will act as the common base pin for all the sensors. The resistor values can be 2M or 10M or 40M Ohm. 2M Ohm will make it so that it only senses when you press on the aluminum tape, 10M Ohm resistor makes it so that your hand can be sensed at a little height of 2-4cm or so and 40M Ohm will sense quite a bit further, but it gets a little messy as if the aluminum tape pieces are too close together then at that height interference occurs therefore other keys might get pressed. If you want to use this 40M Ohm version then you have to make sure to place the aluminum tape pieces a little far away from each other.
I used 10M Ohm for my device and it works perfectly when I wave my hand over the note I want to use.

Step 1: What Is Cap-Sense and How Does It Work

The principle behind this is that the aluminum tape detects the difference between human body capacitance and the capacitance of air, or in other words the aluminum tape is given a small voltage by the arduino which creates an electrical field in that area, and when our finger(being a conductor) touches it or moves close to it so as to disturb the electric field, we form a capacitor. This change is detected by the aluminum tape and therefore sends a signal to the arduino with which we can tell it to send a signal to the buzzer.

(I have heard that we can also use resistive sensing instead of capacitive but I'm not exactly sure how it works.)

For more information: http://en.wikipedia.org/wiki/Capacitive_sensing

Step 2: Pinout Diagram and Wiring

I attached a piezo buzzer to pin A0 or Analogue Pin 0, the common pin to pin 3 and the 8 different squares of aluminum tape to 4,5,6,7,8,9,10,11 pins.

Schematic in attached as an image.

Tip: Attaching wire to the aluminum tape its simple as the tape is sticky, but if you are using pieces of aluminum foil then its kind of hard to do it as solder does not work and you cant use a glue-gun or anything of that sort, so I would advice you to use some conducting glue if you can get hold of it
Here is a link where you can get some conducting glue.
http://www.ebay.in/itm/Electrical-Conductive-Glue-No-Soldering-Iron-Gun-Flux-/270754006766

Step 3: Finishing Up the Casing

Now once you have wired up everything, you will have to find a cardboard box or make one so that you can encase everything neat and firm in the cardboard box.

Once that has been done, then make sure there are no lose connections anywhere and there are no short circuits anywhere.

You can use duct tape to insulate any wires or anything that are hanging out and to make it look a bit neater.
If you want it to be durable even when it falls down you can make sugru tabs on the 8 edges to make sure the cardboard does not get damaged when you throw it down, not really sure why you would do that though.

Step 4: Arduino Code

This is the code I used; (Make sure you have the library installed beforehand, link to library;
http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

#include
#include "pitches.h"

#define COMMON_PIN      3  
#define BUZZER_PIN      A0 
#define NUM_OF_SAMPLES  1 
#define CAP_THRESHOLD   100

#define NUM_OF_KEYS     8

#define CS(Y) CapacitiveSensor(2, Y)

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5};

CapacitiveSensor keys[] = {CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10), CS(11)};

void setup()
{
  for(int i=0; i<8; ++i)
  {
    keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
  }
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop(
{  
  for (int i = 0; i < 8; ++i)
  {
    if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD)
    {
      tone(BUZZER_PIN, notes[i]);
      delay(100);
      noTone(BUZZER_PIN);
    }
  }
}

What the code does is first include the 2 libraries, capacitivesensors.h and pitch.h, pitch.h is used for using the tone command with notes such as A2,B6,F2 etc instead of frequencies themselves.Then it defines the pins and the capacitor threshold, this is basically the amount of "sensing" the capacitor does, if you reduce it then the sensor detects more easily if increased it does the opposite.
Then you are defining the notes for each key pressed, and then you define the pins the keys or aluminum tape pieces are connected to.
In void setup you set buzzer pin as output and you set calibration to 0.
In the void loop you are saying that if the tape detects your finger, then the if statement gets executed, therefore the buzzer is played with the respective note. If that does not happen then since there is no else function, it just goes through void loop again.

The tone() command sets the tone to be played on the buzzer, you can also use the tone command to play separate plain notes as tone(pin, frequency, duration) but we use notes here with the pitch.h so we do not need to bother with that.

Step 5: Final Thoughts and How to Improve+Video

After building this fun project, now I'm thinking about building something much more awesome with this capacitive sensing, maybe a keyboard(Computer keyboard) or maybe a touch-pad mouse for the computer....

Hope to see what others do with this Cap-Sense arduino combination, and if anyone makes this it would be awesome if you shared pictures of the finished project :)

Links;

    Cap-sense Arduino Library: http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense


Inspiration/Credit;
  1.     http://www.youtube.com/watch?v=aaBAp47QujA (Idea Start)
  2.     http://hackaday.com/2011/11/21/simple-touch-sensors-with-the-arduino-capsense-library/ (How does Cap-sense work)
  3.     https://www.instructables.com/id/Capacitive-touch-MoodAmbilight/step3/Capacitive-Touch-Code-Testing/ (Initiative for   Cap-sense)
  4.     http://www.youtube.com/watch?feature=player_embedded&v=GFp9yhYXTUg (More Inspiration)
  5.     http://blog.makezine.com/2008/05/16/build-the-arduino-pocket/ (Inspiration for making a piano)
  6.     Tyler Crumpton, J Z Chen and Nicholas Jones were the people who worked around with this technology to make all sorts of things so all the credit goes to them.

Brief Video; (Cap-Sense Air Piano)

Comments

author
mhidalgo3 made it! (author)2013-07-04

Hi excelent you project!!! Only want question if I want more inputs is it possible with the arduino UNO, like a real piano

author
vishalapr made it! (author)vishalapr2013-07-05

Its possible with most of arduino boards, u can get upto 20 or so outputs on arduino uno and duemilanove and upto 50-60 outputs on mega
If you need more outputs then you can try multiplexing, I didn't try it but it should work (Like an LED cube).

author
Orngrimm made it! (author)2013-05-26

Nice 'ible!

And to answer the question you asked: Resistive sensing uses a different method. Simple put, there are 2 foils (Normally bith transparent) with a bad but existing conductivity stacked over each other with tiny beads sandwitched to keep them apart. If you press on the top-foil it bulges down and connects to the foil below. Since the Foils have a given resistance for each mm in distance, you can read the voltage (analog) and determine how far in in the X and Y-direction you are.
The foils are cheap on dx.com if you want to experiment with them.

author
vishalapr made it! (author)vishalapr2013-05-27

Thx :)
ah so the distance between the 2 foils is what does all the sensing in the resistive one?
so it cant be used to have it in air and can only be used to have it when the keys are touched I think...

author
Orngrimm made it! (author)Orngrimm2013-05-27

Correct. Resistive touchpads need a mechanical force for deforming the foil.
See IMAGE for a simple representation of one single dimension.
And if you look at this IMAGE you see both dimensions and also the formulas to calculate the positions... :)

author
vishalapr made it! (author)vishalapr2013-05-27

Ok :D I understand now,
Thanks!

author
SuperTech-IT made it! (author)2013-05-26

It might have been nice to see (hear) the unit in action. If you're going to go to all that trouble to produce a video, I don't think it would have been that much extra effort...LOL

author
vishalapr made it! (author)vishalapr2013-05-27

Its just that Im horrible at playing it XD so Im trying to learn a simple song first and then Ill make another vid with it in action :)

author
SuperTech-IT made it! (author)SuperTech-IT2013-05-27

Thanks for the video. I used to actually make touch sensitive inputs for circuits a way back in the 80's - early 90-s. I am sure you have heard of a Darlington pair...well, if you get up to a darlington quadruplet, touching the base of the first transistor would produce enough signal at the fourth transistor's output, that you could trigger other circuits. It might have been nice to have this back then. Thanks though, I didn't know the Arduino (Atmel) could do this til now. I think it's time to get rid of push-buttons!

author
vishalapr made it! (author)vishalapr2013-05-27

Yea that would be like super annoying, glad I was able to teach something :)

author
vishalapr made it! (author)vishalapr2013-05-27

Ok I made a vid :) I kinda managed to play jingle bells but badly lol

About This Instructable

28,786views

102favorites

License:

Bio: A programming enthusiast. I tinker around with everything I see and love to game.
More by vishalapr:Diffused Glue Stick LampATtiny85 POV DisplayArtoo [R2] (ATtiny2313 Wall Avoiding Robot)
Add instructable to: