const int ledpin = 13;
const int lightpin = A2;
const int LIGHT = 200; // Sets LIGHT value for the light sensor
void setup() {
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(lightpin, INPUT);
}
void loop() {
int lightsens = analogRead(lightpin); // Read analog data from the light sensor
if (lightsens < LIGHT) {
// Check if it's dark (light level is below the threshold)
digitalWrite(ledpin, HIGH); // Turn the LED on
} else {
digitalWrite(ledpin, LOW); // Turn the LED off
}
}