Lessons · Lesson E5 · Electricity basics · 20 min
Series, parallel and the voltage divider
Combine resistors in a row or side by side, split a voltage in two, and use a light-dependent resistor to let your ESP32 "see" the light. About 20 minutes, with an interactive divider.
Resistors in a row: series
Put two resistors one after the other, with nothing branching off between them. That is in series. The current has a single road, so the same current flows through both [1].
Their resistances simply add up [1][2]:
Rtotal = R1 + R2 + R3 + …
The total is always bigger than the biggest resistor in the row [3].
Worked example. A 220 Ω and a 330 Ω resistor in series, on a 5 V supply:
- Total: 220 + 330 = 550 Ω
- Current (Ohm’s law, lesson E1): 5 ÷ 550 ≈ 9.1 mA, the same in both
- Voltage across the 220 Ω: 9.1 mA × 220 Ω ≈ 2.0 V
- Voltage across the 330 Ω: 9.1 mA × 330 Ω ≈ 3.0 V
Add 2.0 V and 3.0 V and you get the 5 V of the supply back. Series resistors share the voltage, each taking a part in proportion to its resistance [1][4]. Keep this idea: it is the whole point of the voltage divider, in a few screens.
A handy use: you need 270 Ω and only have a 100 Ω and a 150 Ω? In series they make 250 Ω, close enough in many cases. In series, you can stack resistors to reach a value you do not have.
Resistors side by side: parallel
Now connect both resistors between the same two points, like two lanes of a road. That is in parallel. This time both resistors have the same voltage across them and the current splits between the two lanes [2][3].
Adding a lane makes it easier for current to flow, so the total resistance goes down. The formula uses the inverse of each value [2][3]:
1 ÷ Rtotal = 1 ÷ R1 + 1 ÷ R2 + …
For exactly two resistors, there is a shortcut that gives the same answer:
Rtotal = (R1 × R2) ÷ (R1 + R2)
Check the result with one rule: the total in parallel is always smaller than the smallest resistor [2][3]. If your answer is bigger, you made a slip.
Worked example. The same 220 Ω and 330 Ω, now in parallel, on 5 V:
- Total: (220 × 330) ÷ (220 + 330) = 72,600 ÷ 550 = 132 Ω (smaller than 220, good)
- Current in the 220 Ω lane: 5 ÷ 220 ≈ 22.7 mA
- Current in the 330 Ω lane: 5 ÷ 330 ≈ 15.2 mA
- Total current: 22.7 + 15.2 ≈ 37.9 mA. The currents of the lanes add up [3].
- Check: 5 V ÷ 132 Ω ≈ 37.9 mA. Same answer.
Special case worth remembering: two equal resistors in parallel give half the value. Two 10 kΩ in parallel make 5 kΩ.
The voltage divider
Take the series idea from screen 1 and put it to work. Two resistors in series across a voltage, and you tap the voltage in the middle. That is a voltage divider [4][5].
By convention, call the resistor next to the input voltage R1 and the one next to ground R2. The output voltage Vout is the voltage across R2 [5]:
Vout = Vin × R2 ÷ (R1 + R2)
Where does it come from? You already know both steps. The current in the row is I = Vin ÷ (R1 + R2). Then Vout = I × R2 [5]. Put them together and you get the formula.
Read it as a share: R2 takes a fraction R2 ÷ (R1 + R2) of the input voltage.
Worked examples (Vin = 3.3 V):
| R1 | R2 | Fraction | Vout |
|---|---|---|---|
| 10 kΩ | 10 kΩ | 10 ÷ 20 = 0.5 | 1.65 V |
| 10 kΩ | 20 kΩ | 20 ÷ 30 ≈ 0.67 | 2.2 V |
| 20 kΩ | 10 kΩ | 10 ÷ 30 ≈ 0.33 | 1.1 V |
Two things to notice [5]:
- Equal resistors give half, whatever their value.
- Only the ratio matters, not the actual values. 1 kΩ + 1 kΩ and 100 kΩ + 100 kΩ both give half. In practice, we pick values in the kilo-ohm range: big enough to waste little current, small enough to work well with the board.
Handle with care: a divider is for signals, not for power. Connect something to Vout and that something joins R2 in parallel (screen 2), which pulls the output down. Take the first row, 10 kΩ + 10 kΩ at 3.3 V, and hang a 10 kΩ load on the output: R2 and the load in parallel make 5 kΩ, so Vout = 3.3 × 5 ÷ 15 = 1.1 V instead of 1.65 V. A divider does not make a power supply.
Bonus, for later. A divider can also shrink a voltage that is too high for an input. Our rule is still to avoid 5 V signals on the ESP32 [7]: if you ever have no choice, ask for help or for a proper level-shifter module, and check the result with a multimeter before connecting the board.
Play with it. Move the Vin, R1 and R2 sliders and watch the gauge. Then flip the switch and replace R1 with an LDR: a “light” slider takes over (next screen explains why).
The LDR divider runs from the board's 3V3 pin: Vin is 3.3 V.
LDR (typ.) · Read from a typical curve: two LDRs can differ by 50 % or more.
Vout = Vin × R2 ÷ (R1 + R2)
Share of R2: R2 ÷ (R1 + R2)Output Vout
analogRead() on GPIO34typ.
never on an ESP32 pin
Measurable window: about 0.15 V to 3.1 V (11 dB)
Ideal model: 0–3.3 V → 0–4095, and 4095 (saturated) above 3.1 V. A real board differs a little.
A divider is for signals, not for power: a load on Vout pulls it down.
An LDR: a resistor that listens to light
A light-dependent resistor (LDR), also sold as a photocell or photoresistor, is a resistor whose value changes with the light that hits it [6]. In the dark it resists a lot. In bright light, it resists little [6].
One typical photocell is listed from about 200 kΩ in the dark down to about 10 kΩ at 10 lux, with more light taking it lower still [6]. Typical, not exact: two LDRs from the same batch can differ by 50 % or more, so an LDR tells you “lighter or darker than before”, not “exactly 340 lux” [6].
A microcontroller cannot measure a resistance directly. It measures voltage. So we put the LDR into a voltage divider [6], with the LDR as R1 on the top and a fixed resistor as R2 at the bottom. The junction is what we read.
Light up the LDR and its resistance drops. R1 gets smaller, R2 takes a bigger share, and Vout rises. With less light, Vout falls.
Here is that divider on 3.3 V with a fixed 10 kΩ at the bottom. The LDR values are the approximate ones from a photocell guide [6]; we recalculated the voltages for 3.3 V:
| Light (approx.) | LDR resistance (typ.) | Vout = 3.3 × 10 ÷ (10 + RLDR) | Roughly, in ADC counts (straight-line guess; saturated above 3.1 V) |
|---|---|---|---|
| Moonlit night, 1 lux | 70 kΩ | 0.41 V | 512 |
| Dark room, 10 lux | 10 kΩ | 1.65 V | 2,048 |
| Dark overcast day or bright room, 100 lux | 1.5 kΩ | 2.87 V | 3,561 |
| Overcast day, 1,000 lux | 300 Ω | 3.20 V | 4,095 (saturated: above the usable window, see screen 5) |
Notice how the voltage does not climb in a straight line with the light: it bends. At the bright end, the fixed 10 kΩ has so little to fight against that Vout hits the ceiling and cannot tell “bright” from “very bright”. The photocell guide’s fix: if you will use it in bright places, swap the fixed resistor for a smaller one, such as 1 kΩ [6].
Choosing the fixed resistor. Our rule of thumb: start with a value close to the LDR’s resistance at the light level that matters most to you. 10 kΩ is a good first try. If the readings pile up at one end, change the resistor, and keep your eyes on the numbers in the Serial Monitor.
Reading it on GPIO34
Wiring (a breadboard is fine, lesson E2):
- 3V3 pin of the board to one leg of the LDR
- The other leg of the LDR to a row, the junction
- A 10 kΩ resistor from the junction to GND
- A jumper from the junction to GPIO34
Use the 3V3 pin, never 5V, at the top of the LDR. On 5 V, the junction can climb to almost 5 V in bright light, far above the 3.6 V the pin can take [7].
Two good reasons to use GPIO34 here:
- It belongs to ADC1 (channel 6) [7]. The ESP32 has two analog-to-digital converters, ADC1 and ADC2, and ADC2 is also used by Wi-Fi [8]. Keeping our analog readings on ADC1 spares us trouble when we add Wi-Fi in a later lesson.
- GPIO34 is an input-only pin, with no internal pull resistors [7]. For a sensor reading, that is fine: our external 10 kΩ does the job.
What the board gives you. analogRead() returns a number from 0 to 4,095 (12 bits by default) [9]. analogReadMilliVolts() gives the reading already converted to millivolts [9].
One more thing to know: the usable window. With 11 dB attenuation (the setting we assume here), the ESP32 can measure voltages from about 150 mV to 3,100 mV [9]. Readings outside that window are not trustworthy: very dark and very bright cases get squashed. Most rows of our table land inside it; the brightest row does not. And whatever happens, the pin must never be driven above 3.6 V [7].
The sketch. Upload it as in lesson K1, open the Serial Monitor at 115200 baud, then cover the LDR with your hand and uncover it:
// Tinker Mission, lesson E5: read a light divider (LDR + fixed resistor) on GPIO 34
// Wiring (a voltage divider, LDR on top, fixed resistor on the bottom):
// 3V3 pin -> LDR -> junction -> 10 kohm resistor -> GND
// Junction -> GPIO 34 (ADC1, input only)
// Brighter light = lower LDR resistance = higher voltage at the junction.
const int LDR_PIN = 34;
void setup() {
Serial.begin(115200);
// No pinMode needed for an analog reading (GPIO 34 is input only anyway).
}
void loop() {
int raw = analogRead(LDR_PIN); // 0 to 4095 (12 bits)
int millivolts = analogReadMilliVolts(LDR_PIN); // same reading, converted to mV by the board package
Serial.print("raw = ");
Serial.print(raw);
Serial.print(" voltage = ");
Serial.print(millivolts);
Serial.println(" mV");
delay(250); // four readings per second keep the Serial Monitor readable
}
Download the sketch folder (.zip)
Expect numbers that jump a little from one reading to the next: that is normal. In lesson K3, we turn a noisy reading into a clean decision.
If it does not work.
- Reading always 0: the top leg of the LDR is not connected to the 3V3 pin, or the junction is wired straight to GND (a wrong leg or row).
- Reading always at the top: the junction is wired straight to 3V3, or the fixed resistor is missing or not pushed in, so nothing pulls the junction down.
- Reading wandering all over the place, even in steady light: the jumper is not in GPIO34 (or in the wrong row), so the pin is connected to nothing.
- Reading does not move with light: check the junction really sits between the LDR and the fixed resistor, and the board labels (clone boards can differ).
- Value moves the wrong way: swap the positions of the LDR and the fixed resistor, or flip your test in the code.
Check yourself
Three short questions. Nothing is saved, take your time.
You connect two 1 kΩ resistors side by side (in parallel). What is the total resistance?
- 2 kΩ
- 500 Ω
- 1 kΩ
A voltage divider has a 3.3 V input and two equal resistors, R1 = R2 = 10 kΩ. What is the output voltage?
- 3.3 V
- 1.65 V
- 0 V
An LDR sits on top, a fixed resistor at the bottom, and the junction goes to an analog pin. The room gets brighter. What happens to the reading?
- It goes up
- It goes down
- It does not change
Sources
Show the 9 sources
- All About Circuits, Volume I (DC), “Series Circuits and the Application of Ohm’s Law” (one single path, so the same current everywhere; resistances add; voltage drops add up to the supply) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-5/simple-series-circuits/
- OpenStax, University Physics Volume 2, section 10.2 “Resistors in Series and Parallel” (series: sum of the resistances, same current; parallel: reciprocal sum, smaller than any single resistance, same voltage) — https://openstax.org/books/university-physics-volume-2/pages/10-2-resistors-in-series-and-parallel
- All About Circuits, Volume I (DC), “Parallel Circuits and the Application of Ohm’s Law” (same voltage across every branch; branch currents add; total resistance smaller than any branch, reciprocal formula) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-5/simple-parallel-circuits/
- All About Circuits, Volume I (DC), “Voltage Divider Circuits” (a series circuit splits the voltage in proportion to the resistances; the voltage divider formula) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-6/voltage-divider-circuits/
- SparkFun, “Voltage Dividers” (R1 near the input and R2 near ground; Vout = Vin × R2 ÷ (R1 + R2); equal resistors give half the input; derivation from Ohm’s law) — https://learn.sparkfun.com/tutorials/voltage-dividers
- Adafruit, “Photocells” and “Using a Photocell” (a photocell/LDR is a resistor whose value depends on the light; about 200 kΩ in the dark to 10 kΩ at 10 lux; variation of 50 % or more between parts; the divider with a fixed resistor and an analog input; table of resistance by light level; use a smaller fixed resistor in bright places) — https://learn.adafruit.com/photocells and https://learn.adafruit.com/photocells/using-a-photocell
- Espressif, ESP32 Series Datasheet v5.3 (pin table: GPIO34 is ADC1_CH6; GPIO34 to GPIO39 are input-only, with no pull-up or pull-down; Table 5-3: high-level input voltage up to VDD + 0.3 V, which is 3.6 V at 3.3 V) — https://documentation.espressif.com/esp32_datasheet_en.pdf
- Espressif, ESP-IDF Programming Guide, “ADC Oneshot Mode Driver” (ADC2 is also used by Wi-Fi) — https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc/adc_oneshot.html
- Espressif, Arduino-ESP32 documentation, “ADC” (analogRead and analogReadMilliVolts; default resolution 12 bits, 0 to 4,095; measurable range on the ESP32 at 11 dB attenuation: 150 mV to 3,100 mV) — https://docs.espressif.com/projects/arduino-esp32/en/latest/api/adc.html