Modern microcontrollers like the ESP32, Raspberry Pi Pico, and 3.3 V Arduino boards (such as the MKR series, Due, and Nano 33 BLE) operate at a 3.3 V system logic level. Their internal analog-to-digital converters (ADCs) measure voltages strictly within a 0 V to 3.3 V window. Connecting a higher voltage directly to a GPIO pin forces current through the chip's internal electrostatic discharge (ESD) protection diodes, distorting analog readings and risking permanent hardware damage.
Yet real-world maker and embedded projects frequently interface with higher voltages:
- 12 V battery systems: Lead-acid, AGM, 3S lithium-ion (11.1 V nominal, 12.6 V peak), and 4S LiFePO4 battery packs.
- 5 V legacy sensors: Pressure transducers, ultrasonic rangefinder echo pins, infrared distance sensors, potentiometers, and analog gas sensors.
A two-resistor voltage divider is the most common, cost-effective way to scale these signals down to a safe range. However, building a divider that delivers accurate measurements requires three practical considerations: providing voltage headroom for charging spikes, picking standard E12 resistor values, and preventing ADC loading errors.
This guide walks through both circuits with step-by-step math. Every figure below was calculated using the site's tested voltage divider calculator and verified against the Arduino pin planner.
The Voltage Divider Circuit and Core Formulas
A voltage divider consists of two resistors in series between an input voltage (Vin) and ground (GND). The output voltage (Vout) is tapped at the node between them and routed to the microcontroller's ADC pin:
Vin (Battery or 5V Sensor)
|
[R1] (Top / high-side resistor)
|
+-----> Vout (To Microcontroller ADC Pin)
|
[R2] (Bottom / low-side resistor)
|
GND (Common ground)
The common ground rule: The negative terminal of your battery or sensor power supply must share a direct electrical connection with the microcontroller ground pin. Without a shared ground reference, the voltage measured at the ADC pin floats unpredictably.
The unloaded output voltage is determined by the ratio of R2 to the total series resistance:
Vout = Vin × R2 / (R1 + R2)
In microcontroller firmware, you read the ADC count, convert it to the voltage seen at the pin, and reconstruct the original input voltage using the inverse ratio:
Vin = Vout × (R1 + R2) / R2
For a 12-bit ADC (such as on the ESP32), the conversion from raw counts (0 to 4,095) to pin voltage is:
Vout = (rawADC / 4095.0) × Vref
For a 10-bit ADC (such as on standard 3.3 V Arduino boards), the resolution is 1,024 counts (0 to 1,023):
Vout = (rawADC / 1023.0) × Vref
Picking the Right ESP32 Pins
When deploying a voltage divider on an ESP32, pin selection matters:
- Always use ADC1 pins: GPIO 32, 33, 34, 35, 36 (SENSOR_VP), and 39 (SENSOR_VN). ADC2 pins (GPIO 0, 2, 4, 12 to 15, and 25 to 27) share internal hardware with the Wi-Fi subsystem. The moment Wi-Fi initializes, ADC2 analog reads fail or return invalid values.
- Prefer input-only pins: GPIO 34, 35, 36, and 39 have no internal software pull-up or pull-down resistors, making them ideal for high-impedance analog measurements. You can verify available pins for your peripherals using the Arduino pin planner.
Choosing Standard Resistors from the E12 Series
Resistors are manufactured in standardized decade values known as Preferred Numbers. The most widely available collection is the E12 series (10% tolerance band spacing), which provides 12 base values per decade:
1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2
In thousands of ohms (kΩ), these correspond to 1.0 kΩ, 1.2 kΩ, 1.5 kΩ, 1.8 kΩ, 2.2 kΩ, 2.7 kΩ, 3.3 kΩ, 3.9 kΩ, 4.7 kΩ, 5.6 kΩ, 6.8 kΩ, 8.2 kΩ, 10 kΩ, 12 kΩ, 15 kΩ, 18 kΩ, 22 kΩ, 27 kΩ, 33 kΩ, 39 kΩ, 47 kΩ, 56 kΩ, 68 kΩ, 82 kΩ, and 100 kΩ.
When picking resistors for an analog input divider, two conflicting electrical constraints dictate the values:
| Design Goal | What Happens with Low Values (< 1 kΩ) | What Happens with High Values (> 100 kΩ) |
|---|---|---|
| Current Consumption | High quiescent current. A 100 Ω + 220 Ω divider on 12 V draws 37.5 mA (0.45 W), draining batteries rapidly and overheating 1/4-watt resistors. | Tiny quiescent current (< 10 µA), ideal for long-term battery monitoring. |
| ADC Impedance & Noise | Negligible source impedance. Easy for ADC to sample cleanly. | High source impedance. The ADC internal sampling capacitor causes voltage sag, resulting in noisy, inaccurate readings. |
The Thevenin equivalent resistance (Rth) looking into the divider midpoint is the parallel combination of the two resistors:
Rth = (R1 × R2) / (R1 + R2)
For unbuffered SAR ADCs like those in the ESP32 and AVR microcontrollers, the manufacturer application notes recommend an analog source impedance of Rth ≤ 10 kΩ. Keeping Rth near 5 kΩ to 10 kΩ strikes the optimal balance between low idle power draw and fast, accurate ADC sampling.
The Loading Effect Explained
The basic divider equation assumes that nothing draws current from Vout. In reality, whatever circuit you connect across R2—whether a digital multimeter, an oscilloscope probe, or the microcontroller's internal ADC circuitry—acts as an additional load resistance (R_L) in parallel with R2.
When R_L connects across R2, the effective resistance of the bottom branch drops:
R2_effective = (R2 × R_L) / (R2 + R_L)
Because R2_effective is always smaller than R2, the loaded output voltage drops below the theoretical unloaded value:
Vout_loaded = Vin × R2_effective / (R1 + R2_effective)
Alternatively, using the Thevenin equivalent circuit:
Vout_loaded = Vth × [R_L / (Rth + R_L)]
The loading error percentage is directly proportional to the ratio of source impedance to load impedance:
Loading Error (%) = [Rth / (Rth + R_L)] × 100
To maintain less than 1% loading error, the connected load resistance R_L must be at least 100 times larger than Rth. To maintain less than 0.1% error, R_L must be at least 1,000 times larger than Rth.
Here is how different measuring loads affect standard 12 V and 5 V divider circuits:
| Connected Load (R_L) | 12 V Battery Divider (R1=47k, R2=10k, Rth=8.25k) | 5 V Sensor Divider (R1=10k, R2=15k, Rth=6.0k) | Impact on Accuracy |
|---|---|---|---|
| 10 MΩ (Digital Multimeter) | Vout = 2.1035 V (error = 0.08%, drop = 1.7 mV) | Vout = 2.9982 V (error = 0.06%, drop = 1.8 mV) | Negligible. High-end DMMs read the true unloaded voltage. |
| 1 MΩ (Oscilloscope Probe 1X) | Vout = 2.0880 V (error = 0.82%, drop = 17.2 mV) | Vout = 2.9821 V (error = 0.60%, drop = 17.9 mV) | Under 1% error. Acceptable for quick bench checks. |
| 100 kΩ (Low-impedance load) | Vout = 1.9449 V (error = 7.62%, drop = 160.4 mV) | Vout = 2.8302 V (error = 5.66%, drop = 169.8 mV) | Severe error. Alters ADC readings significantly. |
| 10 kΩ (Heavy load) | Vout = 1.1538 V (error = 45.19%, drop = 951.4 mV) | Vout = 1.8750 V (error = 37.50%, drop = 1,125.0 mV) | Circuit failure. Why dividers cannot power active loads. |
Worked Example 1: Reading a 12 V Battery with Headroom
A common mistake when measuring a 12 V battery is designing the divider so that exactly 12.0 V produces 3.3 V. In real hardware, a nominal 12 V battery operates across a wide voltage span:
- 10.5 V: Fully discharged cut-off threshold.
- 12.0 V: 50% state of charge resting.
- 12.6 V to 12.8 V: 100% resting open-circuit charge.
- 14.4 V: Absorption charging voltage delivered by an automotive alternator, solar MPPT controller, or smart charger.
- 15.0 V: Equalization cycles or alternator transient spikes.
If you scale 12.0 V to 3.3 V, then when the battery charges at 14.4 V, the divider output rises to 3.96 V. This exceeds the 3.3 V pin rating and will overload the ADC.
To provide safe operation under all charging conditions, design for a maximum input of Vin_max = 15.0 V mapping to ≤ 3.3 V:
Target Ratio: R2 / (R1 + R2) ≤ 3.3 / 15.0 = 0.220
Selecting the E12 Resistor Pair
From the E12 series, the standard pair R1 = 47 kΩ and R2 = 10 kΩ provides an optimal match:
- Total series resistance:
47,000 Ω + 10,000 Ω = 57,000 Ω(57 kΩ). - Divider ratio:
10 / 57 ≈ 0.1754386(or a scale factor of5.70). - Thevenin source resistance:
Rth = (47,000 × 10,000) / 57,000 = 8,245.6 Ω ≈ 8.25 kΩ. Because this is below 10 kΩ, it drives the microcontroller ADC cleanly without an active op-amp buffer. - Quiescent current at 12.0 V:
12.0 V / 57,000 Ω = 0.2105 mA(211 µA). This discharges less than 5 milliamp-hours per day from the battery. - Power dissipation: At 15.0 V, total power across both resistors is
15.0 V × (15.0 V / 57,000 Ω) = 3.95 mW(3.25 mW in R1, 0.69 mW in R2), well within 1/8 W (125 mW) or 1/4 W (250 mW) resistor limits.
12 V Battery Mapping Table
Using R1 = 47 kΩ and R2 = 10 kΩ, here is the exact voltage and ADC count mapping across the battery's operating profile:
| Battery Voltage (Vin) | Output Voltage (Vout) | 12-Bit ESP32 ADC (Counts) | 10-Bit Arduino ADC (Counts) | Battery State / Operating Condition |
|---|---|---|---|---|
| 10.5 V | 1.8421 V | 2,286 | 571 | Fully discharged cut-off threshold |
| 11.5 V | 2.0175 V | 2,504 | 625 | Low battery warning |
| 12.0 V | 2.1053 V | 2,612 | 653 | Nominal resting (approx. 50% SOC) |
| 12.6 V | 2.2105 V | 2,743 | 685 | 100% resting charge (open circuit) |
| 13.2 V | 2.3158 V | 2,874 | 718 | Float / trickle maintenance charge |
| 13.8 V | 2.4211 V | 3,004 | 751 | Standard automotive alternator float |
| 14.4 V | 2.5263 V | 3,135 | 783 | Bulk / absorption charge cycle |
| 15.0 V | 2.6316 V | 3,266 | 816 | Equalization cycle / peak charging |
Even during a severe 18.0 V jump-start or load spike, the divider outputs 18.0 × (10 / 57) = 3.1579 V, keeping the microcontroller pin protected below 3.3 V.
Worked Example 2: Reading a 5 V Analog Sensor
Many sensors output a 0 V to 5.0 V analog signal:
- 5 V potentiometers and industrial analog joysticks.
- Ratiometric pressure transducers (0.5 V to 4.5 V output).
- Analog gas sensors (MQ series) and optical dust sensors.
- 5 V current sensors (such as the Allegro ACS712, outputting 2.5 V at zero current).
To interface a 5.0 V signal with a 3.3 V ADC, we need a scaling ratio:
Target Ratio: R2 / (R1 + R2) ≤ 3.3 / 5.0 = 0.660
Selecting the E12 Resistor Pair
From the standard E12 series, the pair R1 = 10 kΩ and R2 = 15 kΩ forms an ideal bridge:
- Total series resistance:
10,000 Ω + 15,000 Ω = 25,000 Ω(25 kΩ). - Divider ratio:
15 / (10 + 15) = 15 / 25 = 0.6000(an exact 3:5 ratio). - Output at 5.00 V:
5.00 V × 0.6000 = 3.0000 V. - Thevenin source resistance:
Rth = (10,000 × 15,000) / 25,000 = 6,000 Ω = 6.0 kΩ. This comfortably satisfies theRth ≤ 10 kΩADC requirement. - Sensor load current: At 5.0 V, the divider draws
5.0 V / 25,000 Ω = 0.200 mA(200 µA), which almost any active analog sensor or op-amp output stage can drive without distortion.
Why targeting 3.00 V is better than targeting 3.30 V: Many 5 V USB ports and wall adapters fluctuate between 4.75 V and 5.25 V (+5% tolerance). If you design a divider where 5.00 V yields exactly 3.30 V, a supply spike to 5.25 V produces 3.465 V, clipping your ADC reading at 4,095 counts and overdriving the pin. Designing for 3.00 V leaves a 0.30 V safety buffer: even at 5.25 V in, Vout = 5.25 × 0.60 = 3.150 V, remaining within the safe linear range.
5 V Sensor Mapping Table
Using R1 = 10 kΩ and R2 = 15 kΩ, here is the voltage and ADC response:
| Sensor Voltage (Vin) | Output Voltage (Vout) | 12-Bit ESP32 ADC (Counts) | 10-Bit Arduino ADC (Counts) |
|---|---|---|---|
| 0.0 V | 0.0000 V | 0 | 0 |
| 0.5 V | 0.3000 V | 372 | 93 |
| 1.0 V | 0.6000 V | 745 | 186 |
| 1.5 V | 0.9000 V | 1,117 | 279 |
| 2.0 V | 1.2000 V | 1,489 | 372 |
| 2.5 V | 1.5000 V | 1,861 | 465 |
| 3.0 V | 1.8000 V | 2,234 | 558 |
| 3.5 V | 2.1000 V | 2,606 | 651 |
| 4.0 V | 2.4000 V | 2,978 | 744 |
| 4.5 V | 2.7000 V | 3,350 | 837 |
| 5.0 V | 3.0000 V | 3,723 | 930 |
Hardware Best Practices: Filtering, Protection, and Code
To turn a basic breadboard divider into a reliable instrumentation circuit, apply three hardware design practices:
1. Add a 100 nF Bypass Capacitor Across R2
Place a 100 nF (0.1 µF) ceramic capacitor in parallel with R2, directly between the ADC pin and ground:
- Low-pass noise filtering: Combined with
Rth, the capacitor forms an RC filter that strips away high-frequency switching noise, alternator ripple, and motor EMI.- For the 12 V battery divider (
Rth = 8.25 kΩ,C = 100 nF), the cutoff frequency is:fc = 1 / (2π × 8,245.6 × 100e-9) ≈ 193 Hz - For the 5 V sensor divider (
Rth = 6.0 kΩ,C = 100 nF), the cutoff frequency is:fc = 1 / (2π × 6,000 × 100e-9) ≈ 265 Hz
- For the 12 V battery divider (
- ADC charge reservoir: When the internal SAR ADC closes its sample-and-hold sampling switch, it draws a momentary burst of current into its internal sampling capacitor. The external 100 nF capacitor supplies this charge instantly, eliminating transient voltage dips during sampling.
2. Built-in Fault Current Limiting
R1 doubles as a current-limiting safety resistor. If an overvoltage event occurs (such as accidentally connecting 24 V to the 12 V battery input), the current injected into the microcontroller's internal ESD protection diode is limited to:
I_fault = (24 V − 3.3 V) / 47,000 Ω = 0.44 mA
Because 0.44 mA is well below the 5 mA maximum continuous rating of internal ESD clamping diodes, R1 protects the silicon from destruction.
3. Complete Arduino Implementation Code
Here is a tested Arduino sketch demonstrating multi-sample averaging and software voltage reconstruction for the 12 V battery divider:
// 12V Battery Monitor using R1 = 47k, R2 = 10k on ESP32
const int ADC_PIN = 34; // ADC1 input pin (input-only)
const float R1 = 47000.0; // 47 k ohms (measure for 1% accuracy)
const float R2 = 10000.0; // 10 k ohms
const float VREF = 3.30; // Actual measured 3.3V rail voltage
const float DIVIDER_RATIO = (R1 + R2) / R2; // Scale factor = 5.70
void setup() {
Serial.begin(115200);
analogReadResolution(12); // 12-bit resolution (0-4095)
}
void loop() {
// Average 16 consecutive readings to filter electrical noise
long sum = 0;
for (int i = 0; i < 16; i++) {
sum += analogRead(ADC_PIN);
delay(2);
}
float avgRaw = sum / 16.0;
// Calculate voltage at the pin, then reconstruct battery voltage
float vOut = (avgRaw / 4095.0) * VREF;
float batteryVoltage = vOut * DIVIDER_RATIO;
Serial.print("ADC Raw: ");
Serial.print(avgRaw, 1);
Serial.print(" | Pin Voltage: ");
Serial.print(vOut, 3);
Serial.print(" V | Battery: ");
Serial.print(batteryVoltage, 2);
Serial.println(" V");
delay(1000);
}
Frequently Asked Questions
What happens if I connect a 5V sensor directly to an ESP32 or 3.3V Arduino analog pin?
The microcontroller's internal ESD clamping diodes will attempt to shunt the excess voltage above 3.3 V to the 3.3 V power rail. If the sensor can deliver more than a few milliamps of current, the clamping diodes will overheat and fail, permanently damaging the analog input multiplexer and GPIO pin. Even if the pin survives, any analog voltage above 3.3 V saturates the ADC at maximum counts (4,095 on 12-bit, 1,023 on 10-bit), making high readings impossible to distinguish.
Why can't I use a voltage divider to power a 3.3V sensor or board?
A voltage divider has poor voltage regulation because its output voltage depends directly on load current. As shown in the loading effect analysis above, connecting a 10 kΩ load across the bottom resistor of a 5 V divider causes the output to sag from 3.00 V down to 1.88 V (a 37.5% drop). Any variation in the sensor's operating current causes Vout to fluctuate erratically. To power 3.3 V electronics from 5 V or 12 V, use an active linear regulator (such as an AMS1117-3.3 or AP2112K) or a buck switching converter instead.
How do I choose between 10k/15k resistors and 1k/1.5k resistors for a 5V sensor?
Both pairs produce the identical unloaded 3:5 voltage ratio. However, a 1 kΩ / 1.5 kΩ divider draws 2.0 mA of idle current from the sensor output (5 V / 2.5 kΩ = 2 mA). Many analog sensors have high output impedance and cannot source 2 mA without their signal voltage drooping. The 10 kΩ / 15 kΩ pair draws only 0.2 mA (200 µA), which active sensor output buffers can drive cleanly while keeping Rth (6.0 kΩ) safely below the 10 kΩ ADC impedance limit.
Why does my ESP32 ADC read zero below 100 mV and flatten out above 3.1 V?
The integrated SAR ADCs on the ESP32 chip exhibit significant non-linearity near the bottom (0 V to ~0.1 V) and top (~3.1 V to 3.3 V) of their operating range. When configured with default 11 dB or 12 dB attenuation, the ADC response curve bends near both supply rails. This is why our 5 V sensor divider targets 3.00 V rather than 3.30 V: keeping peak signals around 3.00 V places the measurement entirely within the ESP32 ADC's linear region.
Why is a 100 nF capacitor recommended across the bottom resistor R2?
The internal SAR ADC inside microcontrollers samples signals by briefly closing an analog switch to charge a small internal sampling capacitor (typically 5 pF to 15 pF). Without an external capacitor, this sudden current draw must come through the divider resistors, causing a momentary voltage dip during sampling. An external 100 nF ceramic capacitor acts as a low-impedance reservoir that holds Vout stable during the sample aperture, while filtering high-frequency electrical noise.
Which ESP32 analog pins should I choose for a voltage divider?
Always use pins attached to ADC1: GPIO 32, 33, 34, 35, 36, and 39. Never use ADC2 pins (GPIO 0, 2, 4, 12–15, 25–27) if your project uses Wi-Fi or Bluetooth, because the wireless drivers take exclusive control of ADC2. GPIO 34, 35, 36, and 39 are dedicated inputs without internal pull-up or pull-down circuitry, making them the cleanest pins for voltage dividers. Use the Arduino pin planner to check pin assignments.
What resistor tolerance should I use for voltage dividers?
Always use 1% metal film resistors rather than 5% carbon film resistors. With 5% resistors, the combined worst-case ratio error between R1 and R2 can exceed ±8%, shifting a 12.0 V battery calculation by nearly 1.0 V. With standard 1% resistors, the worst-case error drops to ±1.66% (less than ±0.2 V at 12 V), which can be calibrated out in firmware.
Do I need an op-amp buffer with a voltage divider?
You do not need an op-amp buffer if the Thevenin equivalent resistance of your divider (Rth = R1 ∥ R2) is 10 kΩ or less, which both worked examples in this guide achieve (8.25 kΩ and 6.0 kΩ). You only need a rail-to-rail unity-gain op-amp buffer (voltage follower) if you increase the resistor values into the megaohm range (such as 1 MΩ / 220 kΩ) to achieve microamp-level battery sleep currents.
What happens if the common ground wire between the battery and Arduino is disconnected?
If the ground wire breaks, the microcontroller ADC has no return path to the battery's negative terminal. The ADC pin will float, picking up electromagnetic interference from nearby AC wiring and switching power supplies, and output erratic, meaningless readings. In some configurations where current finds an alternate ground return through a USB cable or sensor shield, ground loops can inject voltage offsets into your measurement.
How do I calibrate a voltage divider in Arduino code?
Rather than assuming ideal mathematical resistance values, perform a two-point calibration. Connect your divider to a stable DC voltage, measure the true battery voltage with a calibrated digital multimeter, and record the raw ADC reading. Compute the exact scale factor in code: float calibrationFactor = measuredMultimeterVoltage / measuredPinVoltage;. This single software adjustment compensates for resistor tolerance, ADC offset, and power supply rail errors simultaneously.
For a related walkthrough, read How to Plan a Perfboard Layout Before Soldering.