Voltage divider

Output from R1 and R2 or picking a pair from a series, ADC check.

What to calculate

Output

V3 V

Divider current
200 µA
Divider dissipation
0.001 W
Output resistance
6 kΩ
  • ESP32 (3.3 V): the pin survives, but the ADC is accurate only up to 2.45 V, above that the error grows.
  • Arduino (5 V): fine.
+5 VinputR1 10 kΩacross it 2 VR2 15 kΩacross it 3 V3 VoutputGND200 µA

R1 10 kΩ: brown,black,orange,gold

R2 15 kΩ: brown,green,orange,gold

How the divider is calculated

The divider output is Vout = Vin × R2 / (R1 + R2), where R1 sits between the input and the output, and R2 between the output and ground. The formula holds as long as the load current is much smaller than the current through the divider. The calculator shows the divider current Vin / (R1 + R2), the power, and the output resistance R1 × R2 / (R1 + R2).

In search mode the calculator goes through pairs from the E12 or E24 series with a sum from 10 kΩ to 1 MΩ and takes the pair with the smallest error. Under the answer come checks for an ESP32 and Arduino ADC input: the voltage, the accurate range, and an output resistance up to 10 kΩ for Arduino.

According to the ESP32 datasheet (table 4-4) with 11 dB attenuation the ADC measures from 150 to 2450 mV with an error of ±60 mV after calibration, and above 2450 mV the error grows. The ESP32's ADC2 is used by the Wi-Fi driver, so for a divider use ADC1 pins (GPIO32-39).

Examples

  • An 18650 cell on an ESP32: 4.2 V through 100 kΩ and 100 kΩ gives 2.1 V, which is inside the range up to 2.45 V. The divider current is 21 µA and the output resistance is 50 kΩ.
  • A 5 V signal to a 3.3 V input: the search in E24 gives R1 = 4.7 kΩ and R2 = 9.1 kΩ, with 3.297 V at the output at a current of 362 µA. The pair 10 and 20 kΩ gives 3.33 V.

Common mistakes

  • People put a 1 kΩ and 1 kΩ divider on a battery. It constantly draws 2.1 mA at 4.2 V, which is 50 mA·h per day.
  • People connect a divider of 100 kΩ or more to an Arduino. The ATmega328P ADC, per its datasheet, is designed for a source of about 10 kΩ or less, and with a higher resistance the reading depends on whether the sampling capacitor had time to charge.

FAQ

How do I measure an 18650 battery voltage on an ESP32 or Arduino?
On an ESP32 put in a divide-by-two divider, for example 100 kΩ and 100 kΩ: a full 4.2 V cell gives 2.1 V, which is inside the accurate range up to 2.45 V at 11 dB attenuation. Use an ADC1 pin (GPIO32-39). An Arduino with a 5 V supply has a 5 V reference, and 4.2 V fits in the range without dividing.
How do I make a 5 V to 3.3 V divider for a signal?
A pair of 10 kΩ on top and 20 kΩ on the bottom (3.33 V) or 4.7 and 9.1 kΩ (3.297 V) will do. The divider works in one direction only, from a 5 V output to a 3.3 V input. For bidirectional lines such as I2C you need a level shifter.
Can I power a module from a 12 V to 5 V divider?
No. The load is connected in parallel with R2, and the load current flows through R1. An 18 kΩ and 13 kΩ divider gives 5.03 V with no load, and with a 5 mA module (about 1 kΩ) it gives 0.59 V. To power something, use a 5 V linear regulator or a buck converter.
Which values keep the divider from draining the battery in sleep?
The divider current is Vin / (R1 + R2). A 100 and 100 kΩ pair at 4.2 V draws 21 µA, which is 0.5 mA·h per day; a 470 and 470 kΩ pair draws 4.5 µA. With resistances from 100 kΩ up, put a 100 nF capacitor from the ADC input to ground, which the Espressif documentation recommends to reduce noise.
What is the voltage divider formula?
Vout = Vin × R2 / (R1 + R2), where R1 is the upper resistor and R2 the lower one. For choosing values: R1 = R2 × (Vin − Vout) / Vout.

You might also need