Automated Piano

by yash yash in Circuits > Audio

1327 Views, 4 Favorites, 0 Comments

Automated Piano

piano.jpeg

I wanted to make a piano that can play automatically by listening to my music instantaneously.So I gave it a try with arduino uno i had lying around.It could be much better with arduino zero using simple frequency meter library i i didn't have it at the moment and i continued with uno.

Theory

The piano is played by matching the frequency of the singer to the piano.so we need to sample the frequency of the singer and playback it in real time.I use a voltage divider out of a trimpot since audio is ac and arduino can't handle negative voltages therefore used the voltage provided by the voltage divider as reference and set it up at 2.5v. The input is provided at A0 pin of the arduino.I then programed the arduino to check when the voltage is at reference level which i measured and named it initial and then measured thethe time interval between successive reference voltage and then calculated the frequency.The del variable is used to store the instantaneous amplitude of the audio signal to eliminate the noise whichhas amplitude less than 15 adc value or 0.0733 volts. A limit is put on the frequency so that extreme values don't interrupt the song.

Material Required

3.5mm.jpeg
breadboard.jpeg
buzzer.jpeg
trimpot.jpeg
uno.jpeg

1)Arduino Uno or equivalent

2)Passive piezo electric buzzer or a speaker with amplifier circuit

3)High resistance trimpot(make sure that current flowing through it at 5v should be small in few millamps)

4)jumper wires

5)breadboard

6)3.5mm audio jack or a mic with amplifier circuit(I used my mobile as an amplifier as i found myself too lazy to build one)

7)Android Phone(To play sound)

8)arduino cable(To program it)

Connections

IMG_20181027_203925.jpg
IMG_20181027_203930.jpg

1)Mount trimpot on the bread board and supply it ground and +5v from arduino using jumper wires.

2)Connect ground of the 3.5mm jack to the third pin of trimpot to work as voltage divider configuration and channel to A0 pin of arduino.

3)Connect ground of buzzer to arduino's ground and signal to pin 13 of arduino.

Arduino Code

casio.png

Here is the complete code

I have commented out some statements of serial print used for testing

-----------------------------------------------------------------------------------

uint64_t curtime=0,ltime=0;
uint32_t freq=0; uint16_t initial,val,del=0; bool last,curr; void setup() { // put your setup code here, to run once: delay(1000); /*Serial.begin(115200); delay(1000); Serial.println("system started");*/ initial = analogRead(A0); if(analogRead(A0)

void loop() { // put your main code here, to run repeatedly: val=analogRead(A0); if(val>=initial)curr=1; else curr=0; del=(int)val-(int)initial; if(last==0 && curr==1){ curtime=micros(); freq=1000000/(2*(curtime-ltime)); /*Serial.print(freq,DEC); Serial.print(" down "); Serial.println(del);*/ if(freq>50&&freq<2000 && abs(del)>15)tone(13,freq,500); delay(100); ltime=micros(); last=1; }

Downloads

Power It!!!

Automated Piano

Connect your your phone to play some music and if you want to sing then you can use all tools app that can be downloaded on play store.Here is the link

https://play.google.com/store/apps/details?id=com.pradhyu.alltoolseveryutility&hl=en

After downloading, open mike option and sing!

Here is how it works!