This document provides a detailed overview of a simple light-responsive LED circuit controlled by an Arduino Uno R3 microcontroller. The circuit utilizes a light-dependent resistor (LDR) to measure ambient light levels and adjusts the brightness of a connected LED accordingly. The Arduino Uno R3 reads the analog value from the LDR and outputs a corresponding PWM signal to control the LED's brightness.
// Declare variables for pin numbers
int ldrPin = A0; // Analog pin connected to LDR
int ledPin = 9; // Digital pin connected to LED
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the light level from LDR
// Print the light level to the Serial Monitor
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Map the LDR value to an LED brightness value (0 to 255)
int ledBrightness = map(ldrValue, 0, 1023, 0, 255);
// Set the LED brightness based on LDR value
analogWrite(ledPin, ledBrightness);
// Add some delay before the next reading
delay(500);
}
Filename: sketch.ino
Description: This Arduino sketch reads the analog value from the LDR sensor connected to pin A0 and maps this value to a range suitable for LED brightness control (0-255). It then outputs this value as a PWM signal to pin 9, which is connected to the LED. The Serial Monitor outputs the raw LDR value for debugging purposes. The loop includes a 500ms delay between readings.