// Define pin numbers
const int ldrPin = A0; // LDR sensor input pin
const int activeIRPin = 12; // Active IR sensor input pin
const int passiveIRPin = 13; // Passive IR sensor input pin
const int ledPin = 13; // LED for indication
const int relayPin = 7; // Relay control pin for street light
void setup() {
Serial.begin(9600);
pinMode(ldrPin, INPUT);
pinMode(activeIRPin, INPUT);
pinMode(passiveIRPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
}
void loop() {
// Read LDR sensor
int ldrValue = analogRead(ldrPin);
// Read Active IR sensor
int activeIRValue = digitalRead(activeIRPin);
// Read Passive IR sensor
int passiveIRValue = digitalRead(passiveIRPin);
// Print sensor values
Serial.print("LDR Value: ");
Serial.println(ldrValue);
Serial.print("Active IR Sensor Value: ");
Serial.println(activeIRValue);
Serial.print("Passive IR Sensor Value: ");
Serial.println(passiveIRValue);
// Check if it's dark and a living object is detected
if (ldrValue < 1000) {
if (activeIRValue == HIGH) {
Serial.println("Living Being Detected!");
digitalWrite(relayPin, HIGH); // Turn on street light
}
else if (passiveIRValue == HIGH) {
Serial.println("Non-living Object Detected.");
digitalWrite(relayPin, HIGH); // Turn on street light
}
else {
Serial.println("No Object Detected.");
digitalWrite(relayPin, LOW); // Turn off street light
}
}
else {
Serial.println("Too Bright, No Object Detected.");
digitalWrite(relayPin, LOW); // Turn off street light
}
delay(1000);
}