WiringLevel shifting

Connecting a 5V Sensor to a 3.3V Board Safely

A 5V sensor and a 3.3V board is the single most common way people quietly damage a Raspberry Pi. There are four sensible ways to bridge the gap, and picking the wrong one for the job is how I2C buses end up mysteriously broken.

Ad space

First: which direction is the problem?

This is the part that most explanations skip, and it decides everything.

A 5V signal going into a 3.3V input is the dangerous direction. The Raspberry Pi's GPIO pins are 3.3V and are not 5V tolerant. Feeding 5V in stresses the input every time the signal goes high, and will degrade or destroy the pin.

A 3.3V signal going into a 5V input is usually fine — but check. Many 5V parts treat anything above roughly 2V as a valid "high", so 3.3V is read correctly. Some don't, and the symptom is a device that never responds rather than a damaged one. The datasheet figure to look for is VIH (input high voltage): if it's below 3.3V, you're fine.

Worked example: the HC-SR04 ultrasonic sensor needs both directions considered. Its Trig pin is an input, so driving it from a 3.3V Pi output is generally fine. Its Echo pin is a 5V output, and that one absolutely needs handling before it touches a GPIO input.

Option 1: A resistor voltage divider

Best for: a single, slow, one-directional signal — like that HC-SR04 Echo pin.

Two resistors in series between the 5V signal and ground, with your 3.3V board connected to the junction between them. A 1kΩ and 2kΩ pair gives you roughly 3.3V from a 5V input.

Cheap, uses parts you already own, and perfectly adequate for what it's designed for.

Do not use a voltage divider on I2C. This is the mistake that sends people round in circles. I2C lines are bidirectional and rely on devices pulling the line low against a pull-up resistor. A divider interferes with that mechanism and fights the bus's own pull-ups. It may appear to work, then fail intermittently or as soon as you add a second device — which is a far worse problem to debug than a clean failure.

Option 2: A MOSFET bidirectional level shifter

Best for: I2C, and anything that needs to work in both directions.

These are the small four-channel boards built around BSS138 MOSFETs, sold everywhere for very little. Each channel handles traffic in either direction automatically, which is exactly what I2C needs.

This is the default answer for most hobby situations. If you're unsure which option to buy, buy a couple of these — they cost very little and solve the majority of cases.

Their limitation is speed: the MOSFET-plus-pull-up arrangement is fine for I2C and slower signals, but not for fast push-pull signals like SPI at high clock rates.

Option 3: A dedicated level-shifter IC

Best for: faster signals, or when you need several channels reliably.

Purpose-built translator chips (the TXB and TXS families are common on hobby breakouts) handle higher speeds than the simple MOSFET boards. Worth knowing that they aren't interchangeable: some variants are intended for push-pull signals like SPI, others for open-drain buses like I2C. Match the part to the bus rather than assuming any shifter does any job.

Ad space

Option 4: Sidestep it entirely

Best for: almost everyone, most of the time.

The cheapest level shifter is the one you don't need. Before buying anything, check whether:

Reading the module's documentation for two minutes genuinely beats an evening of debugging.

Choosing quickly

SituationUse
One slow 5V output into a 3.3V input (e.g. HC-SR04 Echo)Voltage divider
Any I2C device at a different voltageMOSFET bidirectional shifter
Fast SPI, or several channelsDedicated shifter IC matched to the bus type
3.3V output into a 5V inputUsually nothing — check VIH in the datasheet
Module marked "3–5V"Nothing. Wire it directly.

The habit worth building

Before wiring any new module, find two numbers in its documentation: its supply voltage and its signal (logic) voltage. They are frequently different, and assuming they're the same is the root of most of these problems. Reading a datasheet covers where to find them.

If you're planning a multi-sensor build, run it through PinTinker first — it flags known voltage problems like the HC-SR04's Echo pin as you add each component.

Gear that helps

A 4-channel bidirectional logic level converter covers the majority of cases and costs very little — worth keeping a spare in the drawer. An assorted resistor kit covers the divider approach.