#define LDR_PIN 36
#define LED_PIN 23
int ldr_val;
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
ldr_val = analogRead(LDR_PIN);
int light_percentage = map(ldr_val, 0,4063,100,0);
Serial.print("LDR Value : ");
Serial.print(ldr_val);
Serial.print(" , ");
Serial.print("Light percentage : ");
Serial.print(light_percentage);
Serial.println("%");
delay(500);
if (light_percentage < 50) {
digitalWrite(LED_PIN, HIGH);
}
else {
digitalWrite(LED_PIN, LOW);
}
}