/*
* Photoresistor Light Sensor with Arduino
* This code reads light levels from a photoresistor (LDR)
* and displays the values on the Serial Monitor
*/
// Pin definitions
const int PHOTORESISTOR_PIN = A0; // Analog pin for photoresistor
const int LED_PIN = 13; // Built-in LED pin
// Variables
int lightValue = 0; // Variable to store the light reading
int threshold = 500; // Threshold value for LED control
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set LED pin as output
pinMode(LED_PIN, OUTPUT);
Serial.println("Photoresistor Light Sensor Initialized");
Serial.println("Light Level | Status");
Serial.println("-------------------------");
}
void loop() {
// Read the photoresistor value (0-1023)
lightValue = analogRead(PHOTORESISTOR_PIN);
// Print light level to Serial Monitor
Serial.print("Light: ");
Serial.print(lightValue);
Serial.print(" | ");
// Determine light condition
if (lightValue < 300) {
Serial.println("DARK");
digitalWrite(LED_PIN, HIGH); // Turn LED ON in dark
} else if (lightValue < 700) {
Serial.println("DIM");
digitalWrite(LED_PIN, HIGH); // Turn LED ON in dim light
} else {
Serial.println("BRIGHT");
digitalWrite(LED_PIN, LOW); // Turn LED OFF in bright light
}
// Wait before next reading
delay(500);
}