Voltage Level Shifting
Introduction
Your ESP32 speaks 3.3 V logic. Many Arduino shields and sensors speak 5 V. Connect them directly and you risk damaged GPIO pins or garbage readings — the signal is too high or the voltage thresholds do not match.
Level shifting translates one logic voltage to another so both sides understand HIGH and LOW safely. This article covers when you need it, simple methods, and off-the-shelf parts.
Pair with Basics of electronics and Hardware architecture.
Logic levels in one glance
| Voltage | Typical meaning on 3.3 V MCU |
|---|---|
| 0 V – ~0.8 V | LOW (0) |
| ~2.0 V – 3.3 V | HIGH (1) |
A 5 V HIGH (~5 V) is fine for a 5 V chip but too high for a 3.3 V input pin. A 3.3 V HIGH might not reach the minimum HIGH threshold of a 5 V input (~3.5 V on some parts).
In plain terms
Two friends speak different "volume levels." A level shifter is the translator so neither shouts too loud nor whispers too quietly.
When you need a shifter
| Situation | Risk without shifter |
|---|---|
| 5 V sensor → 3.3 V MCU input | Damaged pin or wrong readings |
| 3.3 V MCU → 5 V-only peripheral | Peripheral never sees reliable HIGH |
| I²C bus mixing 3.3 V and 5 V devices | Bus stuck, NACK errors |
| UART between 5 V USB adapter and 3.3 V MCU | Often OK on RX if adapter is open-drain — verify |
Always check the datasheet for VIH, VIL, and "5 V tolerant" on each pin.
Methods
Voltage divider (3.3 V ← 5 V only)
Two resistors drop 5 V to ~3.3 V on an input line. Cheap for one slow GPIO — not for I²C or fast buses (weak edges, no drive back up).
MOSFET bidirectional shifter (common on breakout boards)
Modules like TXS0108E or classic BSS138 circuits shift both directions on I²C, SPI, UART. Connect LV to 3.3 V, HV to 5 V, same GND.
Dedicated I²C level shifter
Boards labeled "I²C logic level converter" — four channels, plug between bus segments.
"5 V tolerant" pins
Some STM32 pins accept 5 V on input — still use correct levels on outputs to the other device.
I²C reminder
I²C uses open-drain with pull-up resistors to each side's voltage. A proper shifter passes SDA/SCL with separate pull-ups on 3.3 V and 5 V segments. See Serial communication protocols.
Videos — other ways to learn
Level shifting overview
Voltage Level Shifting Tutorial
3.3 V to 5 V
Logic levels explained
Relevant topics
- Basics of electronics
- Reading datasheets
- Serial communication protocols
- Hardware architecture
- Microcontrollers overview
Starting points
- List every wire between MCU and peripheral; note each side's I/O voltage.
- Buy or borrow a 4-channel logic level module before mixing 5 V sensors with ESP32.
- Measure with a multimeter: idle HIGH on SDA should match the pull-up rail on that segment.
- Sketch level shifters on your wiring diagram — coaches look for this on mixed-voltage boards.
Focus points
- Never assume "it worked once" means the pin is safe long-term.
- Common ground between 3.3 V and 5 V domains — shifters need shared GND.
- Divider is one-way — do not use it on lines the MCU must drive high at 5 V.
- Document shifters in pin map and BOM like any other IC.
Key points
- 3.3 V and 5 V logic are not directly interchangeable on all pins.
- Use bidirectional shifters for I²C and most buses; dividers only for slow 5 V → 3.3 V inputs.
- Check datasheets for tolerant pins and threshold voltages.
- Level shifting belongs in hardware architecture from day one, not after smoke.