How-to · Intermediate · 4 min read
3.3 V vs 5 V Logic
How to Level Shift Safely
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
You need level shifting when a 5 V device sends signals to a 3.3 V board such as an ESP32 or Raspberry Pi Pico, because 5 V on their pins can damage them. For one-way signals a two-resistor voltage divider works. For I2C use a BSS138 bidirectional shifter. For fast one-way data such as WS2812B LEDs, use a 74AHCT125 buffer.
Key specs at a glance
- 5 V boards
- Arduino Uno, Mega, Nano (classic)
- 3.3 V boards
- ESP32, ESP8266, Raspberry Pi Pico, Raspberry Pi 4 and 5
- Divider for 5 V to 3.3 V
- 1 kΩ (series) + 2 kΩ (to ground) gives 3.33 V
- BSS138 shifter
- Bidirectional, good for I2C up to 400 kHz
- TXS0108E
- 8-channel auto-direction, push-pull signals
- 74AHCT125
- Fast one-way 3.3 V to 5 V buffer
Why 3.3 V and 5 V logic do not always mix
A digital pin sees "high" or "low" by comparing the voltage to thresholds set by its own supply. Two problems appear when you mix supply voltages:
exceeds the absolute maximum (about 3.6 V on ESP32 and RP2040) and can damage the pin over time or instantly.
usually safe, but may not count as "high". An ATmega328P needs at least 0.6 x VCC = 3.0 V, so 3.3 V works with little margin. A WS2812B needs 0.7 x 5 V = 3.5 V, so 3.3 V is out of spec and may glitch.
Which level-shifting method should you use?
| Method | Direction | Speed | Best for | Avoid for |
|---|---|---|---|---|
| Voltage divider (2 resistors) | 5 V to 3.3 V only | Up to a few hundred kHz | HC-SR04 echo, UART RX, 5 V sensor outputs | Signals that go both ways, 3.3 V to 5 V |
| BSS138 MOSFET module | Bidirectional | Up to about 400 kHz | I2C, slow UART, buttons | Fast SPI, LED data |
| TXS0108E module | Bidirectional, auto-sensing | Up to tens of MHz push-pull | SPI, parallel buses | I2C with strong pull-ups, long wires |
| 74AHCT125 / 74HCT245 | 3.3 V to 5 V only | Very fast | WS2812B data, 5 V shift registers | 5 V to 3.3 V |
| Do nothing | 3.3 V out to 5 V in | Any | Many TTL inputs that accept 2 V as high | Inputs that need 0.7 x VCC (WS2812B, CMOS) |
- Voltage divider (2 resistors)
- Direction:
- 5 V to 3.3 V only
- Speed:
- Up to a few hundred kHz
- Best for:
- HC-SR04 echo, UART RX, 5 V sensor outputs
- Avoid for:
- Signals that go both ways, 3.3 V to 5 V
- BSS138 MOSFET module
- Direction:
- Bidirectional
- Speed:
- Up to about 400 kHz
- Best for:
- I2C, slow UART, buttons
- Avoid for:
- Fast SPI, LED data
- TXS0108E module
- Direction:
- Bidirectional, auto-sensing
- Speed:
- Up to tens of MHz push-pull
- Best for:
- SPI, parallel buses
- Avoid for:
- I2C with strong pull-ups, long wires
- 74AHCT125 / 74HCT245
- Direction:
- 3.3 V to 5 V only
- Speed:
- Very fast
- Best for:
- WS2812B data, 5 V shift registers
- Avoid for:
- 5 V to 3.3 V
- Do nothing
- Direction:
- 3.3 V out to 5 V in
- Speed:
- Any
- Best for:
- Many TTL inputs that accept 2 V as high
- Avoid for:
- Inputs that need 0.7 x VCC (WS2812B, CMOS)
Build a 5 V to 3.3 V voltage divider
Connect the 5 V signal to a 1 kΩ resistor, then from the far end of that resistor connect a 2 kΩ resistor to ground. Take your 3.3 V signal from the joint between them: 5 V x 2 / (1 + 2) = 3.33 V. A 2.2 kΩ and 3.3 kΩ pair (giving 3.0 V) also works. Use resistors in the low kilohm range so the signal edges stay sharp.
Wire a BSS138 bidirectional level shifter
- 1Connect HV to 5 V and LV to 3.3 V. Both supplies must be present.
- 2Connect GND on both sides to a common ground.
- 3Connect the 5 V device's signals to HV1 to HV4 and the 3.3 V board's matching signals to LV1 to LV4.
- 4For I2C, wire SDA through one channel and SCL through another. The module's onboard 10 kΩ resistors act as pull-ups on each side.
Which common modules need a level shifter with an ESP32 or Pico?
| Module | Needs shifting? | Why |
|---|---|---|
| HC-SR04 ultrasonic | Yes, on ECHO | Echo output is 5 V. Or buy the 3.3 V HC-SR04P. |
| PIR HC-SR501 | No | Output is already 3.3 V. |
| WS2812B LED strip | Usually | Data input needs 3.5 V. Often works without, but not reliably. |
| 16x2 LCD with I2C backpack | Recommended | Backpack pull-ups go to 5 V. |
| 5 V relay module | Sometimes | Some modules will not switch on at 3.3 V input. |
| DHT22 | No | Runs on 3.3 V directly. |
| SSD1306 OLED | No | 3.3 V native, modules accept 3.3 to 5 V. |
- HC-SR04 ultrasonic
- Needs shifting?:
- Yes, on ECHO
- Why:
- Echo output is 5 V. Or buy the 3.3 V HC-SR04P.
- PIR HC-SR501
- Needs shifting?:
- No
- Why:
- Output is already 3.3 V.
- WS2812B LED strip
- Needs shifting?:
- Usually
- Why:
- Data input needs 3.5 V. Often works without, but not reliably.
- 16x2 LCD with I2C backpack
- Needs shifting?:
- Recommended
- Why:
- Backpack pull-ups go to 5 V.
- 5 V relay module
- Needs shifting?:
- Sometimes
- Why:
- Some modules will not switch on at 3.3 V input.
- DHT22
- Needs shifting?:
- No
- Why:
- Runs on 3.3 V directly.
- SSD1306 OLED
- Needs shifting?:
- No
- Why:
- 3.3 V native, modules accept 3.3 to 5 V.
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Using a voltage divider on a bidirectional line such as I2C SDA.
- Using a TXS0108E on an I2C bus with 4.7 kΩ pull-ups; its auto-direction sensing misbehaves. Use a BSS138 module or PCA9306 instead.
- Forgetting to power both the HV and LV sides of a shifter module.
- Not connecting the grounds of both boards together.
- Assuming a 3.3 V board is safe because it worked once; 5 V damage can be gradual.
Frequently asked questions
Is ESP32 5 V tolerant?
No. ESP32 GPIOs accept up to 3.6 V. Shift any 5 V signal down before connecting it.
Can I connect a 3.3 V output to an Arduino Uno input?
Usually yes. The Uno reads anything above about 3.0 V as high, so 3.3 V works, though with little noise margin. It is never harmful.
Which level shifter is best for I2C?
A BSS138-based bidirectional module or a dedicated I2C translator such as the PCA9306. They handle the open-drain lines correctly.
Do I need a level shifter for WS2812B with an ESP32?
For reliable results, yes. Use a 74AHCT125 powered from 5 V, or power the first LED slightly lower through a diode so 3.3 V meets its threshold.
Can I use a voltage divider instead of a level shifter?
For one-way signals from 5 V to 3.3 V, yes. It cannot raise 3.3 V to 5 V and does not work for bidirectional lines.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 2 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
- BSS138 datasheet (onsemi)
- TXS0108E datasheet (Texas Instruments)
- SN74AHCT125 datasheet (Texas Instruments)
- ESP32 Series Datasheet (Espressif Systems)
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



