Bidirectional I²C level shifter (BSS138)
A 3.3 V ESP32 and a 5 V I²C device share a wire that either side may pull low. One BSS138 MOSFET per line does it: when the 3.3 V side pulls low, the FET turns on and pulls the 5 V side low; when the 5 V side pulls low, the body diode drags the 3.3 V side down until the FET turns on too. Neither side ever sees the other’s high voltage.

Open this lesson in the labFree, in your browser, no account needed.
How it works
LV low: V_GS = 3.3 V, the FET is on (≈ 3 Ω) and the 5 V line falls to 0.5 mA × 3 Ω ≈ 2 mV above the switch.
HV low: the body diode pulls the source down to about 0.6 V, which gives the gate 2.7 V of drive, so the channel turns on and the low side follows to near 0 V.
Idle: V_GS = 0, the FET is off, each side sits at its own pull-up.
Try it on the bench
- Open both switches: each line returns to its own supply.
Parts on the bench
- 2 × Bench power supply
- BSS138 N-MOSFET
- 2 × Resistor
- 2 × Toggle switch
In the course
Embedded & IoT, module “Buses and sensors”.