#include Servo myServo; int ldrPin = D1; // your connection int servoPin = D0; int threshold = 500; // adjust it void setup() { myServo.attach(servoPin); Serial.begin(115200); } void loop() { int ldrValue = analogRead(ldrPin); Serial.println(ldrValue); if (ldrValue > threshold) { myServo.write(180); // light } else { myServo.write(0); // darkness } delay(100); }