Logic levels, 3.3 V and 5 V
A digital wire does not carry a 1 or a 0. It carries a voltage, and the chip at the far end has an opinion about what counts. Those opinions differ between 3.3 V and 5 V parts, and the mismatch damages pins quietly rather than loudly.
Drag the incoming voltage and switch the receiving chip. Note that 3.3 V is fine going into a 5 V part, and 5 V is not fine coming back.
Three bands, not two
Every input has a voltage below which it is definitely 0, a voltage above which it is definitely 1, and a gap in the middle where the chip is not told what to do. In that gap it will read one value, then the other, and the input stage draws far more current than usual while it oscillates.
For a 3.3 V ESP32 the boundaries are roughly 0.25 and 0.75 of the supply: below 0.83 V is a 0, above 2.48 V is a 1. For a 5 V AVR they are about 1.5 V and 3.0 V.
The asymmetry that catches people
3.3 V out → 5 V in usually works. 3.3 V clears the 5 V chip's
3.0 V threshold, with almost no margin.
5 V out → 3.3 V in is a defect. The absolute maximum on an
ESP32 pin is about 3.6 V. Above that, current flows through the pin's
protection diode into the 3.3 V rail.
The second one rarely fails immediately, which is what makes it dangerous. The protection diode survives small currents, the project works, and the pin dies weeks later — or the whole rail gets dragged up and something else fails instead.
Fixing it, cheapest first
A voltage divider. Two resistors bring a 5 V signal down to 3.3 V. Costs two parts, works for anything slow — a button, a UART at 115200, a one-wire sensor. Too slow for fast SPI once the resistors are large. See the voltage divider.
A dedicated level shifter. A four- or eight-channel bidirectional module, a couple of dollars, and the right answer for I2C because both directions need shifting on the same wire.
Check whether you need one at all. Many "5 V" sensor modules run happily on 3.3 V, and many 5 V-powered modules already output 3.3 V logic. Power the module from 3.3 V where its datasheet allows, and the problem disappears.
The one-minute check before you connect
- What voltage is the sending chip's supply? That is what its output will be.
- What is the receiving chip's absolute maximum on an input pin?
- If the first number is bigger than the second, add a divider or a shifter.
Do this once per new module and you will never lose a pin to it.
Edit this page — content/fundamentals/electricity/logic-levels-3v3-and-5v.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.