mindofrobotics
Published © GPL3+

Very basic level Theremin

It is a theremin and it has just pitch feature.

BeginnerWork in progress821
Very basic level Theremin

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
Male/Male Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

diagram

theremin diagram

Code

Theremin.ino

C/C++
//ncelikle Pinleri tanmlyoruz
//We define the necessary pins 
#define Buzz 10         
#define pingPin 9
#define echoPin 8

//Notalarn saysal deerlerini bir listeye kaydediyoruz.
//sterseniz tek tek deiken de atayabilirsiniz: const int do= 131; gibi
//Assing a list for notes
//If you want you can do it seperately so you can see the note names. For example const int C3= 131;

int notes[]={131,147,165,175,196,220,247,262,294};



void setup(){
  //Buzzere elektrik vermesi iin pinMode komutunu kullanyoruz
  //i am using pinMode function to power the buzzer
  pinMode(Buzz, OUTPUT); 

  //Seri portu balatmak iin bu kodu yazyoruz
  //Seri portu kullanmak kiinin kendi tercihidir 
  //ben mesafe sensrnn deerlerini optimize etmek iin kullandm
  //Start the serial port btw it is a choice. I used this for the optimization
  Serial.begin(9600);
}

void loop(){
  //Burada duration ve distance diye iki deiken belirliyoruz.
  //Bu deikenler sayesinde mesafe lmn yapp o lm bir deikene atayacaz.
  //We define two variables here to record our measurments.
  long duration, distance;

   //pingPin aslnda bizim Trig pinimiz. Ondan bir ses dalgas yollayacaz o yzden OUTPUT yazyoruz
   //pingPin is our Trig pin. We'll send a soundwave so we write OUTPUT
   pinMode(pingPin, OUTPUT);

   //loopta srekli okuyacamz iin aralkl olarak sesleri yollamamz lazm.
   //o yzden ilk bata elektrik vermiyoruz
   //We use a loop and We will read the sounds intermittently.
   //So we don't power the pin firstly 
   digitalWrite(pingPin, LOW);
   
   //2 mikro saniyelik bir ara veriyoruz
   //give a 2 microseconds delay
   delayMicroseconds(2);

   //ve elektrii veriyoruz
   //and power up
   digitalWrite(pingPin, HIGH);
   
   //Verdikten sonra 10 mikro saniyelik bir ara veriyoruz
   //after the power up, give a 10 microseconds delay
   delayMicroseconds(10);
   
   //ve Trig pininin elektriini kesiyoruz
   // and power down the Trig pin
   digitalWrite(pingPin, LOW);
   
   //echo pinimiz bizim sesleri yakaladmz yer deer okuma ilemi yapacamz iin INPUT yazyoruz.
   // we'll catch the sounds on th echo Pin. so we write INPUT here
   pinMode(echoPin, INPUT);
   //duration deikenine deer okunana kadar geen sreyi kaydediyoruz
   //use the duration to record the time
   duration = pulseIn(echoPin, HIGH);
   
   //distance deikeni ile de mesafeyi alyoruz buradaki matematik ilemi santimetre iinidir.  
   //use distance to record the distance of the object from our sensor. calculation is for cm 
   distance = duration / 29 / 2;

  //Mesafe lmlerini kontrol etmek iin Seri portu kullandm sylemitim.
  //seri porta mesafeyi yazdryoruz. Eer byle bir isteiniz yoksa kullanmayabilrsiniz.
  //I said before, I used the serial port for the optimization.
  //we print the serial port the distance.
  Serial.println(distance);

  //Bu blokta 5 santimlik mesafelere gre hangi sesleri kraca yazyor.
  //Notalar liste eklinde yazmak, buraya yazarken ilerimizi kolaylatrd.
  //this block contains if confdtions to sound which note in which distances. I cut 5 cm pieces. 
  if (distance >= 5 && distance <10){tone(Buzz,notes[0]);} //tone fonksiyonu 3 parametre alr (pin numaras, frekans deeri, alma sresi)
  if (distance >= 10 && distance <15){tone(Buzz,notes[1]);}// eer alma sresi koymazsanz hi durmadan alar
  if (distance >= 15 && distance <20){tone(Buzz,notes[2]);}
  if (distance >= 20&& distance <25){tone(Buzz,notes[3]);}
  if (distance >= 25 && distance <30){tone(Buzz,notes[4]);}
  if (distance >= 30 && distance <35){tone(Buzz,notes[5]);}
  if (distance >= 35 && distance <40){tone(Buzz,notes[6]);}
  if (distance >= 40 && distance <45){tone(Buzz,notes[7]);}
  //Delay fonksiyonu lmlerin arasn amamz ve daha net sesler ve notalar almamz salyor. 
  //sterseniz delay fonksiyonunun deeri ile oynayarak kendiniz de sonular grebilirsiniz
  //Delay funtion is here to make more clear sounds. If you want you ccan play with it and you can he results.
  delay(500);
  //noTone fonksiyonu eer stteki olaylar gereklemezse buzzerin susmasn sylyor.
  //noTone is here to close the buzzer if there is no object.
  noTone(Buzz);
}

Credits

mindofrobotics
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.