Electronics From Zero Search/

Circuit lab 02 · Intermediate

Voltage dividers and sensors

Most simple sensors are resistors whose value changes with the world around them. Put one in a voltage divider and the change becomes a voltage a microcontroller can measure. Swap sensors, connect a load, and watch what the ADC actually reads.

The bench

Bench · divider → ADCSimplified model
Voltage divider feeding an ADC input A supply feeds a fixed resistor R1 on top and a sensor at the bottom. The midpoint, Vout, goes to an ADC input; an optional load can be connected from Vout to ground.
V out—
Sensor R—
Divider current—
ADC reading—
Temperature read back—
Bottom resistor
V
Ω

0% is darkness, 100% is bright daylight. LDR model: 1 MΩ dark to 1 kΩ bright.

    How the numbers were worked out

    Response curve

    How Vout changes across the sensor’s whole range with the current R1. The dot is where the bench is now. A steep curve over the range you care about means a sensitive measurement.

    Design it: choose R1

    For the biggest change in Vout between two sensor readings, choose R1 = √(Rmin × Rmax), the geometric mean of the sensor’s resistance at each end of the range you care about.

    Best R1—
    Nearest E12—
    V out swing—

    The model behind this lab

    Simplified model, not a SPICE simulation

    Vout = Vin × R2 ÷ (R1 + R2). With a load, R2 is replaced by R2 ∥ RL = 1 ÷ (1/R2 + 1/RL). The ADC is ideal: code = floor(Vout ÷ Vref × 2ⁿ), clamped to its range.

    The LDR model is illustrative: its resistance falls smoothly on a logarithmic scale from 1 MΩ in the dark to 1 kΩ in bright light. Real LDRs vary a lot between parts and respond slowly. The thermistor uses the B-parameter equation, R = R25 × eB(1/T − 1/T25) with T in kelvin, which is accurate to roughly a degree or so over a limited range; the Steinhart–Hart equation is more accurate.

    Protect your inputs

    Never let a divider output exceed your microcontroller’s supply voltage. A divider powered from 5 V can destroy the input of a 3.3 V board; power the divider from the board’s own 3.3 V pin instead.

    Practical challenge

    Use the bench above to check each answer.

    Next: put this sensor to work in the automatic night light project.