// This is a very simple code. I have avoided a complex code because this code works quite well// // Author - mrfrozenpeak int freq1 = 3000; // frequency of keys , you can change it as per your need int freq2 = 2500; int freq3 = 2000; int freq4 = 1800; int freq5 = 1500; int freq6 = 1200; int freq7 = 1000; int freq8 = 600; int freq9 = 400; int freq10 = 200; #define buzzer_speaker 2 // speaker output # define string1 4 # define string2 5 // keys of piano # define string3 6 # define string4 7 # define string5 8 # define string6 9 # define string7 10 # define string8 11 # define string9 12 # define string10 13 //int tone_mode[] = [[]]; void setup() { pinMode(string1,INPUT); pinMode(string2,INPUT); pinMode(string3,INPUT); // setting up input pins pinMode(string4,INPUT); pinMode(string5,INPUT); pinMode(string6,INPUT); pinMode(string7,INPUT); pinMode(string8,INPUT); pinMode(string9,INPUT); pinMode(string10,INPUT); pinMode(buzzer_speaker,INPUT); Serial.begin(9600); // serial monitor in case you want to check sensor inputs // put your setup code here, to run once: } void loop() { int a1 = digitalRead(string1); // take readings from all input pins int a2 = digitalRead(string2); int a3 = digitalRead(string3); int a4 = digitalRead(string4); int a5 = digitalRead(string5); int a6 = digitalRead(string6); int a7 = digitalRead(string7); int a8 = digitalRead(string8); int a9 = digitalRead(string9); int a10 = digitalRead(string10); if(a1==0){ // simple if statements to give output to buzzer if input is low tone(buzzer_speaker,freq1); // function in this format: tone(output pin, frequency you want to output) } if(a2==0){ tone(buzzer_speaker,freq2); } if(a3==0){ tone(buzzer_speaker,freq3); } if(a4==0){ tone(buzzer_speaker,freq4); } if(a5==0){ tone(buzzer_speaker,freq5); } if(a6==0){ tone(buzzer_speaker,freq6); } if(a7==0){ tone(buzzer_speaker,freq7); } if(a8==0){ tone(buzzer_speaker,freq8); } if(a9==0){ tone(buzzer_speaker,freq9); } if(a10==0){ tone(buzzer_speaker,freq10); } if(a1==1 & a2==1 & a3==1 & a4==1 & a5==1 & a6==1 & a7==1 & a8==1 & a9==1 & a10==1){ // if all inputs high, stop the buzzer noTone(buzzer_speaker); // notone is funtion used to stop buzzer/speaker } // Thanks }