LDR light sensor reads strange values: build a voltage divider

An LDR is a variable resistor, so it must be paired with a fixed resistor to make a voltage the board can read.

What the message means

The analog pin reads voltage, not resistance. A divider turns the changing resistance into a changing voltage.

Fix it in this order

  1. Connect the LDR from the supply to the analog pin, and a fixed resistor of about 10 kohm from the pin to ground.
  2. Swap the two parts if you want the reading to rise with light instead of falling.
  3. Use the supply voltage of your board. On an ESP32 keep it at 3.3 V.
  4. Choose the fixed resistor near the LDR resistance at the light level you care about.
  5. Average several readings to reduce noise, and calibrate with your own light levels.

Why it happens

An LDR changes resistance with light, but an analog input measures voltage. A voltage divider solves this by placing the LDR and a fixed resistor in series across the supply. The junction between them has a voltage that depends on the ratio of the two resistances, so as the LDR’s resistance changes with light, the junction voltage changes too. The ADC converts that voltage to a number. If the divider is missing or wired wrong, the pin sits at a fixed level and the reading never moves.

The fixed resistor sets the sensitivity range. Choosing a value close to the LDR’s resistance at the light level you care about spreads the voltage swing across a useful part of the range. Swapping the two parts reverses the direction, so the reading can rise or fall with light. Readings also vary with supply voltage and temperature, so averaging several samples and calibrating under your own lighting gives values that mean something for your project.

If you see this, do this

You seeDo this
Reading never changesDivider missing or wired wrongly.
Reading noisyAverage and add a capacitor.

Confirm the fix

  1. Measure the junction voltage with a multimeter while covering the LDR and then uncovering it; the reading should move clearly.
  2. Print analogRead() values once per second, first in darkness and then in bright light, and note the two numbers.
  3. Print the average of ten readings and compare its spread with single readings to confirm that averaging reduces noise.

Common mistake: Readers assume the LDR outputs a voltage on its own, when it only changes resistance and the divider is what lets the analog pin see that change.

floating analog pin, voltage divider calculator.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.