Home / Learn / Electronics basics

3.3 V and 5 V logic: connecting them safely with level shifters

New to this? Read from the top. Already know the basics? Jump to Going deeper for intermediate and advanced detail.

Logic levels: a 5 volt Arduino input needs at least 3.0 volts to read high, so a 3.3 volt signal only just passes. A 5 volt signal into a 3.3 volt Pico or ESP32 pin can damage it, so a level shifter sits between them
Beginner

An Arduino Uno works at 5 V. A Raspberry Pi, a Raspberry Pi Pico and an ESP32 work at 3.3 V. Connect them together carelessly and, at best, signals aren't read reliably. At worst, the 3.3 V board is damaged. This guide explains why, and how to connect them properly.

What logic levels mean

A digital input doesn't switch at a single voltage. The datasheet gives two thresholds:

  • VIH: the lowest voltage guaranteed to read as HIGH.
  • VIL: the highest voltage guaranteed to read as LOW.

In between is a no-man's-land where the reading is unreliable. For an Uno's ATmega328P running at 5 V, the datasheet gives VIH as 0.6 × VCC = 3.0 V and VIL as 0.3 × VCC = 1.5 V.

The two directions

5 V into a 3.3 V input: the dangerous one

The RP2040 on the Pico, the ESP32 and the Raspberry Pi's processor all have absolute maximum input ratings only a little above their 3.3 V supply. A 5 V signal pushes current through the pin's protection diodes and can damage the chip, sometimes immediately, sometimes slowly. Never connect a 5 V output directly to these inputs.

The Pico 2's RP2350 datasheet describes its GPIO as tolerant of 5 V under specific conditions, including the chip being powered. Unless you've read and met those conditions, treat 3.3 V as the limit on every 3.3 V board.

3.3 V into a 5 V input: usually works, but marginal

A 3.3 V output high is just above the Uno's 3.0 V VIH, so it usually reads correctly, but with very little margin for noise or long wires. Some 5 V parts need more. WS2812B addressable LEDs, for example, want 0.7 × VDD = 3.5 V at 5 V, so a 3.3 V data signal is below spec and may give flickering or wrong colours.

Three ways to level-shift

1. Voltage divider (5 V to 3.3 V, one direction)

Two resistors scale the 5 V signal down. With 1 kΩ from the 5 V output to the 3.3 V input, and 2 kΩ from the input to ground, the input sees 5 × 2 ÷ 3 = 3.33 V. Simple and cheap, but it only works one way, and the resistors slow fast edges, so it's fine for a UART receive line or a sensor output but not for high-speed SPI. Our voltage divider calculator finds other pairs.

2. MOSFET level shifter (bidirectional)

Small modules with a BSS138 MOSFET and two pull-up resistors per channel shift in both directions. They're the standard answer for I²C, whose lines are open-drain and bidirectional. They're limited in speed by the pull-up resistors, so they suit I²C and slow signals rather than fast SPI.

3. A logic buffer chip

For fast, one-way signals, use a buffer. A 74AHCT125 or 74HCT245 powered from 5 V accepts a 3.3 V input as HIGH (the "T" means TTL thresholds, with VIH of 2.0 V) and outputs a clean 5 V. That's the usual fix for driving WS2812B LEDs from a 3.3 V board. Going the other way, a 74LVC buffer powered from 3.3 V accepts 5 V on its inputs and outputs 3.3 V.

Quick reference

SignalDirectionGood choice
UART (serial)5 V TX → 3.3 V RXVoltage divider on that line; 3.3 V TX → 5 V RX usually direct
I²CBothBSS138 MOSFET shifter, or pull-ups to 3.3 V only if every 5 V device accepts 3.3 V as HIGH
SPIMixed, fastBuffer chips (74AHCT125 / 74LVC125)
WS2812B data3.3 V → 5 V74AHCT125 powered from 5 V
Button or slow sensor5 V → 3.3 VVoltage divider, or power the sensor from 3.3 V if it allows

Power pins: a common mistake

Many 3.3 V boards have a 5 V pin (VBUS or VIN) as well as a 3V3 pin. The 5 V pin feeds the board's regulator. Connecting 5 V to the 3V3 pin bypasses the regulator and can destroy the board. Check the board's pinout first: Pico, ESP32, Raspberry Pi.

Analogue inputs have the same limit: a 3.3 V board's ADC reads up to its reference voltage, so a 5 V sensor output needs dividing down. See how ADCs work.

Intermediate and advanced

Going deeper

Noise margins

The noise margin is the gap between what a driver guarantees and what a receiver needs: NMH = VOH(min) − VIH(min) and NML = VIL(max) − VOL(max). A 3.3 V CMOS output driving a 5 V ATmega328P input has a high-side margin of only a couple of hundred millivolts once the output's own drop under load is included, against more than a volt for 5 V to 5 V. That's why the connection works on a bench and fails with long wires near a motor.

How the BSS138 shifter works

The MOSFET's gate is tied to the low-voltage supply and its source to the low side. When the low side pulls down, the gate-source voltage rises, the MOSFET turns on and pulls the high side down too. When the high side pulls down, current flows through the MOSFET's body diode until the source falls far enough for the MOSFET to turn on. When nothing pulls down, each side's pull-up takes it high and the MOSFET is off. NXP's application note AN10441 describes the circuit for I²C.

Injection current through protection diodes

A series resistor of a few kilohms limits the current a 5 V signal can push through a 3.3 V pin's clamp diode, and some datasheets specify a maximum injection current. That injected current also flows into the 3.3 V supply and can raise it if the board draws little current. It's a fragile fix: use a proper divider or buffer.

Open-drain outputs

An open-drain output can only pull low. With a pull-up resistor to the receiver's supply, it naturally produces the receiver's logic level, which is why I²C and many interrupt lines shift levels so easily: just make sure the pull-ups go to the lower voltage when any device on the bus can't tolerate the higher one.

Sources

The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.