Interfacing LDR Light Sensor with Arduino

1,166 views

Introduction

In the world of electronics, sensors are an essential part of any project. Light sensors are a common type of sensor used to detect light levels and adjust the output of a circuit accordingly. LDR (Light Dependent Resistor) sensors are widely used for light sensing applications due to their simplicity, low cost, and ease of use.

In this article, we will discuss how to interface an “LDR light sensor with Arduino” to control the intensity of light in various applications.

What is LDR Light Sensor?

LDR (Light Dependent Resistor) Light Sensor is a type of sensor that is used to detect the presence or absence of light in a given environment. It is a passive electronic component that changes its resistance in response to the amount of light falling on its surface. LDRs are made up of semiconductor materials that are sensitive to light, and when exposed to light, they produce an electric current that varies with the intensity of the light. LDRs are commonly used in various applications such as light-sensitive alarms, automatic street lighting systems, and in photography to measure the amount of light falling on the subject. They are cost-effective, easy to use, and reliable, making them an excellent choice for a wide range of applications.

LDR Light sensor
LDR Light sensor

Hardware Components

To interface light sensor with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
Light Sensor1
Jumper Wires1

LDR Light Sensor Pinout

LDR-Light-sensor-Pinout
LDR-Light-sensor-Pinout
Pin NamePin Description
5V+Ve Power Supply.
GNDGround.
SIGAnalog Output Signal

LDR Light Sensor Arduino Circuit

Make connections according to the circuit diagram given below.

Light Sensor Arduino Circuit
Light Sensor Arduino Circuit

Wiring / Connections

ArduinoLight Sensor
5VVCC
GNDGND
A5SIG PIN

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

int photocellPin = A5;     // the cell and 10K pulldown are connected to a5
int photocellReading;     // the analog reading from the analog resistor divider
 
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);  
}
 
void loop(void) {
  photocellReading = analogRead(photocellPin);  
 
  Serial.print("Analog reading = ");
  Serial.print(photocellReading);     // the raw analog reading
 
  // We'll have a few thresholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Dark");
  } else if (photocellReading < 200) {
    Serial.println(" - Dim");
  } else if (photocellReading < 500) {
    Serial.println(" - Light");
  } else if (photocellReading < 800) {
    Serial.println(" - Bright");
  } else {
    Serial.println(" - Very bright");
  }
  delay(1000);
}

Code Explanation

This Arduino code reads the value of an LDR light sensor connected to analog pin A5 of the Arduino board. The sensor reading is then displayed on the Serial Monitor via the serial communication port of the board. The code then uses a series of threshold values to determine the amount of light detected by the sensor.

If the photocellReading is less than 10, it is considered “Dark,” if it is less than 200, it is considered “Dim,” if it is less than 500, it is considered “Light,” if it is less than 800, it is considered “Bright,” and if it is greater than or equal to 800, it is considered “Very bright.”

The delay(1000) command at the end of the loop ensures that the code waits for one second before repeating the process, which effectively creates a one-second delay between each reading. Overall, this code allows you to use an LDR sensor to detect the light levels and classify them into various categories based on pre-defined threshold values.

Applications

Here are some common applications of LDR (Light Dependent Resistor) Light Sensor:

  • Automatic lighting control systems
  • Light-sensitive alarms
  • Photography and imaging equipment
  • Outdoor and street lighting systems
  • Security systems that use light detection
  • Industrial automation processes
  • Agricultural processes that require light detection and monitoring
  • Weather monitoring systems that detect ambient light levels
  • Electronic toys and games that respond to changes in light levels
  • Home automation systems that control lighting based on the time of day or ambient light levels.

Conclusion.

In conclusion, interfacing an LDR light sensor with an Arduino is a straightforward process that can be used to control the intensity of light in various applications. This simple technique can be used in many projects, from controlling streetlights to controlling the brightness of a room’s lights. With the help of Arduino, it is possible to develop complex systems using the simple LDR light sensor.