#define LDR_PIN 34
#define POT_PIN 35
#define PIR_PIN 27
#define LED_PIN 25
void setup() {
pinMode(PIR_PIN, INPUT);
// New PWM method (Wokwi compatible)
ledcAttach(LED_PIN, 5000, 8);
Serial.begin(115200);
}
void loop() {
int ldrValue = analogRead(LDR_PIN);
int potValue = analogRead(POT_PIN);
int motion = digitalRead(PIR_PIN);
// Map potentiometer to brightness (0–255)
int brightness = map(potValue, 0, 4095, 0, 255);
Serial.print("LDR: ");
Serial.print(ldrValue);
Serial.print(" | Motion: ");
Serial.print(motion);
Serial.print(" | Brightness: ");
Serial.println(brightness);
// 🌞 Day → Light OFF
if (ldrValue < 2500) {
ledcWrite(LED_PIN, 0);
}
else {
// 🌙 Night
if (motion == HIGH) {
ledcWrite(LED_PIN, brightness); // Controlled brightness
} else {
ledcWrite(LED_PIN, 50); // Dim light
}
}
delay(500);
}