Instructables
Picture of Capacitive-Touch Arduino Keyboard Piano
Using only an Arduino, a few resistors, a buzzer, and some bits of aluminum foil, you can create your own touch-sensor piano keyboard in just a few minutes! Using an Arduino Uno, you can create a piano with up to 18 keys; or with an Arduino Mega, you can get over 60 keys! Other Arduino boards should work with this project with little to no modification to the code.

 
 
Remove these adsRemove these ads by Signing Up

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
• Tape
• 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
1-40 of 53Next »
jrtumbles2 days ago

https://learn.sparkfun.com/tutorials/installing-an...

Try this tutorial for installing the libraries. It is much more clear than the arduino site explanation and code worked immediately after installing the libraries properly.

john

jrtumbles3 days ago

Hi Tyler,

I hate to bother you with this especially because you have addressed it so many times before. I am getting the following errors each time I try to compile the library and or sketches.

I have followed the arduino tutorial and tried following the instructions here, but to no avail. Can you help me get this code loaded and working? I am planning to teach this to my grandson as soon as I can get it working right. I absolutely love your projects and the fact that you are helping so many people is just amazingly generous and kind. I would greatly appreciate it if you could kind of walk me through the process and get this working.

Thank you,

John

sketch_nov14a:32: error: 'CapacitiveSensor' does not name a type

sketch_nov14a.ino: In function 'void setup()':
sketch_nov14a:39: error: 'keys' was not declared in this scope
sketch_nov14a.ino: In function 'void loop()':
sketch_nov14a:50: error: 'keys' was not declared in this scope

lucia100116 days ago

Hi, just a quick question. When i press a key, the sound plays perfectly fine, and does what it is supposed to do. However whenever i let go of the key, it keeps playing the same note even though i am not touching the key. Is this supposed to happen? If it isn't, how would i fix this?

omadison1 year ago
The code doesn't work. I have installed the library correctly (I think, because it shows on my libraries when the arduino program is opened) and I cannot get the code to verify without this error :
CapSensePiano:32: error: 'CapacitiveSensor' does not name a type
CapSensePiano.ino: In function 'void setup()':
CapSensePiano:37: error: 'keys' was not declared in this scope
CapSensePiano.ino: In function 'void loop()':
CapSensePiano:47: error: 'keys' was not declared in this scope

I really suck with code. That's why I use this site to make cool things without a lot of coding. Can you help me out?
tylercrumpton (author)  omadison1 year ago
Hello! Which Arduino are you using? It looks like there is a separate version of the library for the Arduino Due (which is included in the library .zip file).

Does the sample "CapacitiveSensorSketch" Arduino code that came with the library verify correctly for you? If not, then there may be something wrong with the way the library is set up on your computer.
i am using arduino uno but am experiencing the same problem as omadison
12
tylercrumpton (author)  amore21 year ago

Hi! Sorry for the delayed response; do you have the Capacitive Sense Arduino library properly installed? Make sure that this library is installed before trying to run the sketch.

sorry i want to ask you

both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

sorry i want to ask you

both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

sorry i want to ask you

both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

sorry i want to ask you

both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

sorry i want to ask you

both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

aasd456917126 days ago

sorry i want to ask you
both program and Material are right but when i tough tHe Aluminum foil

it don`t have sound
this is the program
/*

Capacitive-Touch Arduino Keyboard Piano

Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"

Created 18 May 2013

Modified 23 May 2013

by Tyler Crumpton and Nicholas Jones

This code is released to the public domain. For information about the circuit,

visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-...

*/

#include <CapacitiveSensor.h>

#include "pitches.h"

#define COMMON_PIN 2 // The common 'send' pin for all keys

#define BUZZER_PIN A4 // The output pin for the piezo buzzer

#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings

#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)

#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:

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

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:

int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale

//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

// Defines the pins that the keys are connected to:

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

void setup() {

// Turn off autocalibrate on all channels:

for(int i=0; i<8; ++i) {

keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);

}

// Set the buzzer as an output:

pinMode(BUZZER_PIN, OUTPUT);

}

void loop() {

// Loop through each key:

for (int i = 0; i < 8; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

}

}

}

So I have the circuit hooked up and I did it on a bread board. However, when I use pin 2 as the send pin it does not work. if I unplug the wire in pin 2 it sends it perfectly, but continually plays iwthout touching. I must add, I am also using pop cans instead of pieces of aluminum. Any suggestions?

Angela

tylercrumpton (author)  angela.sims.181 month ago

Hello Angela!

It might be worthwhile to try lowering the CAP_THRESHOLD value (if you haven't already), since the cans will probably have a different capacitive characteristic. Try lowering it to the point were it triggers automatically and then raise it up a bit from there.

Hope that helps!

EjazJ1 month ago

Heyy, i am trying to make this project. but it shows up the same error as capacitance type not defined. i have properly installed the libraries (pitches.h) but still the error shows up. please help me as i am not that good at coding.

tylercrumpton (author)  EjazJ1 month ago

Hi there!

You shouldn't need to do anything special with the "pitches.h" file; you can just leave it in the same folder as the ".ino" file. You will, however, need to install the "CapactiveSensor" library for your Arduino installation. You can download that library here:

https://github.com/arduino-libraries/CapacitiveSen...

Here is a guide for installing libraries if you need help with that:

http://arduino.cc/en/Guide/Libraries

Hope that helps!

So I have the circuit hooked up and I did it on a bread board. However, when I use pin 2 as the send pin it does not work. if I unplug the wire in pin 2 it sends it perfectly, but continually plays iwthout touching. I must add, I am also using pop cans instead of pieces of aluminum. Any suggestions?

Angela

Hi there, Im looking to implement this design but in a few different ways...perhaps you can help point a noob in the right direction.

1. How can I send midi out to a device (in this case a midi controllable turntable to control the pitch of vinyl records) ....is there a specific arduino that has midi in/out?

Also im trying (rather ambitiously) to make a 3d printed case for it and instead of foil for the 'keys' can a solid aluminum pin/screw/button be used instead to prevent wear?

Hi! I know there are some Arduino devices like the Leonardo that can output MIDI over USB. You should be able to use a different material for the "keys", but it's hard to tell until you give it a shot! Try it with a variety of pins or screws until you find one that reacts well.

Hi! I have both libraries installed into my library and they are still coming up with the error message

"CapacitiveSensor Has not been declared" and

"CapacitiveSensor does not have a type"

can you help?

tylercrumpton (author)  angela.sims.182 months ago

Hi Angela!

Those errors are usually indicative of an improperly-installed or missing library. In the CapacitiveSensor-master.zip file, make sure that you only copy over the CapacitiveSensor and CapacitiveSensorDue folders over to your Arduino "libraries" folder.

If the libraries are properly installed, you should be able to select them in the "Sketch>>Import Library..." menu in the Arduino IDE. Do they show up there for you?

Hope this helps,

Tyler

DizzyIzzi3 months ago

Hi! This is my first instructables and my first Arduino Uno project. Can you tell me where to change the Cap Threshold value? I looked around your files and I just can't see it. Thanks!

tylercrumpton (author)  DizzyIzzi3 months ago

Hi there! The Cap Threshold value is near the top of the CapSensePiano.ino file and looks like:

#define CAP_THRESHOLD 150

Just change the 150 value to something else if you need to. Hope that helps!

SimonR13 months ago

Hello! Thanks very much for taking the time to put this together.

Is there anything stopping me from programming this onto an ATmega328?? As far as I can see the Uno isn't doing anything that the mega couldn't, but would there be memory issues?

Thanks,

Simon

tylercrumpton (author)  SimonR13 months ago
Hey Simon!

There shouldn't be any problem using an Uno; it's what we used! You'll only need something with more inputs like the Mega if you need more pads.
Ahh sorry youve misunderstood, i was asking if i could use the microprocessor that forms the heart of the uno (the atmega328) in isolation, because I'd like to make several of these cheaply with some conductive ink, that stand alone with a couple of 3V coin cells. I think what Ive realised though is that I can make a battery powered uno board for pennies myself and use a breakout board to program it.
Thanks though!
karti6 months ago

hi, i tried your project, but there seems to be a delay from when I press the foil to when the sound comes. can someone please help me out.

happy,happy7 months ago

hey i am using arduino Uno

after writing code

i have uploaded the libarary

error is coming

CapSensePiano:36: error: 'CapacitiveSensor' does not name a type
CapSensePiano.ino: In function 'void setup()':
CapSensePiano:43: error: 'keys' was not declared in this scope
CapSensePiano.ino: In function 'void loop()':
CapSensePiano:54: error: 'keys' was not declared in this scope

happy,happy7 months ago

hey i am using arduino Uno

after writing code

i have uploaded the libarary

error is coming

CapSensePiano:36: error: 'CapacitiveSensor' does not name a type
CapSensePiano.ino: In function 'void setup()':
CapSensePiano:43: error: 'keys' was not declared in this scope
CapSensePiano.ino: In function 'void loop()':
CapSensePiano:54: error: 'keys' was not declared in this scope

happy,happy7 months ago

hey i am using arduino Uno

after writing code

i have uploaded the libarary

error is coming

CapSensePiano:36: error: 'CapacitiveSensor' does not name a type
CapSensePiano.ino: In function 'void setup()':
CapSensePiano:43: error: 'keys' was not declared in this scope
CapSensePiano.ino: In function 'void loop()':
CapSensePiano:54: error: 'keys' was not declared in this scope

Where is the .zip file with the code?

Thanks

RobertCraven8 months ago

im using a arduino mega and it says

CapacitiveSensorSketch:12: error: 'CapacitiveSensor' does not name a type

CapacitiveSensorSketch:13: error: 'CapacitiveSensor' does not name a type

CapacitiveSensorSketch:14: error: 'CapacitiveSensor' does not name a type

CapacitiveSensorSketch.pde: In function 'void setup()':

CapacitiveSensorSketch:18: error: 'cs_4_2' was not declared in this scope

CapacitiveSensorSketch.pde: In function 'void loop()':

CapacitiveSensorSketch:25: error: 'cs_4_2' was not declared in this scope

CapacitiveSensorSketch:26: error: 'cs_4_6' was not declared in this scope

CapacitiveSensorSketch:27: error: 'cs_4_8' was not declared in this scope

RobertCraven8 months ago

hello,

i have a very simple and dumb problem.

it says:

"Attached below, uou will find a zip file that contains the Arduino code for the Capacitive-Touch Arduino Keyboard Piano."

...i cant find the zipfile :/

jordanguy12311 months ago
Can you please tell me how to hook this up to an external powers (meaning no laptop involved for portability purposes)
tylercrumpton (author)  jordanguy12310 months ago

You've got a few options available that should work!

1) Search eBay/Amazon for "9v arduino" and find a battery clip that lets you hook up a 9V battery to power the Arduino through the barrel jack connect on the board, or

2) Use a rechargeable USB battery pack (can also be found on eBay/Amazon) to power the Arduino over the USB port.

Note: I've never tried to power this particular project off of battery power, so it's possible that the grounding may be a little strange for the sensor pads. If you try it out, please let us know how it goes!

Thanks for the great instructions - my son and I built this and it worked great right away using the code from mrizkall below - until we tried anything other than USB power. It didn't work at all on batteries or a 9V wall wart, or even a USB cable connected to a USB charger.

The fix I found was to rig a 9V connector so the negative lead splits off and connects to a good earth ground - like a copper pipe - while still going to the Arduino as usual.

Not the most portable solution, but it works for the installation we have in mind.

Side note... we experimented with 1M, 2M, and 10M resistors. We wanted it to work on touch contact, and the 1M worked fine for that. We also used copper tape for pads, and were able to solder wires directly to them for a solid connection.

Update! My 7 year old son just discovered that the ground wire doesn't need to be attached to ground. If you hold the exposed end in one hand, you can play the piano with the other and it works.

tylercrumpton (author)  jordanguy12310 months ago

You've got a few options available that should work!

1) Search eBay/Amazon for "9v arduino" and find a battery clip that lets you hook up a 9V battery to power the Arduino through the barrel jack connect on the board, or

2) Use a rechargeable USB battery pack (can also be found on eBay/Amazon) to power the Arduino over the USB port.

Note: I've never tried to power this particular project off of battery power, so it's possible that the grounding may be a little strange for the sensor pads. If you try it out, please let us know how it goes!

mrizkalla11 months ago

Thanks. Very cool. Here is how I changed the loop() function to make it so the sound stops playing when the finger has been lifted off the keys.

void loop() {

unsigned int keysPlaying = 0;

// Loop through each key:

for (int i = 0; i < NUM_OF_KEYS; ++i) {

// If the capacitance reading is greater than the threshold, play a note:

int c = keys[i].capacitiveSensor(NUM_OF_SAMPLES);

if(c > CAP_THRESHOLD) {

tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed

keysPlaying++;

}

}

if (keysPlaying == 0) {

noTone(BUZZER_PIN);

}

}

1-40 of 53Next »