What is a Voltage Divider
A voltage divider uses two resistors to reduce a voltage. It is the simplest way to convert a 5V sensor signal to 3.3V for ESP32 or Raspberry Pi.
The Formula
Vout = Vin × R2 / (R1 + R2)
Vin ──┬── R1 ──┬── Vout
│ │
│ R2
│ │
GND ──┴────────┴──
Quick Reference: 5V → 3.3V
| R1 | R2 | Vout (Vin=5V) | Use Case |
|---|---|---|---|
| 1kΩ | 2kΩ | 3.33V | Common values |
| 2.2kΩ | 3.9kΩ | 3.20V | Slight margin for safety |
| 10kΩ | 20kΩ | 3.33V | Low current draw |
Arduino Example: Read 5V Sensor on ESP32
// 5V sensor output → R1 (1k) → ESP32 GPIO → R2 (2k) → GND
const int sensorPin = 34; // ADC pin
void setup() { Serial.begin(115200); }
void loop() {
int raw = analogRead(sensorPin);
float voltage = raw * 5.0 / 4095; // ESP32 ADC is 0-4095
Serial.println(voltage);
delay(500);
}
When NOT to Use a Voltage Divider
- Power supply — resistors waste power as heat. Use a voltage regulator (buck/boost).
- High-speed signals — resistors add RC delay, degrading I2C/SPI above ~400 kHz. Use a dedicated level shifter (e.g., TXS0108E).
- Precision analog — resistor tolerance (±5%) affects accuracy. Use 1% resistors or an op-amp buffer.