divya_kadava
Published © GPL3+

Smart Street Lights Using LDR and ultrasonic sensor

The street lights we are using aren't smart. Isn't it cool when a vehicle is moving on road the LED will glow automatically.

BeginnerFull instructions provided30 minutes12,301
Smart Street Lights Using LDR and ultrasonic sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Smart Street Lights Using LDR and ultrasonic sensor

The circuit representation of Smart Street Lights

Code

Smart Street Lights Using LDR and ultrasonic sensor

Arduino
Arduino code for Smart Street Lights
const int trigpin=9;
const int echopin=10;
const int ledpin=13;
const int ldrpin=A0;
long duration;
int distance;
int safedistance;
void setup() {
  pinMode(trigpin,OUTPUT);
  pinMode(echopin,INPUT);
  pinMode(ledpin,OUTPUT);
  pinMode(ldrpin,INPUT);
 
}

void loop() {
  Serial.begin(9600);
  digitalWrite(trigpin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin,LOW);
  duration=pulseIn(echopin,HIGH);
  distance=duration*0.034/2;
  safedistance=distance;
  int light=analogRead(ldrpin);
  if(light<=400){
    if(safedistance<=5){
      digitalWrite(ledpin,HIGH);
      delay(10);
    }
    else if(safedistance>5){
      digitalWrite(ledpin,LOW);
      delay(10);
    }
  }
  delay(200);
}  
   

Credits

divya_kadava

divya_kadava

2 projects • 3 followers
currently, I am studying BTech. And having interest to learn technology i was started in developing hardware.

Comments