// Smart Light Pins
int ldrPin = 34;
int pirPin = 26;
int lightLed = 25;
// Smart Dustbin Pins
int trigPin = 5;
int echoPin = 18;
int binLed = 13;
// Threshold values
int lightThreshold = 3000; // Dark condition
int binThreshold = 15; // Bin full distance (cm)
void setup() {
Serial.begin(115200);
pinMode(ldrPin, INPUT);
pinMode(pirPin, INPUT);
pinMode(lightLed, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(binLed, OUTPUT);
Serial.println("Smart Home Automation Started");
}
void loop() {
// -------- SMART LIGHT --------
int ldr = analogRead(ldrPin);
int pir = digitalRead(pirPin);
Serial.print("LDR: ");
Serial.print(ldr);
Serial.print(" PIR: ");
Serial.println(pir);
if (pir == 1 && ldr > lightThreshold) {
digitalWrite(lightLed, HIGH);
Serial.println("Light ON");
} else {
digitalWrite(lightLed, LOW);
Serial.println("Light OFF");
}
// -------- SMART DUSTBIN --------
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration * 0.034 / 2;
Serial.print("Dustbin Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance > 0 && distance <= binThreshold) {
digitalWrite(binLed, HIGH);
Serial.println("Dustbin FULL");
} else {
digitalWrite(binLed, LOW);
Serial.println("Dustbin NOT FULL");
}
Serial.println("------------------");
delay(1000);
}