Project: Dual-Control LED System with LDR Night Light and Button-Controlled LED
Concept
This project explores the integration of analog and digital controls using an LDR (Light Dependent Resistor) and a button to control two LEDs. The first LED functions as an automatic night light, turning on in low-light conditions as detected by the LDR. The second LED is controlled by a button, which allows the user to toggle it on and off. This setup demonstrates the use of both analog and digital inputs to create interactive light control.
Design and Execution
Components
– LDR: Senses ambient light and provides analog input for the night light.
– Button: Serves as a digital switch for the second LED.
– LED 1: Acts as a night light that responds to light levels.
– LED 2: Controlled by the button for manual on/off functionality.
– 220Ω Resistors: Limit current to protect the LEDs.
Schematic Diagram
The circuit is designed on a breadboard, with the LDR setup on one side and the button on the other. Power and ground rails connect both sides to the Arduino.
1. LDR Circuit: Creates a voltage divider with a 10kΩ resistor connected to analog pin A0.
2. Button Circuit: Connected to digital pin 7 with an internal pull-up resistor enabled in the code.
3. LEDs: LED 1 is controlled by the LDR (analog), and LED 2 by the button (digital).
Code
// Dual-Control LED System: LDR and Button // Pin definitions const int led1 = 8; // LED for night light (LDR-based) const int sensorPin = A0; // LDR sensor pin const int buttonPin = 7; // Button pin for second LED control const int led2 = 9; // Second LED pin (button-controlled) // Threshold for LDR to turn on the night light const int threshold = 500; // Adjust based on ambient light // Variables int sensorValue; // LDR sensor reading int buttonState; // Button state void setup() { pinMode(led1, OUTPUT); // Set LED1 as output pinMode(buttonPin, INPUT_PULLUP); // Set button as input with pull-up pinMode(led2, OUTPUT); // Set LED2 as output Serial.begin(9600); // Initialize serial communication } void loop() { // LDR-controlled LED (Night Light) sensorValue = analogRead(sensorPin); // Read LDR value Serial.println(sensorValue); // Print for debugging if(sensorValue < threshold) { // If below threshold, turn on LED1 digitalWrite(led1, HIGH); } else { // Otherwise, turn off LED1 digitalWrite(led1, LOW); } // Button-controlled LED buttonState = digitalRead(buttonPin); // Read button state if (buttonState == LOW) { // If button is pressed digitalWrite(led2, HIGH); // Turn on LED2 } else { digitalWrite(led2, LOW); // Turn off LED2 } delay(100); // Small delay for stability }
Observations
– Night Light Sensitivity: The LDR-based LED responds to ambient light, offering a basic “automatic night light” functionality. The threshold value can be adjusted to suit different lighting conditions.
– Button Responsiveness: The button controls the second LED reliably, allowing manual toggling.
Video Demonstration
https://drive.google.com/file/d/1wugSSY6orAYq02qOQg9335lDeIQAwCms/view?usp=drive_link
Reflection and Future Improvements
This project demonstrates the integration of analog and digital inputs for LED control, offering insights into how sensors can drive interactive behavior. Future improvements could include adding adjustable sensitivity for the night light or introducing more complex patterns for the button-controlled LED.
This project enhanced my understanding of basic sensor interactions, providing a foundation for more advanced input/output controls in Arduino projects.