Light Dependent Resistor with Arduino

arduino logo

Welcome to the World of Sensors and Modules with Arduino!

The Light Dependent Resistor (LDR), also known as a photoresistor, is a key component in electronics that exhibit a change in resistance based on the intensity of light they are exposed to. In this sensors and modules guide, we’ll explore its working principle, key features, applications, and how it can enhance your Arduino projects.

If you’re new to Arduino, why not take a look at our Getting Started with Arduino guides. These guides are designed for beginners to learn the fundamental basics of Arduino¬†programming.

How the Light Dependent Resistor Works

LDRs operate on the principle of the photoconductivity effect, where their resistance changes in response to incident light. In the absence of light, an LDR exhibits high resistance due to the low conductivity of its semiconductor material. When exposed to light, the semiconductor material absorbs photons, generating electron-hole pairs and leading to an increase in conductivity. The change in conductivity results in a proportional change in resistance. More light leads to lower resistance, while less light results in higher resistance.

Features and Specifications:
  • Operating Voltage: 5V
  • Output: Analog signal
  • Size: 28mm x 15mm
  • Compatibility: This sensor is also compatible with other devices like the Raspberry Pi, ESP32, and ESP8266 etc…

Necessary Equipment:

  • Arduino (e.g., Arduino Uno)
  • Light Dependent Resistor Module
  • Jumper wires
  • Breadboard (optional)

Pin Configuration

Connecting the light dependent resistor to an Arduino is fairly simple. The connections are as follows:

  • S on the LDR to Analog pin A0 on the Arduino.
  • + on the LDR (middle pin) to 5V on the Arduino.
  • on the LDR to 5V on the Arduino.

Pin labels may vary.

Light Dependent Resistor with Arduino Diagram

KY-018 Photoresistor Module Fritzing Part is created by and published under Creative Commons Attribution-ShareAlike 4.0 International license

Arduino Code Example

// Define the pin to which the LDR is connected
const int ldrPin = A0;  // Change this to the actual analog pin you're using

void setup() {
  // Initialize the Serial communication for debugging

void loop() {
  // Read the analog value from the LDR
  int ldrValue = analogRead(ldrPin);

  // Print LDR value to Serial Monitor
  Serial.print("LDR Value: ");

  // Add a short delay for stability

Breaking Down the Code

Constant Declaration
  • A constant variable, ldrPin, is defined to represent the analog pin on the Arduino to which the LDR (Light Dependent Resistor) is connected.
Setup Function
  • The setup function initializes serial communication at a baud rate of 9600, facilitating communication with the Serial Monitor for debugging purposes.
Loop Function
  • The loop function is executed repeatedly.
  • The analog value from the LDR pin is read and stored in a variable, ldrValue.
  • A message “LDR Value: ” is sent to the Serial Monitor.
  • The actual LDR value is sent to the Serial Monitor on a new line.
  • A short delay of 500 milliseconds is added for stability before the next iteration.

Applications and Usage Scenarios

Light Sensing

LDRs are commonly used in light-sensing applications, such as automatic streetlights that turn on in the dark and off in daylight.

Camera Exposure Control

In photography, LDRs can be used to control the exposure settings based on ambient light conditions.

Energy-Efficient Lighting

LDRs contribute to energy conservation by controlling the intensity of artificial lighting based on natural light levels.

Sun Tracking Systems

LDRs can be employed in solar tracking systems, ensuring solar panels are always positioned to receive maximum sunlight.

Ambient Light Control

Develop an Arduino project that adjusts the brightness of an LED based on ambient light conditions using an LDR.

Solar-Powered Devices

Implement an LDR-based system to control the charging and discharging of batteries in solar-powered devices.


In this sensors and modules guide, we explained the functionality of the Light Dependent Resistor Module, exploring its working principles, and demonstrating how to interface it with an Arduino for practical applications. Light Dependent Resistors offer a simple yet powerful way to incorporate light-sensing capabilities into your Arduino projects. Understanding their features, working principles, and applications opens up possibilities for creating intelligent systems that adapt to varying lighting conditions. Whether it’s enhancing energy efficiency or creating responsive lighting systems, LDRs provide a versatile tool for Arduino enthusiasts and electronic hobbyists alike.

Discover the endless possibilities for Arduino projects with more of our Sensors and Modules guides.

Luke Barber

Hello, fellow tech enthusiasts! I'm Luke, a passionate learner and explorer in the vast realms of technology. Welcome to my digital space where I share the insights and adventures gained from my journey into the fascinating worlds of Arduino, Python, Linux, Ethical Hacking, and beyond. Armed with qualifications including CompTIA A+, Sec+, Cisco CCNA, Unix/Linux and Bash Shell Scripting, JavaScript Application Programming, Python Programming and Ethical Hacking, I thrive in the ever-evolving landscape of coding, computers, and networks. As a tech enthusiast, I'm on a mission to simplify the complexities of technology through my blogs, offering a glimpse into the marvels of Arduino, Python, Linux, and Ethical Hacking techniques. Whether you're a fellow coder or a curious mind, I invite you to join me on this journey of continuous learning and discovery.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights