iotproject
iotproject
Components
1. Arduino Uno
2. Ultrasonic sensor Hc-sr04
3. 7 x LEDs
4. 7 x 220ohm resistor
5. Breadboard
6. jumper wire
1
409
Features
Circuit diagram
Add LED and resistor according to circuit diagram .keep common all
the negative terminal of all 5 LED's.Connect resistors with the
positive terminal of this LED's.Now take arduino and connect pin
no. 4,5,6,7 with second terminal of this resistors.Now connect the
ground pin of arduino with the ground negative terminal of
LED's.Now take ultrasonic sensor HCSR-04 and connect it's
VCC to 5V pin of arduino and it's GND pin with arduino GND
pin.Finally connect the Trigger pin of ultrasonic sensor with pin
no. 2 of arduino and echo pin of ultrasonic sensor with pin no. 3
of arduino.
2
409
Code:
nt Time ;
int distance;
void setup()
{
pinMode(12,OUTPUT);
pinMode(13,INPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);
3
409
void loop()
{
digitalWrite(2,HIGH);
delayMicroseconds(10);
digitalWrite(2,LOW);
delayMicroseconds(5);
digitalWrite(2,HIGH);
delayMicroseconds(10);
Time = pulseIn(3,HIGH);
distance= 0.0343*Time/2;
Serial.print("distane from sensor to object is =");
Serial.println(distance);
delay(5);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
4
409
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if(distance>25 && distance <=30)
{
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
Working of project
Add LED and resistor according to circuit diagram .keep
common all the negative terminal of all 5 LED's.Connect resistors
with the positive terminal of this LED's.Now take arduino and
connect pin no. 4,5,6,7 with second terminal of this resistors.Now
connect the ground pin of arduino with the ground negative
terminal of LED's.Now take ultrasonic sensor HCSR-04 and
connect it's VCC to 5V pin of arduino and it's GND pin with
arduino GND pin.Finally connect the Trigger pin of ultrasonic
sensor with pin no. 2 of arduino and echo pin of ultrasonic sensor
with pin no. 3 of arduino.
Distance calculation
5
409