Français

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:

  1. Total: 220 + 330 = 550 Ω
  2. Current (Ohm’s law, lesson E1): 5 ÷ 550 ≈ 9.1 mA, the same in both
  3. Voltage across the 220 Ω: 9.1 mA × 220 Ω ≈ 2.0 V
  4. 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 in series share the voltage Top: a 5 volt supply, a 220 ohm resistor and a 330 ohm resistor in one row, one after the other, then back to the supply. There is a single road, so one single current flows everywhere, about 9.1 milliamps. Total resistance: 220 + 330 = 550 ohms. Bottom: the voltage along the loop drawn as a staircase. It starts at 5 volts at the plus terminal, steps down by 2.0 volts across the 220 ohm resistor to 3.0 volts, then down by 3.0 volts across the 330 ohm resistor to 0 volts. The two steps, 2.0 V and 3.0 V, add up to the 5 V of the supply: each resistor takes a share in proportion to its resistance. FIG. 1 — SERIES: ONE CURRENT, SHARED VOLTAGE5 V220 Ω330 ΩII ≈ 9.1 mA, the same everywhereR total = 220 + 330 = 550 ΩVOLTAGE ALONG THE LOOP5 V3.0 V0 V−2.0 V−3.0 V2.0 V + 3.0 V =5 Vthe supply
Tap the diagram to open it full screen.

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:

  1. Total: (220 × 330) ÷ (220 + 330) = 72,600 ÷ 550 = 132 Ω (smaller than 220, good)
  2. Current in the 220 Ω lane: 5 ÷ 220 ≈ 22.7 mA
  3. Current in the 330 Ω lane: 5 ÷ 330 ≈ 15.2 mA
  4. Total current: 22.7 + 15.2 ≈ 37.9 mA. The currents of the lanes add up [3].
  5. 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Ω.

Resistors in parallel: two lanes A 5 volt supply feeds two resistors connected between the same two rails, like two lanes of a road: a 220 ohm resistor and a 330 ohm resistor. Both have the same 5 volts across them. The current leaves the plus terminal, about 37.9 milliamps, then splits: about 22.7 milliamps through the 220 ohm lane and about 15.2 milliamps through the 330 ohm lane. The two lanes join again and the full 37.9 milliamps returns to the minus terminal. Arrow thickness follows the current. Total resistance: 220 × 330 ÷ (220 + 330) = 132 ohms, smaller than the smallest resistor. FIG. 2 — PARALLEL: SAME VOLTAGE, SPLIT CURRENT5 V220 Ω330 Ω37.9 mA22.7 mA15.2 mA37.9 mAI5 V5 Vsame 5 Vacross both22.7 mA + 15.2 mA ≈ 37.9 mAthe lane currents add upR total = (220 × 330) ÷ (220 + 330) = 132 ΩCheck: in parallel, the total is always smaller than the smallest resistor.
Tap the diagram to open it full screen.

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.

The voltage divider Left: the divider schematic. Vin, 3.3 volts, at the top. R1, 10 kilohms, next to the input. The junction in the middle is the output, Vout. R2, 10 kilohms, next to ground, GND, at the bottom. One current flows down through both resistors. Right: the voltage along the chain drawn as a hill with two slopes. It stays at 3.3 volts along the top wire, slopes down across R1 to 1.65 volts at the junction, stays flat there, then slopes down across R2 to 0 volts. Vout is the middle step. Formula: Vout = Vin × R2 ÷ (R1 + R2) = 3.3 × 10 ÷ 20 = 1.65 volts. Equal resistors give half the input. FIG. 3 — THE VOLTAGE DIVIDERVin = 3.3 VR110 kΩR210 kΩVout1.65 VIGNDvoltage along the chain3.3 V1.65 V0 VVoutR1R2topGNDa hill with two slopes:Vout is the middle stepVout = Vin × R2 ÷ (R1 + R2)= 3.3 × 10 ÷ 20 = 1.65 V · equal resistors give half
Tap the diagram to open it full screen.

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).

Voltage divider
The voltage divider Left: the divider schematic. Vin, 3.3 volts, at the top. R1, 10 kilohms, next to the input. The junction in the middle is the output, Vout. R2, 10 kilohms, next to ground, GND, at the bottom. One current flows down through both resistors. Right: the voltage along the chain drawn as a hill with two slopes. It stays at 3.3 volts along the top wire, slopes down across R1 to 1.65 volts at the junction, stays flat there, then slopes down across R2 to 0 volts. Vout is the middle step. Formula: Vout = Vin × R2 ÷ (R1 + R2) = 3.3 × 10 ÷ 20 = 1.65 volts. Equal resistors give half the input. FIG. 3 — THE VOLTAGE DIVIDERVin = 3.3 VR110 kΩR210 kΩVout1.65 VIGNDvoltage along the chain3.3 V1.65 V0 VVoutR1R2topGNDa hill with two slopes:Vout is the middle stepVout = Vin × R2 ÷ (R1 + R2)= 3.3 × 10 ÷ 20 = 1.65 V · equal resistors give half
Tap the diagram to open it full screen.

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.

An LDR in a divider: more light, higher Vout Three copies of the same divider on 3.3 volts: on top the LDR, drawn as a resistor with two arrows pointing at it for the light it receives; at the bottom a fixed 10 kilohm resistor to ground; the junction is the output Vout. A gauge beside each shows Vout. Dark, about 1 lux: the LDR is about 70 kilohms, Vout is low, about 0.41 volts, roughly 510 ADC counts. Medium, a dark room, about 10 lux: about 10 kilohms, Vout about 1.65 volts, roughly 2050 counts. Bright, a bright room, about 100 lux: about 1.5 kilohms, Vout about 2.87 volts, roughly 3560 counts. More light means a smaller LDR, so the fixed resistor takes a bigger share and Vout rises. The values are typical: two LDRs can differ by 50 percent or more. FIG. 4 — AN LDR IN A DIVIDER (TYP. VALUES)Dark≈ 1 lux3V3LDRtyp. 70 kΩ10 kΩVout3.3 V0 VVout ≈ 0.41 V≈ 510 countsMedium≈ 10 lux · dark room3V3LDRtyp. 10 kΩ10 kΩVout3.3 V0 VVout ≈ 1.65 V≈ 2050 countsBright≈ 100 lux · bright room3V3LDRtyp. 1.5 kΩ10 kΩVout3.3 V0 VVout ≈ 2.87 V≈ 3560 countsMore light → smaller LDR → bigger share for the 10 kΩ → Vout rises.Symbol: a resistor with two arrows pointing in (light received).Typical values: two LDRs can differ by 50 % or more. Counts: ideal 0–3.3 V → 0–4095.LDR = light-dependent resistor (photoresistor, photocell).
Tap the diagram to open it full screen.

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.
Wiring: the LDR divider on GPIO34 Breadboard seen from above, the ESP32-DevKitC across the centre gap, USB on the left, its 3V3, GND and 34 pins in the top row with column j free. Five numbered wires. 1 red: the 3V3 pin to the top plus rail, which carries 3.3 volts here. 2 black: a GND pin to the top minus rail. 3 red: the plus rail to row 22, one leg of the LDR; the LDR's other leg is in row 25, the junction row. The 10 kilohm resistor goes from row 25 to row 29. 4 black: row 29 to the minus rail. 5 yellow: GPIO 34 to the junction row 25. GPIO 34 belongs to ADC1, channel 6, and is input only. FIG. 5 — WIRING, BREADBOARD VIEW+−−+jihgfedcba15101519222529ENBOOT5VCMDD3D213GND121427262533323534VNVPEN3V312345GPIO 34 · ADC1LDR10 kΩjunction: row 253V313V3 pin → top + rail (3.3 V here)2GND pin → top − rail3+ rail → LDR leg (row 22)410 kΩ end (row 29) → − rail5GPIO 34 → junction (row 25)LDR rows 22–25 · 10 kΩ rows 25–29GPIO 34: ADC1 (channel 6), input only. Keep the pin at or below 3.6 V.
Tap the diagram to open it full screen.

Check yourself

Three short questions. Nothing is saved, take your time.

  1. You connect two 1 kΩ resistors side by side (in parallel). What is the total resistance?

    • 2 kΩ
    • 500 Ω
    • 1 kΩ
    Show the answer

    500 Ω. In parallel, the total is always smaller than the smallest resistor [2][3]. For two equal resistors, it is half of one: 1 kΩ ÷ 2 = 500 Ω.

  2. 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
    Show the answer

    1.65 V. Vout = Vin × R2 ÷ (R1 + R2) = 3.3 × 10 ÷ 20 = 1.65 V. With equal resistors, the output is always half the input [4][5].

  3. 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
    Show the answer

    It goes up. More light means lower LDR resistance [6]. The top resistor shrinks, so the bottom one takes a bigger share of the voltage [4][6]: the voltage at the junction rises.


Sources

Show the 9 sources
  1. 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/
  2. 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
  3. 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/
  4. 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/
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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

Pinch or double-tap to zoom, swipe to change diagram.Scroll with Ctrl or double-click to zoom. Arrow keys change diagram.