Jeremy Sow
Published

Touch Sensing Paper Piano

A paper piano that relies on human touch for audio output using transistors.

BeginnerFull instructions provided4,668
Touch Sensing Paper Piano

Things used in this project

Hardware components

2N3904 TRANSISTOR (NPN)
×1
Male/Male Jumper Wires
×1
Buzzer
Buzzer
×1
5 mm LED: Green
5 mm LED: Green
×1
Arduino Mega 2560
Arduino Mega 2560
×1

Story

Read more

Schematics

circuit diagram ( for ONE PIANO KEY).

this is the circuit diagram for the piano. From the cover picture, it can be seen that is is complicated, hence, this circuit if for ONE PIANO KEY ONLY. The collector is connected to two things, which is a 5 volt rail, and a wire for the person's hand to hold to complete the circuit. The base is connected to the piano key, and the emitter is connected to the LED, which leads to a analog pi to read the change in voltage, and also to ground.

As for the buzzer, it is connected to a digital pin for its live wire so that it will only output audio when there is a change in voltage which is picked up by the analog pin, and ground obviously to ground.

It is highly recommended to create a three rails to simplify the circuit for all keys. These rails consists of a live rail for the 5v from the arduino, a ground rail as well as a rail for the hand wire.

Code

piano code.

Arduino
int pin[7] = {A0,A1,A2,A8,A9,A10,A11}; // pin that reads voltage
int x;int y;int z;
 #define speaker 3                     // speaker output pin
int volts[10] = {analogRead (pin[x])};  //stores 10 readings of voltage for ONE pin
                //number of samples for the average mean vaule is 10
int sum;int sum1;int average;       // aVERAGE VARIABLES
int store [7];                    //stores AVERAGE reading of voltages of ALL pins

void setup() {
  
for (x = 0;x<=6; x++){
pinMode (pin[x], INPUT);
pinMode(speaker,OUTPUT);

Serial.begin (115200);}}                     

void loop() {
const int samples = 10;  
                     
    for ( x = 0; x <= 6 ; x++){   
      for ( y = 0;y<= 9 ; y++){               
       analogRead (pin [x]);                    //read voltage at each pin
        volts [y] = analogRead (pin [x]);          // store voltage of each pin in the array volts(up to 10 values as the array can only store 10 values)
        sum = volts[y];                    // sum of all the votlage (10 values)
        sum1 = sum += analogRead (pin [x]);  //add the previous analog reading to the current
        average = sum1/samples;
         store [x] = average; 
          Serial.println ("");
          Serial.println (store [5]);}}


const int EV =97;                     //value obtained through testing and observing how the voltage changes during serial.
   
  if ( (store [0]) > EV){   // if average voltage for the first pin value stored in the array (pin A0) is larger than 97
tone (speaker,195.9977);}   // tone(pin,frequency) to play

  
   else if ((store [1]) > EV ){
    tone (speaker,220.0000);}
    

     else if(store [2] > EV){                                                               
     tone(speaker,246.9417);}                                     
                                    
        
  else if (store [3] > EV ){                                            
     tone ( speaker,261.6256);}
     
      
       else if (store [4] > EV){
        tone (speaker,293.6648);}
         
            
         else if (store [5] > EV){
           tone(speaker,329.6276);}
             
                
                else if (store [6] > EV){
                  tone(speaker,523.2511);}

                  else {noTone(speaker);}} // prevents speaker from playing continuously.

Credits

Jeremy Sow
2 projects • 1 follower
mechical engineering student.
Contact

Comments

Please log in or sign up to comment.