Pages: [1]   Go Down
Author Topic: Capacitive Touch Piano  (Read 1645 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I posted this in the project guidance forum, but I wanted to post it here to as this sub-forum is more specific to my issue. I hope that is ok.

I am in need of some help. I am trying to build a capacitive touch piano, like the one: http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/?ALLSTEPS.

I have been trying for hours to get this thing to work, but I cannot for the life of me get it to. I have followed the instructions to a tee, but I cannot get the capactive touch part of this project to work. I have a 10M ohm resistor connected to pin 2 and then in parallel with a wire connected to pin 4 (could be any between 3 and 11). I connected the other ends to a a piece of aluminum foil to act as the "key," however it just does not work correctly. Whenever I touch the foil, nothing happens. The speaker does work sometime though, but it is extremely inconsistent on when it does. I feel like there is an issue with the sensitivity somewhere.

Here is the code I am using:
Code:
/*
  Capacitive-Touch Arduino Keyboard Piano
 
  Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"
*/

#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   100  // 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
    }
  }
}

I have tried modifying CAP_THRESHOLD as well as NUM_OF_SAMPLES, but that did not seem to change anything.
Also, here is a picture of what I have: http://imgur.com/gmVeh7g

Let me know if you need more information. I am getting extremely frustrated with this right now.
Thanks for the help!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27113
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm deleting the duplicate thread then.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I posted this in the project guidance forum, but I wanted to post it here to as this sub-forum is more specific to my issue. I hope that is ok.

I am in need of some help. I am trying to build a capacitive touch piano, like the one: http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/?ALLSTEPS.

I have been trying for hours to get this thing to work, but I cannot for the life of me get it to. I have followed the instructions to a tee, but I cannot get the capactive touch part of this project to work. I have a 10M ohm resistor connected to pin 2 and then in parallel with a wire connected to pin 4 (could be any between 3 and 11). I connected the other ends to a a piece of aluminum foil to act as the "key," however it just does not work correctly. Whenever I touch the foil, nothing happens. The speaker does work sometime though, but it is extremely inconsistent on when it does. I feel like there is an issue with the sensitivity somewhere.

Here is the code I am using:
Code:
/*
  Capacitive-Touch Arduino Keyboard Piano
 
  Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"
*/

#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   100  // 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
    }
  }
}

I have tried modifying CAP_THRESHOLD as well as NUM_OF_SAMPLES, but that did not seem to change anything.
Also, here is a picture of what I have: http://imgur.com/gmVeh7g

Let me know if you need more information. I am getting extremely frustrated with this right now.
Thanks for the help!

try narrowing the problem down. Have you tried to see if you are even triggering the keys or if its an issue with the speaker? I would try some Serial printing to see if the keys are being triggered:

Code:
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
      Serial.print("key "); Serial.print(i); Serial.println(" has been triggered");
    }
  }
}

if you do not see anything happen try lowering:

Code:
#define CAP_THRESHOLD   100

by 10 until you get a trigger. Also monitoring what:

Code:
keys[i].capacitiveSensor(NUM_OF_SAMPLES)

is at is a good idea too, so you can see what the value actually is. Capacitance will definitely be different than his, since cutting the tinfoil slightly smaller will reduce the resistance.
« Last Edit: December 02, 2013, 03:51:39 pm by hilukasz » Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 502
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cant see any sensing plates in your diagram.
The capsense library relies on a fairly large area of sensing plate to work properly.
If the plate is too small, the capacitance change becomes too small to detect.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I cant see any sensing plates in your diagram.
The capsense library relies on a fairly large area of sensing plate to work properly.
If the plate is too small, the capacitance change becomes too small to detect.


actually that isn't true. I've done it with just wire and resistors. so that should work. mostly depends on the resistor value, you can increase it and wires alone will work, but even smaller value ones will work after a certain amount of pressure.
« Last Edit: December 04, 2013, 01:25:26 pm by hilukasz » Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

on this same code i have the 'CapacitiveSensor' does not name type error pleas help smiley-sad


on this line

// Defines the pins that the keys are connected to:
CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(smiley-cool, CS(9), CS(10)};

and if i put #define CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(smiley-cool, CS(9), CS(10)};
it gets me to the problem of  keys was not declare in this scope  on the first void setup
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

on this same code i have the 'CapacitiveSensor' does not name type error pleas help smiley-sad


on this line

// Defines the pins that the keys are connected to:
CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(smiley-cool, CS(9), CS(10)};

and if i put #define CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(smiley-cool, CS(9), CS(10)};
it gets me to the problem of  keys was not declare in this scope  on the first void setup


make sure you download the library and install it, as well as add the header file at the top of your code:

Code:
#include <CapacitiveSensor.h>
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Pages: [1]   Go Up
Jump to: