How to Interface a Light Sensor with Arduino Uno for an Automatic Street Light System

Oct 12, 2025
Tutorials
Advertisement
Article Top Ad (728x90)
How to Interface a Light Sensor with Arduino Uno for an Automatic Street Light System

Overview

Welcome to IoTZone! In this tutorial, we’ll show you how to interface a light sensor (LDR) with an Arduino Uno and build a simple automatic streetlight system. This project is perfect for beginners who want to dive into electronics, sensors, and programming with Arduino. We’ll walk you through the process step by step, from hardware setup to coding, so you can understand how light intensity affects the control of an LED. By the end of this guide, you'll have a fully functional light sensor circuit that turns an LED on or off based on the surrounding light conditions.

Materials Required:

  1. Arduino Uno - The brain of the project that will control everything.

  2. Light Dependent Resistor (LDR) - A light sensor that varies its resistance based on light intensity.

  3. LED - Used to indicate the system’s response to light intensity changes.

  4. Resistors - To limit the current flowing through the LED and LDR.

  5. Jumper Wires - To make all necessary connections.

  6. Breadboard - For assembling the components.

  7. Power Source - A USB cable or a battery to power the Arduino Uno.

Circuit Diagram

Before we begin with the hardware connections, here is a simple circuit diagram of the setup.

Circuit Diagram

Understanding the Circuit

Light Sensor (LDR) Setup

The Light Dependent Resistor (LDR) acts as a sensor in our circuit. It changes its resistance based on the light falling on it. The more light it receives, the lower the resistance. We use this characteristic to determine the level of ambient light.

  • LDR and Resistor Network: The LDR will be paired with a 10k ohm resistor in a voltage divider configuration. The output from this network will be connected to an analog input pin on the Arduino (A0 in our case) to read the light intensity. The LDR and the resistor are connected to 5V and Ground in such a way that the analog input (A0) measures the voltage drop between them, which is proportional to the light intensity.

  • LED Indicator: An LED is used to indicate whether it’s day or night. The LED will turn ON when it's dark and OFF when it's bright.

Resistor Ratings and Purpose

  • 330-ohm resistor: This is used with the LED to limit the current and prevent damage to the LED.

  • 10k-ohm resistor: This is used with the LDR to form the voltage divider circuit.

Wiring the Circuit

  1. Connect the LDR to the breadboard and wire it to 5V on one side and Ground on the other.

  2. Connect the 10k resistor in series with the LDR, ensuring one leg of the resistor connects to the LDR and the other to Ground.

  3. Wire the output from the junction of the LDR and resistor to A0 on the Arduino to measure the light intensity.

  4. Connect the LED to pin 7 (or any available digital pin) and its anode to 5V through a 330-ohm resistor.

  5. Ensure the ground is connected properly, so all components share a common ground.

Arduino Code for Light Sensor Circuit

The following Arduino code reads the light intensity from the LDR and turns the LED ON or OFF based on the threshold value you set. If the ambient light is below a certain level (indicating it’s dark), the LED turns ON, and if the light intensity is high (indicating it’s day), the LED turns OFF.

if__name__=="__main__":
    main()
intldrPin= A0;  // LDR connected to analog pin A0
intled=7;       // LED connected to digital pin 7
intthreshold=70; // Threshold for light intensity to turn the LED on or off

void setup()
{
    Serial.begin(9600);  // Start serial communication to print data
    pinMode(led, OUTPUT); // Set LED pin as output
}

void loop()
{
    int data = analogRead(ldrPin);  // Read light intensity from LDR
    Serial.println("");  // Start a new line
    Serial.print("Light Sensor ");
    Serial.print("Value = ");
    Serial.print(data); // Print the value of light intensity

    // Check if the light intensity is below the threshold
    if(data <= threshold)
    {
        digitalWrite(led, HIGH);  // Turn ON the LED when it’s dark
    }
    else
    {
        digitalWrite(led, LOW);  // Turn OFF the LED when it’s light
    }
}

Step-by-Step Explanation of the Code:

  1. Pin Initialization:

    • int ldrPin = A0; assigns the LDR sensor to analog pin A0.

    • int led = 7; assigns the LED to digital pin 7.

  2. Setup Function:

    • Serial.begin(9600); initializes serial communication for debugging and monitoring the light sensor values on the Serial Monitor.

    • pinMode(led, OUTPUT); sets the LED pin as an output so the Arduino can control it.

  3. Main Loop:

    • int data = analogRead(ldrPin); reads the light intensity from the LDR.

    • The value of the light intensity is printed to the Serial Monitor using Serial.print().

    • Thresholding: If the value of the light intensity (data) is less than or equal to the threshold, the LED is turned ON. Otherwise, it is turned OFF.

Testing the System

Once you’ve uploaded the code to your Arduino and built the circuit, you can test the system by changing the light conditions around the LDR. The Serial Monitor will display the current light sensor value. When the value falls below the threshold, the LED should light up, simulating an automatic street light turning ON in the dark.

  • Test the Sensor: Block the light with your hand and observe how the sensor value decreases and the LED turns ON.

  • Test with Light: Shine a light on the sensor, and the value should increase, causing the LED to turn OFF.

Conclusion

In this project, we successfully interfaced a light-dependent resistor (LDR) with an Arduino Uno to create an automatic streetlight system. The system reads the light intensity and uses that data to control an LED, simulating an automatic light that turns ON in the dark and OFF when it is bright. This is a great beginner project to learn how sensors work with Arduino and to explore simple light-based automation systems.

Sponsored Content
In-Content Ad (300x250)
Tutorials IoT Blog Verified
Written by

Administrator

IoT Expert
Verified Author
Advertisement
Ad Banner
(300x250)
Advertisement
Ad Banner (728x90)

Frequently Asked Questions

Common questions about How to Interface a Light Sensor with Arduino Uno for an Automatic Street Light System. Find answers to the most frequently asked questions.

An LDR is a sensor that changes its resistance based on the intensity of light falling on it. In this project, it is used with Arduino to detect light levels and control an LED, simulating an automatic streetlight system.
To interface an LDR with Arduino, you connect it in a voltage divider circuit with a resistor, and then read the analog values through the Arduino’s A0 pin. The Arduino can then process the data and control an output like an LED.
You will need an Arduino Uno, a Light Dependent Resistor (LDR), an LED, a 330-ohm resistor, a 10k-ohm resistor, jumper wires, and a breadboard to assemble the circuit.
The Arduino code reads the analog value from the LDR, compares it with a threshold value, and turns the LED on when the light intensity is below the threshold (indicating darkness) and off when it is above the threshold (indicating daylight).
The threshold value determines when the LED should turn on or off. It is set to a specific level of light intensity. If the LDR detects a light level below the threshold, the LED will turn on; if the light level is above it, the LED will turn off.
Yes, the basic concept can be scaled up for real-world applications such as automatic streetlights. The project demonstrates light-based automation, and with additional components, it can be adapted for larger, more robust systems.

User Reviews & Comments

Share your experience with this IoT Blog. Your feedback helps our community make informed decisions!

0 reviews

Share Your Experience

Help others by sharing your thoughts about this IoT Blog.

0/1000 characters

No Reviews Yet

Be the first to share your experience with this IoT Blog!

Related Blogs

Explore more IoT Blogs in the same category

What is the Internet of Things (IoT)?

What is the Internet of Things (IoT)?

Tutorials

The Internet of Things (IoT) connects everyday devices to the internet, enabling smart homes, healthcare, farming, and industries with automation, real-time monitoring, and data-driven insights.

IoT Security Risks and How to Protect Your Devices

IoT Security Risks and How to Protect Your Devices

Tutorials

Learn how to secure your IoT devices at home and office, reduce cyber risks, and protect privacy with best practices for a safer connected world.

IoT Components: Working of IoT, Sensors & Actuators, Role of IoT, IoT Cloud, IoT Analytics

IoT Components: Working of IoT, Sensors & Actuators, Role of IoT, IoT Cloud, IoT Analytics

Tutorials

Explore IoT components, working, sensors, actuators, IoT cloud, and analytics. Learn how IoT transforms data into insights, connecting devices for smarter and efficient solutions.

Advertisement
Ad Banner (728x90)
Advertisement
Footer Ad (728x90)