// Smart Street Light with Arduino
// Define pin connections
const int lightSensorPin = A0; // Light sensor connected to analog pin A0
const int motionSensorPin = 2; // Motion sensor connected to digital pin 2
const int relayPin = 13; // Relay pin connected to digital pin 13
// Define threshold values
const int lightThreshold = 600; // Adjust this value according to ambient light conditions
const int motionThreshold = 100; // Adjust this value according to sensitivity of motion sensor
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pin modes
pinMode(lightSensorPin, INPUT);
pinMode(motionSensorPin, INPUT);
pinMode(relayPin, OUTPUT);
// Initially turn off the street light
digitalWrite(relayPin, LOW);
}
void loop() {
// Read sensor values
int lightLevel = analogRead(lightSensorPin);
int motionDetected = digitalRead(motionSensorPin);
// Print sensor values (for debugging)
Serial.print("Light Level: ");
Serial.println(lightLevel);
Serial.print("Motion Detected: ");
Serial.println(motionDetected);
// Check conditions to turn on/off the street light
if (lightLevel < lightThreshold || motionDetected > motionThreshold) {
// If it's dark or motion is detected, turn on the street light
digitalWrite(relayPin, HIGH);
} else {
// Otherwise, turn off the street light
digitalWrite(relayPin, LOW);
}
// Delay before taking the next sensor readings
delay(1000);
}