Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Speaker, Mini
Breadboard (generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Software & Tools
Arduino IDE
Project description
Code
Code for tunes with hand gesture
arduino
Paste this code in your Arduino IDE.. Try tweaking the values as mentioned above and have fun!
1#define echoPin 6 2#define trigPin 5 3long duration; // variable for the duration of sound wave travel 4int distance; // variable for the distance measurement 5int tones; 6int tim=200;// duration for which one sound pulse will last 7int buzzerPin = 8; 8int space =500; 9 10void setup() { 11 pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT 12 pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT 13 pinMode(buzzerPin, OUTPUT); 14 } 15 16void loop() { 17 18 //Finding distance of obstacle using ultrasonic sensor 19 digitalWrite(trigPin, LOW); 20 delayMicroseconds(2); 21 digitalWrite(trigPin, HIGH); 22 delayMicroseconds(10); 23 digitalWrite(trigPin, LOW); 24 25 duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds 26 distance = duration * 0.034 / 2; // Distance = time*speed/2 27 28 //Emitting sound as per the distance 29 30 tones =20+distance*5; //calculating the frequency that has to be emitted 31 32 tone(buzzerPin, tones, tim); //emits sound at the specified frequency and for the specified duration 33 34 delay (space); //delay between each beat 35 36} 37
Downloadable files
Here is the fritzing file
Make these connection, upload the code and you are ready to go!
Here is the fritzing file
Schematic representation
Schematic representation

Pictorial representation
Follow these connections carefully
Pictorial representation

Here is the fritzing file
Make these connection, upload the code and you are ready to go!
Here is the fritzing file
Schematic representation
Schematic representation

Pictorial representation
Follow these connections carefully
Pictorial representation

Comments
Only logged in users can leave comments