Arduino UNO-Based Smart Street Light Control with PIR and LDR Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This project is a Street Light Control System that uses an Arduino UNO microcontroller to control street lights based on inputs from a Light Dependent Resistor (LDR) sensor and two Passive Infrared (PIR) sensors. The LDR sensor determines whether it is day or night, and the PIR sensors detect motion. At night, three LEDs are turned on via a transistor switch, and an additional LED is turned on when motion is detected.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
PIR Sensor
- Description: Passive Infrared sensor for motion detection.
- Pins: VDD, SIG, GND
LED: Two Pin (red)
- Description: Red LED.
- Pins: Cathode, Anode
LED: Two Pin (blue)
- Description: Blue LED.
- Pins: Cathode, Anode
Resistor
- Description: Resistor with a resistance of 200 Ohms.
- Pins: Pin1, Pin2
12v Battery
- Description: Power source.
- Pins: -, +
NPN-Transistor
- Description: NPN Bipolar Junction Transistor.
- Pins: E, C, B
Photoresistor (LDR) Sensor (Wokwi Compatible)
- Description: Light Dependent Resistor sensor.
- Pins: VCC, GND, DO, AO
Wiring Details
Arduino UNO
- 5V connected to VDD of both PIR sensors and VCC of the LDR sensor.
- GND connected to GND of one PIR sensor, GND of the LDR sensor, and - of the 12v Battery.
- A5 connected to AO of the LDR sensor.
- D11 connected to Anode of one red LED.
- D10 connected to Anode of another red LED.
- D9 connected to Anode of another red LED.
- D8 connected to Pin2 of one resistor.
- D5 connected to Anode of another red LED.
- D4 connected to SIG of one PIR sensor.
- D3 connected to Anode of the blue LED.
- D2 connected to SIG of the other PIR sensor.
PIR Sensor
- VDD connected to 5V of the Arduino UNO.
- GND connected to GND of the Arduino UNO.
- SIG connected to D2 of the Arduino UNO.
LED: Two Pin (red)
- Anode connected to D11 of the Arduino UNO.
- Cathode connected to Pin2 of one resistor.
LED: Two Pin (blue)
- Anode connected to D3 of the Arduino UNO.
- Cathode connected to Pin2 of one resistor.
Resistor
- Pin1 connected to GND of the LDR sensor.
- Pin2 connected to GND of the Arduino UNO.
12v Battery
- + connected to E of the NPN-Transistor.
- - connected to GND of the Arduino UNO.
NPN-Transistor
- E connected to + of the 12v Battery.
- C connected to Pin1 of one resistor.
- B connected to Pin2 of one resistor.
Photoresistor (LDR) Sensor (Wokwi Compatible)
- VCC connected to 5V of the Arduino UNO.
- GND connected to GND of the Arduino UNO.
- AO connected to A5 of the Arduino UNO.
Code Documentation
/*
* Street Light Control Project
* This code controls street lights based on LDR and PIR sensors.
* - LDR sensor determines day/night.
* - At night, three LEDs are turned on via a transistor switch.
* - PIR sensor detects motion to turn on an additional LED.
*/
const int ldrPin = A5; // LDR sensor pin
const int pirPin1 = 2; // PIR sensor 1 pin
const int pirPin2 = 4; // PIR sensor 2 pin
const int ledPin1 = 8; // LED controlled by transistor
const int ledPin2 = 9; // LED controlled by transistor
const int ledPin3 = 10; // LED controlled by transistor
const int motionLedPin = 3; // LED for motion detection
void setup() {
pinMode(ldrPin, INPUT);
pinMode(pirPin1, INPUT);
pinMode(pirPin2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(motionLedPin, OUTPUT);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(motionLedPin, LOW);
}
void loop() {
int ldrValue = analogRead(ldrPin);
int pirValue1 = digitalRead(pirPin1);
int pirValue2 = digitalRead(pirPin2);
// Check if it is night time
if (ldrValue < 500) { // Adjust threshold as needed
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
} else {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
// Check for motion detection
if (pirValue1 == HIGH || pirValue2 == HIGH) {
digitalWrite(motionLedPin, HIGH);
} else {
digitalWrite(motionLedPin, LOW);
}
delay(100); // Small delay to debounce sensors
}
This code initializes the pins for the LDR sensor, PIR sensors, and LEDs. In the loop function, it reads the values from the LDR and PIR sensors. If the LDR sensor detects that it is night (value below 500), it turns on three LEDs. If either of the PIR sensors detects motion, it turns on an additional LED.