LDR Light Sensor Explained: How It Works and How to Wire It to an Arduino Uno
Share
An LDR light sensor module pairs a light-dependent resistor (LDR, or photoresistor) with an LM393 comparator chip and an onboard potentiometer, turning the LDR's continuously variable resistance into a clean digital HIGH/LOW output at an adjustable brightness threshold — while still exposing the LDR's raw analog voltage on a second pin. It runs on 3.3–5V, drops straight onto an Arduino Uno or ESP32 with four wires (VCC, GND, DO, AO), and is the standard part behind automatic night lights, dusk-to-dawn switches, and light-triggered alarms.
How does a photoresistor (LDR) detect light?
The sensing element itself has no chip, no polarity, and no digital logic — it is a strip of cadmium-sulfide-type material whose electrical resistance drops as light intensity increases, a property called photoconductivity. In darkness an LDR can sit in the hundreds of kilohms; under bright light that can fall to a few hundred ohms. On its own, an LDR can't tell a microcontroller anything — you have to turn a resistance change into a voltage, which is what the rest of the module exists to do.
What's the difference between the DO and AO pins?
The module wires the bare LDR into a voltage divider, feeds that divider into one input of an LM393 comparator, and uses the onboard potentiometer to set the other input as an adjustable reference. DO (digital output) is the comparator's output: it snaps HIGH or LOW the instant ambient light crosses whatever threshold the potentiometer is set to — read it with a simple digitalRead() and you get clean on/off logic with no software threshold needed. AO (analog output) bypasses the comparator entirely and hands you the divider's raw, continuously variable voltage, read with analogRead() — useful when you want an actual light-level number (for logging trends, dimming, or setting your own threshold in code) rather than a simple switch.
How do you wire the LDR module to an Arduino Uno?
| Arduino Uno | Sensor pin | Signal |
|---|---|---|
| 5V | VCC | power |
| GND | GND | ground |
| D2 | DO | digital light/dark threshold |
| A0 | AO | analog light level |
Four wires cover both pins at once; most night-light builds only need DO. Turn the onboard potentiometer while covering and uncovering the sensor until DO flips at the darkness level you want it to react to — that's the entire calibration step, done in hardware, with no code required.
What does "day/night invert logic" mean?
Some LDR modules, including the one referenced here, add a jumper or onboard option that flips which state DO reports in the dark. Without it, you'd have to write an if (digitalRead(pin) == LOW) versus == HIGH depending on the project, and remember which way round it goes every time you reuse the part. With invert logic set at the hardware level, the same module can drive "turn on a light when it gets dark" or "turn on a fan when it gets bright" without touching a single line of firmware — the polarity choice moves out of your sketch and onto the board.
Watch it built live: a real Arduino Uno + LDR sensor project
Rather than describe a generic build, we typed one real sentence into Compoden's AI build assistant on the storefront and let it pick parts, price them, and explain the reasoning — unscripted, screenshotted as it happened:
"I want to build an automatic night light project using an LDR light sensor and an Arduino Uno"

For this prompt, the assistant priced the build around the bare GL5528 LDR rather than a pre-wired comparator module, pairing it with an LED pack, breadboard, jumper wires, and a power adapter. As it explained: "The GL5528 LDR is your ambient light sensor. LDR stands for Light Dependent Resistor. This sensor changes its electrical resistance based on how much light is falling on it... You will need to calibrate it, meaning you'll have to figure out what resistance values correspond to 'dark' and 'light' in your specific environment." That calibration step is exactly what the LM393 module above does in hardware with its potentiometer instead — both are the same underlying sensor, wired two different ways. Compoden also stocks that module version, the LDR Light Sensor Module with Day/Night Invert Logic (₹45), as an alternative in the same slot.
Watch the firmware get generated
We then asked Compoden's build companion, Soldr, to write the actual Arduino sketch for the same project — targeting the Uno specifically:

Because this build used the bare LDR, the generated sketch wires it as a voltage divider — the comments spell out one leg of the LDR to Arduino pin A2, the other leg to a 10k-ohm resistor, and the resistor's far end to GND — then reads the divider with analogRead() on LDR_PIN A2. No external library is needed for this approach; the Arduino IDE's built-in Library Manager step in the build log literally reads "none — analogRead." That's the software-threshold version of the same day/night decision the LM393 module makes in hardware.
So what is an LDR sensor good for?
Anything that needs to react to ambient light crossing a threshold: automatic night lights, dusk-to-dawn switches, light-following robots, laser tripwire alarms, and streetlight or garden-light controllers. The AO pin's continuous reading also makes it usable for logging ambient light trends over a day, not just switching something on or off.
Get everything in this build
The exact six parts Soldr priced above, at today's live price and stock — each links straight to checkout, or add the whole tray in one click.
| Part | Price | |
|---|---|---|
| Arduino Uno R3 CH340G ATmega328P Board | ₹230 | Add to cart → |
| GL5528 LDR | ₹5 | Add to cart → |
| 5mm LED Assorted Pack (Red, Green, Blue, Yellow, White) | ₹120 | Add to cart → |
| 400-point solderless breadboard | ₹40 | Add to cart → |
| Male-to-Male Breadboard Jumper Wires (20cm, 24AWG) | ₹40 | Add to cart → |
| 5V 2A Micro-USB Power Adapter | ₹140 | Add to cart → |
| Total | ₹575 | Add all 6 to cart → |
Prices and stock verified live at the time this was written; Compoden's storefront always reflects the current price at checkout. Swapping the bare GL5528 LDR for the LDR Light Sensor Module with Day/Night Invert Logic (₹45) removes the need for the external divider resistor and adds the invert jumper described above.
Built and Backed by Compoden
Every part above ships from Compoden's own India stock, tested for compatibility before it's carded together — not sourced individually and hoped to work. Delivery in 3–7 days across India, with COD and UPI available at checkout. If a part in this build doesn't perform as described, Compoden's support team will help you troubleshoot or replace it.
FAQ
What does LDR stand for?
Light Dependent Resistor, also called a photoresistor. Its resistance drops as light falling on it increases.
What's the difference between the DO and AO pins on an LDR module?
DO is a comparator output that switches HIGH or LOW at a threshold set by the onboard potentiometer — read with digitalRead() for simple on/off logic. AO is the raw, continuously variable divider voltage — read with analogRead() when you need an actual light-level number.
What does "day/night invert logic" mean on this module?
It's a jumper or onboard option that lets you choose whether DO goes HIGH in light or HIGH in darkness, so the same module can drive "light on at night" or "fan on in daylight" logic without changing your firmware.
Is an LDR fast enough for a laser tripwire alarm?
Yes for a simple beam-break trigger — you're only checking whether the light level crossed a threshold, not decoding a fast signal. The response time (tens of milliseconds) is too slow for actual optical data communication, but that's not what a tripwire needs.