Components and supplies
1
Buzzer
1
Male/Male Jumper Wires
1
Arduino UNO
1
Ultrasonic Sensor - HC-SR04 (Generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Theremin.ino
c_cpp
1//ncelikle Pinleri tanmlyoruz 2//We define the necessary pins 3#define Buzz 10 4#define pingPin 9 5#define echoPin 8 6 7//Notalarn saysal deerlerini bir listeye kaydediyoruz. 8//sterseniz tek tek deiken de atayabilirsiniz: const int do= 131; gibi 9//Assing a list for notes 10//If you want you can do it seperately so you can see the note names. For example const int C3= 131; 11 12int notes[]={131,147,165,175,196,220,247,262,294}; 13 14 15 16void setup(){ 17 //Buzzere elektrik vermesi iin pinMode komutunu kullanyoruz 18 //i am using pinMode function to power the buzzer 19 pinMode(Buzz, OUTPUT); 20 21 //Seri portu balatmak iin bu kodu yazyoruz 22 //Seri portu kullanmak kiinin kendi tercihidir 23 //ben mesafe sensrnn deerlerini optimize etmek iin kullandm 24 //Start the serial port btw it is a choice. I used this for the optimization 25 Serial.begin(9600); 26} 27 28void loop(){ 29 //Burada duration ve distance diye iki deiken belirliyoruz. 30 //Bu deikenler sayesinde mesafe lmn yapp o lm bir deikene atayacaz. 31 //We define two variables here to record our measurments. 32 long duration, distance; 33 34 //pingPin aslnda bizim Trig pinimiz. Ondan bir ses dalgas yollayacaz o yzden OUTPUT yazyoruz 35 //pingPin is our Trig pin. We'll send a soundwave so we write OUTPUT 36 pinMode(pingPin, OUTPUT); 37 38 //loopta srekli okuyacamz iin aralkl olarak sesleri yollamamz lazm. 39 //o yzden ilk bata elektrik vermiyoruz 40 //We use a loop and We will read the sounds intermittently. 41 //So we don't power the pin firstly 42 digitalWrite(pingPin, LOW); 43 44 //2 mikro saniyelik bir ara veriyoruz 45 //give a 2 microseconds delay 46 delayMicroseconds(2); 47 48 //ve elektrii veriyoruz 49 //and power up 50 digitalWrite(pingPin, HIGH); 51 52 //Verdikten sonra 10 mikro saniyelik bir ara veriyoruz 53 //after the power up, give a 10 microseconds delay 54 delayMicroseconds(10); 55 56 //ve Trig pininin elektriini kesiyoruz 57 // and power down the Trig pin 58 digitalWrite(pingPin, LOW); 59 60 //echo pinimiz bizim sesleri yakaladmz yer deer okuma ilemi yapacamz iin INPUT yazyoruz. 61 // we'll catch the sounds on th echo Pin. so we write INPUT here 62 pinMode(echoPin, INPUT); 63 //duration deikenine deer okunana kadar geen sreyi kaydediyoruz 64 //use the duration to record the time 65 duration = pulseIn(echoPin, HIGH); 66 67 //distance deikeni ile de mesafeyi alyoruz buradaki matematik ilemi santimetre iinidir. 68 //use distance to record the distance of the object from our sensor. calculation is for cm 69 distance = duration / 29 / 2; 70 71 //Mesafe lmlerini kontrol etmek iin Seri portu kullandm sylemitim. 72 //seri porta mesafeyi yazdryoruz. Eer byle bir isteiniz yoksa kullanmayabilrsiniz. 73 //I said before, I used the serial port for the optimization. 74 //we print the serial port the distance. 75 Serial.println(distance); 76 77 //Bu blokta 5 santimlik mesafelere gre hangi sesleri kraca yazyor. 78 //Notalar liste eklinde yazmak, buraya yazarken ilerimizi kolaylatrd. 79 //this block contains if confdtions to sound which note in which distances. I cut 5 cm pieces. 80 if (distance >= 5 && distance <10){tone(Buzz,notes[0]);} //tone fonksiyonu 3 parametre alr (pin numaras, frekans deeri, alma sresi) 81 if (distance >= 10 && distance <15){tone(Buzz,notes[1]);}// eer alma sresi koymazsanz hi durmadan alar 82 if (distance >= 15 && distance <20){tone(Buzz,notes[2]);} 83 if (distance >= 20&& distance <25){tone(Buzz,notes[3]);} 84 if (distance >= 25 && distance <30){tone(Buzz,notes[4]);} 85 if (distance >= 30 && distance <35){tone(Buzz,notes[5]);} 86 if (distance >= 35 && distance <40){tone(Buzz,notes[6]);} 87 if (distance >= 40 && distance <45){tone(Buzz,notes[7]);} 88 //Delay fonksiyonu lmlerin arasn amamz ve daha net sesler ve notalar almamz salyor. 89 //sterseniz delay fonksiyonunun deeri ile oynayarak kendiniz de sonular grebilirsiniz 90 //Delay funtion is here to make more clear sounds. If you want you ccan play with it and you can he results. 91 delay(500); 92 //noTone fonksiyonu eer stteki olaylar gereklemezse buzzerin susmasn sylyor. 93 //noTone is here to close the buzzer if there is no object. 94 noTone(Buzz); 95} 96
Theremin.ino
c_cpp
1//ncelikle Pinleri tanmlyoruz 2//We define the necessary pins 3#define Buzz 10 4#define pingPin 9 5#define echoPin 8 6 7//Notalarn saysal deerlerini bir listeye kaydediyoruz. 8//sterseniz tek tek deiken de atayabilirsiniz: const int do= 131; gibi 9//Assing a list for notes 10//If you want you can do it seperately so you can see the note names. For example const int C3= 131; 11 12int notes[]={131,147,165,175,196,220,247,262,294}; 13 14 15 16void setup(){ 17 //Buzzere elektrik vermesi iin pinMode komutunu kullanyoruz 18 //i am using pinMode function to power the buzzer 19 pinMode(Buzz, OUTPUT); 20 21 //Seri portu balatmak iin bu kodu yazyoruz 22 //Seri portu kullanmak kiinin kendi tercihidir 23 //ben mesafe sensrnn deerlerini optimize etmek iin kullandm 24 //Start the serial port btw it is a choice. I used this for the optimization 25 Serial.begin(9600); 26} 27 28void loop(){ 29 //Burada duration ve distance diye iki deiken belirliyoruz. 30 //Bu deikenler sayesinde mesafe lmn yapp o lm bir deikene atayacaz. 31 //We define two variables here to record our measurments. 32 long duration, distance; 33 34 //pingPin aslnda bizim Trig pinimiz. Ondan bir ses dalgas yollayacaz o yzden OUTPUT yazyoruz 35 //pingPin is our Trig pin. We'll send a soundwave so we write OUTPUT 36 pinMode(pingPin, OUTPUT); 37 38 //loopta srekli okuyacamz iin aralkl olarak sesleri yollamamz lazm. 39 //o yzden ilk bata elektrik vermiyoruz 40 //We use a loop and We will read the sounds intermittently. 41 //So we don't power the pin firstly 42 digitalWrite(pingPin, LOW); 43 44 //2 mikro saniyelik bir ara veriyoruz 45 //give a 2 microseconds delay 46 delayMicroseconds(2); 47 48 //ve elektrii veriyoruz 49 //and power up 50 digitalWrite(pingPin, HIGH); 51 52 //Verdikten sonra 10 mikro saniyelik bir ara veriyoruz 53 //after the power up, give a 10 microseconds delay 54 delayMicroseconds(10); 55 56 //ve Trig pininin elektriini kesiyoruz 57 // and power down the Trig pin 58 digitalWrite(pingPin, LOW); 59 60 //echo pinimiz bizim sesleri yakaladmz yer deer okuma ilemi yapacamz iin INPUT yazyoruz. 61 // we'll catch the sounds on th echo Pin. so we write INPUT here 62 pinMode(echoPin, INPUT); 63 //duration deikenine deer okunana kadar geen sreyi kaydediyoruz 64 //use the duration to record the time 65 duration = pulseIn(echoPin, HIGH); 66 67 //distance deikeni ile de mesafeyi alyoruz buradaki matematik ilemi santimetre iinidir. 68 //use distance to record the distance of the object from our sensor. calculation is for cm 69 distance = duration / 29 / 2; 70 71 //Mesafe lmlerini kontrol etmek iin Seri portu kullandm sylemitim. 72 //seri porta mesafeyi yazdryoruz. Eer byle bir isteiniz yoksa kullanmayabilrsiniz. 73 //I said before, I used the serial port for the optimization. 74 //we print the serial port the distance. 75 Serial.println(distance); 76 77 //Bu blokta 5 santimlik mesafelere gre hangi sesleri kraca yazyor. 78 //Notalar liste eklinde yazmak, buraya yazarken ilerimizi kolaylatrd. 79 //this block contains if confdtions to sound which note in which distances. I cut 5 cm pieces. 80 if (distance >= 5 && distance <10){tone(Buzz,notes[0]);} //tone fonksiyonu 3 parametre alr (pin numaras, frekans deeri, alma sresi) 81 if (distance >= 10 && distance <15){tone(Buzz,notes[1]);}// eer alma sresi koymazsanz hi durmadan alar 82 if (distance >= 15 && distance <20){tone(Buzz,notes[2]);} 83 if (distance >= 20&& distance <25){tone(Buzz,notes[3]);} 84 if (distance >= 25 && distance <30){tone(Buzz,notes[4]);} 85 if (distance >= 30 && distance <35){tone(Buzz,notes[5]);} 86 if (distance >= 35 && distance <40){tone(Buzz,notes[6]);} 87 if (distance >= 40 && distance <45){tone(Buzz,notes[7]);} 88 //Delay fonksiyonu lmlerin arasn amamz ve daha net sesler ve notalar almamz salyor. 89 //sterseniz delay fonksiyonunun deeri ile oynayarak kendiniz de sonular grebilirsiniz 90 //Delay funtion is here to make more clear sounds. If you want you ccan play with it and you can he results. 91 delay(500); 92 //noTone fonksiyonu eer stteki olaylar gereklemezse buzzerin susmasn sylyor. 93 //noTone is here to close the buzzer if there is no object. 94 noTone(Buzz); 95} 96
Downloadable files
diagram
theremin diagram
diagram
Comments
Only logged in users can leave comments