AI • Technology • White Hat SEO
AI • TECHNOLOGY • ETHICAL SEO

Smart Technology.
Better Digital World.

AICircuit brings practical AI, technology, software and White Hat SEO guides that help you understand and use the digital world.

Explore Latest Guides →
ADVERTISEMENT

Explore AICircuit

AI

Artificial Intelligence

AI tools, tutorials, prompts and practical guides.

Technology

Technology & Software

Apps, software, Android, Windows and useful tech tips.

White Hat SEO

Ethical SEO

Safe and sustainable search optimization strategies.

Ai Assistant

AICircuit Assistant

LDR Sensor Working Principle, Circuit and Code – Complete Arduino Guide

LDR Sensor Working Principle, Circuit and Code

Learn how an LDR detects light, how its resistance changes, how to connect it with Arduino, and how to build a simple automatic light project.

What Is an LDR Sensor?

LDR means Light Dependent Resistor. It is a simple light-sensitive component whose resistance changes according to the amount of light falling on it.

In normal use, an LDR has higher resistance in darkness and lower resistance when more light reaches its surface. This makes it useful when an Arduino project needs to detect whether an environment is bright or dark.

LightMore light
LDRChanges resistance
ArduinoReads voltage

How Does an LDR Work?

The basic idea is simple: light changes the electrical resistance of the photoresistive material inside the component. As light increases, resistance generally falls. As light decreases, resistance rises.

Light ChangesLDR Resistance ChangesVoltage ChangesArduino Reads It

Arduino does not directly measure the LDR's resistance. Instead, the LDR is normally combined with another resistor to create a voltage divider. The changing resistance then produces a changing voltage that an analog input can read.

LDR in Light vs Darkness

ConditionTypical LDR Behavior
Bright lightResistance decreases
Normal room lightIntermediate resistance
Low lightResistance increases
DarknessResistance can become very high

Remember: LDRs are excellent for detecting relative changes in light, but a basic LDR circuit should not be treated as a precision lux meter.

Why Do We Need a Resistor?

The Arduino analog input reads voltage rather than resistance. A fixed resistor and LDR are therefore connected as a voltage divider.

+5V | [LDR] | +-------- A0 | [10KΩ] | GND

When the LDR resistance changes, the voltage at the A0 connection changes. Arduino can then convert that analog voltage into a numerical reading.

Components Required

ComponentQuantity
Arduino Uno1
LDR / Photoresistor1
10KΩ resistor1
Breadboard1
Jumper wiresSeveral

LDR Arduino Wiring

Arduino 5V | [ LDR ] | +---------- A0 | [ 10KΩ ] | Arduino GND

Connect one side of the LDR to 5V. Connect its other side to A0. Then connect the 10KΩ resistor between A0 and GND.

The LDR is not polarized, so its two legs can be inserted either way. What matters is the complete voltage-divider arrangement.

Arduino LDR Code

This simple sketch reads the sensor and displays the value in the Serial Monitor.

const int ldrPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int lightValue = analogRead(ldrPin);

  Serial.print("LDR Value: ");
  Serial.println(lightValue);

  delay(200);
}

Upload the sketch and open the Serial Monitor at 9600 baud. Shine a light on the LDR and then cover it with your hand. The reading should change.

What Does analogRead() Do?

analogRead() reads the voltage on an analog input and converts it into a number that the program can use. On the Arduino Uno, the analog input uses a 10-bit ADC, giving readings from 0 to 1023.

The exact LDR values depend on the sensor, resistor, wiring, supply voltage and surrounding lighting. That is why copying a threshold from another project may not work perfectly on your circuit.

Automatic Night Light With LDR

Once the sensor is working, you can use its reading to control an LED. The following example turns the LED on when the measured value falls below a chosen threshold.

const int ldrPin = A0;
const int ledPin = 13;

int threshold = 500;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {

  int lightValue = analogRead(ldrPin);

  Serial.println(lightValue);

  if (lightValue < threshold) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }

  delay(100);
}

Important: 500 is only an example threshold. Check your own Serial Monitor readings and adjust the value according to your circuit.

How to Calibrate Your LDR

Calibration is easy. First record the value when the LDR is in bright light. Then record the value when it is dark. Choose a threshold between those readings and test the circuit several times.

Bright ReadingDark ReadingChoose ThresholdTest

For example, if your circuit gives a reading around 850 in bright conditions and 250 in darkness, a value somewhere between them could be used as a starting point.

Common LDR Problems

Reading Does Not Change

Check the connection between the LDR, 10KΩ resistor and A0. Make sure the A0 wire is connected to the voltage-divider junction.

Reading Goes the Opposite Way

If the LDR and fixed resistor positions are reversed, the voltage behavior can also reverse. The circuit can still work; adjust your program accordingly.

Reading Jumps

Room lighting can naturally fluctuate. If you need a steadier decision, average several readings in software instead of reacting to a single measurement.

LED Never Turns On

Check the threshold. Do not assume that 500 will work for every LDR circuit.

LDR Applications

  • Automatic night lights
  • Street-light prototypes
  • Day and night detection
  • Light-sensitive alarms
  • Garden lighting projects
  • Basic automation
  • Arduino learning projects
  • Brightness detection

LDR vs Digital Light Sensor

LDRDigital Light Sensor
Simple and inexpensiveUsually more feature-rich
Excellent for relative light detectionBetter for measured light data
Uses a voltage-divider circuitOften communicates digitally
Great for beginner projectsUseful for more controlled measurements

Safety Tips

  • Use a suitable resistor with an LED.
  • Check wiring before powering the Arduino.
  • Do not connect mains electricity directly to a breadboard or Arduino.
  • Use properly rated and safely isolated hardware for real high-voltage lighting systems.
  • Remember that an LDR is normally a relative light sensor, not a precision lux instrument.

Frequently Asked Questions

What does LDR stand for?

LDR stands for Light Dependent Resistor. It is also called a photoresistor or photocell.

Does LDR resistance increase or decrease with light?

For a typical LDR, resistance decreases when more light reaches the sensor and increases as the environment becomes darker.

Why use a 10KΩ resistor?

The resistor forms a voltage divider with the LDR, allowing Arduino to detect the LDR's resistance change as a voltage change.

Can Arduino directly measure LDR resistance?

No. The analog input measures voltage. The voltage-divider circuit converts the resistance change into a measurable voltage.

Can an LDR measure exact lux?

A basic LDR circuit is better suited to relative brightness detection. Accurate light measurement generally requires a dedicated light sensor.

Which Arduino pin is used for the LDR?

On an Arduino Uno, an analog input such as A0 can be used to read the voltage from the LDR divider.

Conclusion

An LDR is one of the easiest sensors to start with because its concept is simple but teaches an important electronics principle. Light changes the LDR's resistance, the voltage divider converts that change into a voltage, and Arduino reads the voltage through an analog input.

After learning this basic circuit, you can build automatic night lights, light alarms, day/night detectors and many other Arduino automation projects.

Technical References

Technical concepts were checked against Arduino documentation and educational photoresistor/voltage-divider references.

About Me

My photo
Welcome to my profile. I am Adil Sultan, the person behind AICircuit, a technology and digital knowledge platform focused on Artificial Intelligence, technology, software, programming, blogging and White Hat SEO. Through AICircuit, I aim to share useful, practical and original information that helps students, beginners and technology enthusiasts understand the digital world. My focus is on ethical technology education, practical tutorials, AI tools, programming, blogging and sustainable White Hat SEO strategies. For AICircuit-related questions and collaboration, you can contact me through the official AICircuit contact channel.
Powered By Blogger

AICircuit is your trusted destination for Artificial Intelligence, Technology, AI Tools, Software, Blogging and White Hat SEO. Discover practical guides, helpful tutorials, latest tech updates, useful AI tools and ethical SEO strategies to grow your digital knowledge and online presence.

Powered by Blogger.

About AICircuit

Hi, I’m the creator of AICircuit.

I’m passionate about Artificial Intelligence, technology, AI tools, blogging and White Hat SEO. Through AICircuit, my goal is to make modern technology easier to understand and actually useful for everyday users, creators and bloggers.

I share practical guides, AI tools, technology tutorials and ethical SEO strategies based on real-world use rather than shortcuts or spam.

AI & Technology

AICircuit explores the rapidly changing world of AI and emerging technology — from AI tools and automation to productivity, software and practical digital workflows.

The focus is simple: use technology smarter, understand how it works, and turn useful tools into practical results.

White Hat SEO

I believe SEO should be built on quality, useful content and long-term trust.

AICircuit focuses on White Hat SEO techniques such as search intent, keyword research, on-page optimization, internal linking, technical SEO, indexing and Search Console — without relying on spam, manipulation or harmful shortcuts.

My aim is to help readers build websites that are genuinely useful to people and sustainable in search.

Connect With Me

Contact Form

Name

Email *

Message *

Tech Pulse

⚡ AICircuit Tech Pulse

Explore AI, Technology & White Hat SEO

ADVERTISEMENT