#include <WiFi.h>
const int LED_PIN = 5; // Pin connected to the LED
const int LDR_PIN = 35; // Pin connected to the LDR
void setup()
{
Serial.begin(115200); // Initialize serial communication
pinMode(LDR_PIN, INPUT); // Set LDR pin as input
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
}
void loop()
{
int lightLevel = analogRead(LDR_PIN); // Read the analog value from the LDR
if (lightLevel < 750) { // Adjust threshold as needed
digitalWrite(LED_PIN, HIGH); // Turn on the LED
Serial.println("Cahaya redup, lampu menyala"); // Light is dim, LED on
} else {
digitalWrite(LED_PIN, LOW); // Turn off the LED
Serial.println("Cahaya terang, lampu mati"); // Light is bright, LED off
}
// Display the LDR value
Serial.print("LDR Value: ");
Serial.println(lightLevel);
delay(1000); // Wait for 1 second before the next reading
}