Robotics EveryDay
Published © LGPL

DIY Piano | Make Piano with Touch based keys | Touch Sensor

This is an Arduino-based Piano. It has capacitive touch sensors instead of keys. No need to press it just touch it and play tunes on speaker

IntermediateFull instructions provided757
DIY Piano | Make Piano with Touch based keys | Touch Sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Test Cable Assembly, Alligator Terminated Test Lead Set
Test Cable Assembly, Alligator Terminated Test Lead Set
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Scissor, Electrician
Scissor, Electrician
Wire Cutter / Stripper, 5.25 " Overall Length
Wire Cutter / Stripper, 5.25 " Overall Length
Tape, Clear
Tape, Clear
Conductive Tape, Copper Foil
Conductive Tape, Copper Foil

Story

Read more

Schematics

Arduino Interfacing with touch sensor and speaker

Arduino Interfacing with touch sensor, speaker, transistor and resistors

Code

Arduino Piano with tones, Interfacing with touch sensor and speaker

Arduino
Arduino Interfacing with touch sensor and speaker to make a piano with tones
//Piano With Touch Sensor Sketch

#include <CapacitiveSensor.h>

const int sensitivity  = 1000; // default 30

//Sa 240 Hz, Re 270 Hz, Ga 300 Hz, Ma 320 Hz, Pa 360 Hz, Dha 400 Hz, and Ni 450 Hz, Sa 480 Hz
int sa = 240, re = 270, ga = 300, ma = 320, pa = 360, dha = 400, ni = 450;
int freq[] = {240,270,300,320,360,400,450,480};
int dly = 1000;

CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5);
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);
CapacitiveSensor   cs_4_7 = CapacitiveSensor(4,7);
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        
CapacitiveSensor   cs_4_9 = CapacitiveSensor(4,9);        
CapacitiveSensor   cs_4_10 = CapacitiveSensor(4,10);        
CapacitiveSensor   cs_4_11 = CapacitiveSensor(4,11);

void setup()                    
{
   pinMode(A5, OUTPUT);
   cs_4_8.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_4_9.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_4_10.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
//   Serial.begin(9600);
}

void human(){
  
  long total1 =  cs_4_5.capacitiveSensor(sensitivity);
  long total2 =  cs_4_6.capacitiveSensor(sensitivity);
  long total3 =  cs_4_7.capacitiveSensor(sensitivity);
  long total4 =  cs_4_8.capacitiveSensor(sensitivity);
  long total5 =  cs_4_9.capacitiveSensor(sensitivity);
  long total6 =  cs_4_10.capacitiveSensor(sensitivity);
  long total7 =  cs_4_11.capacitiveSensor(sensitivity);
  
  int thresh = 25;
  
  if(total1>thresh){
    tone(A5,freq[0]);
  }else if(total2>thresh){
    tone(A5,freq[1]);
  }else if(total3>thresh){
    tone(A5,freq[2]);
  }else if(total4>thresh){
    tone(A5,freq[3]);
  }else if(total5>thresh){
    tone(A5,freq[4]);
  }else if(total6>thresh){
    tone(A5,freq[5]);
  }else if(total7>thresh){
    tone(A5,freq[6]);
  }else{
    noTone(A5);
  }
}

void robotic_hbd(){
  int freq[] = {
    sa,sa,re,sa,ma,ga,
    sa,sa,re,sa,pa,ma,
    sa,sa,dha,pa,ma,ga,re,
    ni,ni,dha,ma,pa,ma,
    sa,re,sa,ma,ga,
    sa,re,sa,pa,ma,
    sa,dha,ma,ga,re,re,
    ni,ni,dha,ma,pa,ma
  };
  int i=0,l=sizeof(freq)/sizeof(int);
  
  for(i=0;i<l;i++){
    tone(A5,freq[i]);
    delay(150);
    }
}

void loop(){
  human();
//  robotic_hbd();
}

Credits

Robotics EveryDay

Robotics EveryDay

0 projects • 9 followers

Comments