Introduction:
This blog describes about how you can control led upon the movement of hand.
Requirements:
I) Arduino Nano & Cable
II) Ultrasonic Senor
III) Led
IV) Resistors
V) Breadboard
VI) Jumper Wires
Description:
In this project, we are going to control 5 led by the help of ultrasonic sensor.
So basically, one ultrasonic sensor measures distance through its ultrasonic wave. We will take our hand close to the sensor by which the 5 led will turn on serially, again we will take our hand away from the sensor the led will turn of serially.
So, lets see how can we interface all together.
Circuit diagram:
In this above diagram, we connected the ultrasonic sensor, 5 led and resistors with Arduino Nano with some M-M, M-F jumper wires.
Here we connected ultrasonic sensor’s trigger pin to D9 pin and echo pin to D8 pin of Nano.
Then we connected 5 led through 220 Ohm resistors to D7,D6,D5,D4,D3 pin of Nano.
Trig Pin |
D9 |
Echo pin |
D8 |
Led1 |
D7 |
Led2 |
D6 |
Led3 |
D5 |
Led4 |
D4 |
Led5 |
D3 |
Code:
////////////////////////////////////////////////////define part
#define trigPin 9 //trig pin connected to D9
#define echoPin 8 // echo pin connected to D8
#define led1 7 // connected to D7
#define led2 6 // connected to D6
#define led3 5 // connected to D5
#define led4 4 // connected to D4
#define led5 3 // connected to D3
long duration;
int distance;
void setup()
{
Serial.begin(9600); //for serial monitor
////////////////////////////////////////////////declartion part
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
}
void loop()
{
digitalWrite(trigPin,LOW); //initially off
delayMicroseconds(2);
digitalWrite(trigPin,HIGH); //send wave
delayMicroseconds(10);
digitalWrite(trigPin,LOW); //receives wave
duration=pulseIn(echoPin,HIGH);
distance=(duration*0.034/2); // formula for distance
Serial.print("Distance : ");
Serial.print(distance);
Serial.println(" cm ");
delay(100);
///////////////////////////////////////////////////////////condition part
if (distance <= 28)
{
digitalWrite(led1, HIGH);
}
else
{
digitalWrite(led1,LOW);
}
if (distance < 25)
{
digitalWrite(led2, HIGH);
}
else
{
digitalWrite(led2, LOW);
}
if (distance < 20)
{
digitalWrite(led3, HIGH);
}
else
{
digitalWrite(led3, LOW);
}
if (distance < 15)
{
digitalWrite(led4, HIGH);
}
else
{
digitalWrite(led4,LOW);
}
if (distance < 7)
{
digitalWrite(led5, HIGH);
}
else
{
digitalWrite(led5,LOW);
}
}
For more details go for the video.
Comments
Leave a Reply