Day 01

Begineer

Day 20 :- Automatic Light Control (LDR)

Aug 29, 2026

Completed

Wiring Schematic

Arduino Code

ARDUINO / C++

Day 20 Core Training Documentation

Project Overview

The Automatic Light Control LDR project teaches you how to create an intelligent lighting system that responds to natural light conditions: automatically turning lights on when it gets dark and off when it gets bright.

In this project, a Light Dependent Resistor (LDR) continuously measures ambient light levels. When the surrounding light decreases below a threshold, Arduino automatically turns on a light. When ambient light increases above the threshold, the light automatically turns off.

When the environment is bright, the LDR detects high light levels and keeps the light off, saving energy. As the sun sets and light decreases, the LDR reading drops below the threshold. Arduino instantly detects this change and activates the light. When morning comes and light increases again, Arduino automatically turns off the light.

This project teaches Light Sensor Operation, Ambient Light Measurement, Automated Lighting Control, Threshold-Based Automation, and Energy Conservation Systems.

By finishing this project, you’ll understand how automatic lighting systems work in street lights, smart homes, security lighting, and energy-efficient building automation.

Components Required

To build this circuit, collect these specific items from your kit:

Arduino Uno × 1, Breadboard × 1, LDR (Light Dependent Resistor) × 1, LED (High Power or Relay Controlled) × 1, 10kΩ Resistor × 2, 220Ω Resistor × 1, Relay Module × 1, Jumper Wires × 7, USB Cable × 1

Circuit Connections

Step 1: Connect Ground Rail

Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground connection for all components.

Step 2: Connect LDR to 5V

Connect one leg of the LDR directly to Arduino 5V. This leg provides power to the light sensor.

Step 3: Connect LDR to Analog Input

Connect the other leg of the LDR to Arduino Pin A0. This pin receives the analog sensor reading from the LDR.

Step 4: Connect First Pull-Down Resistor

Connect one end of a 10kΩ resistor to the junction between the LDR and Pin A0. Connect the other end to the breadboard GND rail. This creates a voltage divider circuit.

Step 5: Connect Relay Module VCC

Connect the VCC pin of the Relay Module to Arduino 5V. This provides power to the relay electromagnet.

Step 6: Connect Relay Module GND

Connect the GND pin of the Relay Module to the breadboard GND rail. This completes the relay power circuit.

Step 7: Connect Relay Module Signal

Connect the IN (input signal) pin of the Relay Module to Arduino Pin 9. This pin controls relay activation.

Step 8: Connect Light to Relay

Connect your LED or light bulb to the relay’s normally open (NO) and common (COM) terminals. The relay will control power to the light.

Step 9: Connect Second Pull-Up Resistor

Connect the other 10kΩ resistor between Pin A0 and 5V for additional signal stability. This ensures reliable analog readings from the LDR.

Step 10: Verify All Connections

Check all LDR connections and relay wiring before uploading your code. Ensure the light load is properly connected to the relay terminals.

Important: The LDR and resistors form a voltage divider that provides varying analog voltage based on light levels. Different lighting conditions produce different analog readings that Arduino compares against a threshold.

How the Arduino Code Works

Initialize Sensor and Relay

In setup(), Arduino configures Pin 9 as OUTPUT to control the relay. Pin A0 is set for analog input to read LDR values. The Serial Monitor starts for debugging and light level monitoring.

Read Light Level Continuously

Arduino continuously reads the LDR using analogRead(A0). The reading ranges from 0 to 1023, where high values indicate bright light and low values indicate darkness.

Establish Light Threshold

A threshold value is defined in the code. This value represents the decision point between darkness and brightness. When the LDR reading falls below this threshold, darkness is detected.

Control Light Based on Conditions

When the LDR reading drops below the threshold, Arduino sets Pin 9 HIGH, activating the relay and turning on the light. When the reading rises above the threshold, Pin 9 goes LOW, deactivating the relay and turning off the light.
 

Display Lighting Information

The current light level reading and light status are printed to the Serial Monitor. This information helps users understand ambient light conditions and adjust the threshold value if needed.

Expected Output

After uploading your code, here is what happens.

In bright daylight, the LDR reading is high and the light remains off. As the sun begins to set and ambient light decreases, the LDR reading gradually drops. When the reading falls below your threshold value, the relay clicks and the light automatically turns on. As darkness deepens, the light continues to shine. When morning arrives and light increases, the LDR reading climbs above the threshold. The relay clicks and the light automatically turns off. The system continuously monitors ambient light and adjusts automatically.

Operational Troubleshooting

Light Does Not Turn On :- Verify that Pin 9 connects to the relay signal pin. Check that the relay receives proper 5V power. Ensure the light is properly connected to the relay terminals. Test by lowering the threshold value in your code.

Light Does Not Turn Off :- Increase the threshold value in your code so the light turns off at higher ambient light levels. Check that the LDR is not blocked and can detect changes in light.

LDR Reading Does Not Change :- Verify the LDR connections and ensure it is exposed to light. Check that the pull-down resistor is connected between Pin A0 and GND. Try covering the LDR with your hand to test if readings change.

Relay Clicks Constantly :- Increase the gap between your threshold value and the actual light level. Add a debounce delay in your code to prevent rapid on-off cycling.

Light Too Dim or Too Bright :- If using an LED, verify the 220Ω resistor limits current appropriately. If using a relay-controlled light, check that the relay is activating the light correctly.

What You Learned

By finishing this project, you now know :-

How LDR sensors detect light levels, how to create voltage divider circuits, how to use analog readings for threshold-based decision making, how to control high-power loads safely with relays, and how to build automatic lighting systems.

Next Lesson

In Day 21, you’ll learn how to create a Temperature-Based Fan Control System using a DHT11 sensor to automatically adjust fan speed based on temperature.