Introduction: Automatic Streetlights Using LDR

This is a simple Automatic Streetlights Using LDR and based on arduino. As long as the car passes the streetlights it will automatically ON and Off if its not. :D

Step 1: Items

*Some Popsicle stick

*cardboard(or any platform)

*LDR(light dependent resistor)

*LED(light emitting diode) i used white :)

*connecting wires (solid wires)

*resistor(4-100ohms)(4-10kohms)

Step 2: Circuit Diagram

Picture of Circuit Diagram

1.) Mount the LDR to the breadboard then test the LDR value using the program serial monitor

2.) As soon as you have the desired value(value depends in light environment. i got a value of 100 for dark) time to put the LED to test it using the program.

Step 3: Program

Picture of Program

1.) LDR pinout A5,A4,A3,A2

2.) LED pinout 2, 3, 4 , 5

3.) i assign sensorvalue as the stored value

Step 4: Code

Picture of Code

1.) As the sensorvalue become less than 100 the LED is High(on), greater than 100 means LED is low(off)

int sensorPin1 = A5; // select the input pin for LDR
int sensorPin2 = A4; // select the input pin for LDR int sensorValue1 = 0; // variable to store the value coming from the sensor int sensorValue2 = 0; // variable to store the value coming from the sensor int sensorPin3 = A3; // select the input pin for LDR int sensorPin4 = A2; // select the input pin for LDR int sensorValue3 = 0; // variable to store the value coming from the sensor int sensorValue4 = 0; // variable to store the value coming from the sensor
int led1=2;
int led2=3;
int led3=4;
int led4=5;
void setup() {
Serial.begin(9600); //sets serial port for communication
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() 
{
  ldr();
  if( sensorValue1<100)
  {
    digitalWrite(led1, HIGH);
  }
  else
  {
  digitalWrite(led1,LOW);
  }
  if( sensorValue2<100)
  {
    digitalWrite(led2, HIGH);
  }
  else
  {
  digitalWrite(led2,LOW);
  }
    if( sensorValue3<100)
  {
    digitalWrite(led3, HIGH);
  }
  else
  {
  digitalWrite(led3,LOW);
  }
      if( sensorValue4<100)
  {
    digitalWrite(led4, HIGH);
  }
  else
  {
  digitalWrite(led4,LOW);
  }
}
void ldr()
{
sensorValue1 = analogRead(sensorPin1); // read the value from the sensor
Serial.println(1);
Serial.println(sensorValue1); //prints the values coming from the sensor on the screen
delay(50);
sensorValue2 = analogRead(sensorPin2); // read the value from the sensor
Serial.println(2);
Serial.println(sensorValue2); //prints the values coming from the sensor on the screen
delay(50);
sensorValue3 = analogRead(sensorPin3); // read the value from the sensor
Serial.println(3);
Serial.println(sensorValue3); //prints the values coming from the sensor on the screen
delay(50);
sensorValue4 = analogRead(sensorPin4); // read the value from the sensor
Serial.println(4);
Serial.println(sensorValue4); //prints the values coming from the sensor on the screen
delay(50);
}

Comments

About This Instructable

403views

4favorites

License:

Bio: Hi I'm John Rey Cabatana 23y/o, a graduate of Electronics Engineering from Iloilo Science and Technology University. License ECE, ECT 2016-2017 #ilovepanda:)
More by ECEPanda:Marriage Proposal Using RGB LED Avoider MouseBotAutomatic Streetlights Using LDR
Add instructable to: