RisalDash RisalDash

Guide · Hardware · Levels

3.3V ↔ 5V: how to not fry your ESP32

Half the sensors and modules in the Arduino world run at 5 V. The ESP32, ESP8266 and most modern chips run at 3.3 V. Wire a 5 V output straight into a 3.3 V pin and you can damage it on the spot. Here’s why they don’t mix, when you can skip the shifter, and three clean ways to bridge them.

Level shifting3.3V / 5VBSS138ESP32ArduinoHardware

This is the “how is a level read?” question from the bus fundamentals made painfully practical — and it’s the single most common way beginners kill an ESP32 pin.

Why 3.3V and 5V don’t just work together

Two separate problems, one in each direction:

First — do you even need a shifter?

Check before adding parts:

Method 1 — Resistor divider (one direction)

For a single 5 V output going into a 3.3 V input — a sensor’s TX into the ESP32’s RX — two resistors are all you need:

5V TX ──[ R1 = 1kΩ ]──┬──> 3V3 RX (safe)
                      │
                   [ R2 = 2kΩ ]
                      │
                     GND

Vout = 5V × R2 / (R1 + R2) = 5 × 2 / 33.3 V
// One direction only (5V -> 3V3). Do NOT use on an I²C SDA line.
HC-SR04 wired to an ESP32 with a 1 kΩ / 2 kΩ resistor divider on the 5 V Echo line to protect the 3.3 V input pin
The divider in practice: an HC-SR04's 5 V Echo dropped to a safe 3.3 V — 1 kΩ in series, 2 kΩ to ground. Built in BoardLab.

Cheap and reliable, but one-way only and a bit slow (the resistance plus wire capacitance rounds fast edges). Never put it on a bidirectional line like I²C SDA.

Method 2 — BSS138 MOSFET (bidirectional, the go-to)

The classic 4-channel “logic level converter” board is a handful of BSS138 MOSFETs. Each channel shifts both directions automatically, which is exactly what I²C needs (both SDA and SCL are bidirectional). Wire the high side to 5 V, the low side to 3.3 V, share ground, and pass your signals through. It’s a couple of dollars and solves 90% of cases.

Method 3 — Dedicated shifter ICs (many/fast lines)

For an 8-bit parallel bus or fast SPI, use a purpose-built IC: TXS0108E (auto-direction, open-drain friendly) or TXB0104 (push-pull, faster, not for I²C). They handle higher speeds and more channels cleanly than a divider or a single MOSFET.

Gotchas

Rule of thumb: one 5 V signal in → a divider. A bidirectional bus (I²C) → a BSS138 board. Many or fast lines → a proper shifter IC. Get it right once and your ESP32 pins live a long life.

Fighting a silent I²C bus? Level mismatch is one of the usual suspects.