#include <Servo.h>

Servo motor;

const int servoPin = 9;
const int ldrPin = A0;

const int runSpeed = 1350;   // Spinning Speed 
const int stopSpeed = 1500; // Stop point 
const int lightThreshold = 400; // Adjust based on your room lighting

void setup() {
  motor.attach(servoPin);
  delay(100);
  motor.writeMicroseconds(stopSpeed); // Start stopped
}

void loop() {
  int lightValue = analogRead(ldrPin);

  if (lightValue > lightThreshold) {
    motor.writeMicroseconds(runSpeed);   // Light = spin
  } else {
    motor.writeMicroseconds(stopSpeed);  // Dark = stop
  }

  delay(20); // Small delay
}