// Define the pin connections
const int sensorPin = 7; // Digital pin for the light sensor
const int ledPin = 8; // Digital pin for the LED
void setup() {
pinMode(sensorPin, INPUT); // Set the sensor pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output
digitalWrite(ledPin, LOW); // Initially turn off the LED
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int sensorValue = digitalRead(sensorPin); // Read the sensor value
if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED if sensor detects light
Serial.println("Light detected!"); // Print a message for debugging
} else {
digitalWrite(ledPin, LOW); // Turn off the LED if no light is detected
Serial.println("No light detected!"); // Print a message for debugging
}
delay(1000); // Delay to prevent rapid LED flickering due to sensor readings
}