Plenty of cheap modules were designed for the 5 V Arduino Uno: ultrasonic distance sensors, LED strips, LCD backpacks, relay boards. The ESP32 runs its I/O at 3.3 V. Sometimes the two talk to each other without trouble, sometimes a 5 V output slowly damages a GPIO, and sometimes the 5 V side simply never sees a valid high. Which one you get depends on the direction of the signal and on a few numbers from the datasheets. This guide goes through those numbers and the four common fixes: a resistor divider, a buffer chip, a MOSFET module and an auto-direction translator.
The numbers that decide it
The ESP32 datasheet (DC characteristics at 3.3 V, 25 °C) gives these limits for a digital pin:
| Parameter | Value | At VDD = 3.3 V |
|---|---|---|
| High-level input voltage (VIH) | 0.75 × VDD to VDD + 0.3 V | 2.475 V to 3.6 V |
| Low-level input voltage (VIL) | -0.3 V to 0.25 × VDD | up to 0.825 V |
| High-level output voltage (VOH) | at least 0.8 × VDD | at least 2.64 V |
Two conclusions follow. A 5 V signal is above the 3.6 V input limit, so it must be brought down before it reaches the pin. In the other direction, the ESP32 only guarantees 2.64 V as a high output, and whether that is enough depends entirely on the input it drives.
Before you buy anything, check what the module actually puts on its pins. "5 V module" often describes the supply, not the logic. Some boards have their own regulator and 3.3 V logic, and newer versions of old designs can run from 3.3 V. The HC-SR04P ultrasonic sensor, for example, accepts 2.8 to 5.5 V, so powered from 3.3 V it needs no level shifting at all. If the module works at 3.3 V, power it from 3.3 V and skip the rest of this article.
5 V output into an ESP32 input: a resistor divider
The classic case is the original HC-SR04. It needs 5 V, its trigger input accepts a 3.3 V pulse, but its echo output goes up to 5 V. One input line, one direction, a slow signal: two resistors are enough.
The output voltage of a divider is Vin × R2 / (R1 + R2), where R1 goes from the 5 V signal to the GPIO and R2 from the GPIO to ground:
- 1 kΩ and 2 kΩ: 5 × 2 / 3 = 3.33 V. This is the combination most wiring guides show.
- 680 Ω and 1 kΩ: 5 × 1 / 1.68 = about 2.98 V, which the Toit documentation suggests for the HC-SR04.
- two equal resistors: 2.5 V. Toit warns that this is too close to the ESP32's 2.475 V minimum for a high.
Aim for roughly 3 to 3.3 V. Lower and you lose margin on a guaranteed high; higher and you approach the 3.6 V limit when the 5 V rail runs a little high.
A divider has costs. It draws current all the time the signal is high (5 V across 3 kΩ is about 1.7 mA), it works in one direction only, and it is slow with large resistors, because the resistors and the capacitance of the pin and wiring form an RC filter. Keep the values in the low kilohm range for anything faster than an echo pulse or a push button. For a UART at a few hundred kilobaud or SPI, use a proper chip instead.
Analog signals are a separate case
Level shifter modules are purely digital. SparkFun says so plainly in the guide to its bi-directional converter: they cannot map an analog voltage from one range to another. For a sensor with a 0-5 V analog output, use a divider and size it for the ADC, not for the digital thresholds. The ESP32 datasheet notes that at the highest attenuation the ADC is less accurate above a reading of about 2450 mV. Halving 5 V gives 2.5 V, which is already over that line, so pick a ratio that keeps the sensor's maximum output below it.
3.3 V output into a 5 V input: check the input's VIH
Many 5 V chips accept 3.3 V as a high without help. Others do not. The difference is the input threshold.
- TTL-compatible inputs. The TI SN74AHCT125 datasheet specifies a VIH of 2 V at a 5 V supply. The ESP32's guaranteed 2.64 V is comfortably above it.
- 5 V CMOS inputs. The SN74HC125, the plain HC version of the same buffer, needs at least 3.15 V for a high at a 4.5 V supply. The WS2812B LED datasheet gives VIH as 0.7 × VDD, which at 5 V is 3.5 V. A 3.3 V signal is below both.
The second group often "works" on the bench and then fails with a longer cable, a warmer room or a different batch. When the datasheet threshold is above what the ESP32 guarantees, treat it as not working.
The clean fix for one-way signals is a buffer with TTL inputs powered from 5 V, such as the 74AHCT125 or 74HCT125. It reads the 3.3 V signal against a 2 V threshold and drives a full 5 V output. This is the circuit the WLED project shows for addressable LED strips, with the output enable pins and unused inputs tied to ground. The same chip works for any one-way, push-pull signal: a data line, a chip select, a clock.
Bidirectional lines: I²C and the BSS138 module
I²C is the case where a divider or a buffer cannot help. SDA carries data both ways, and SCL can be held low by the target device (clock stretching), so both lines are effectively bidirectional and open-drain.
The usual answer is the small MOSFET board sold as a "bi-directional logic level converter", based on SparkFun's design. Each channel is one N-channel MOSFET (typically a BSS138) with a pull-up resistor on each side. The circuit comes from the NXP application note AN10441, now published by Nexperia:
- the gate goes to the lower supply (3.3 V), the source to the 3.3 V side of the line and the drain to the 5 V side;
- when nobody pulls the line low, each side is pulled up to its own supply, so the ESP32 sees 3.3 V and the 5 V device sees 5 V;
- when either side pulls the line low, the MOSFET (or its body diode, at first) drags the other side low too.
The application note specifies the circuit for Standard-mode (up to 100 kbit/s) and Fast-mode (up to 400 kbit/s) I²C, not for the faster Hs-mode. As a bonus, it isolates a powered-down section from the rest of the bus and protects the low-voltage side from spikes on the high-voltage side.
Wiring the module correctly takes four supply connections: HV to 5 V, LV to 3.3 V and both grounds. SparkFun's guide stresses that both references must be supplied and that HV must be higher than LV. Any of the four channels can carry any signal, so the spare channels can also handle a UART or a GPIO.
One I²C trap is worth checking before you add anything. A 5 V module may already have pull-up resistors to 5 V on SDA and SCL. Connect it straight to the ESP32 and those resistors put 5 V on the GPIO, even though the ESP32 itself only pulls the lines low. AN10441 makes the same point in general form: devices of different voltages can share one bus with pull-ups to the higher supply only if the lower-voltage devices are 5 V tolerant. The ESP32 is not, so either remove those pull-ups or put the module behind a level shifter.
Auto-direction translators: TXS0108E and TXB0108
Eight-channel boards with a TXS0108E or TXB0108 are cheap and look like a universal answer. They are not interchangeable, and both have rules that cheap module listings leave out.
TXB0108 is for push-pull signals only. TI's datasheet says its output drivers have low DC drive strength, external pull-up or pull-down resistors must be higher than 50 kΩ, and the chip should not be used for I²C or 1-Wire, where an open-drain driver is involved. It is designed for loads up to 70 pF.
TXS0108E handles open-drain lines as well. TI specifies up to 110 Mbps push-pull and 1.2 Mbps open-drain, with the A side at 1.4 to 3.6 V and the B side at 1.65 to 5.5 V (VCCA must not exceed VCCB). Its internal "smart" pull-ups are 4 kΩ while passing a high and 40 kΩ while passing a low, and one-shot accelerators speed up the edges. That design brings conditions:
- The low level must be really low. The recommended input low voltage is 0.15 V at most, on both ports. A driver that only pulls down to a few hundred millivolts, for example through a series resistor or a weak open-drain output, may not be read as low.
- External pull-downs eat the high level. The datasheet gives VOH = VCC × RPD / (RPD + 4 kΩ). A module with a 10 kΩ pull-down on a 5 V line would see only about 3.6 V as a high.
- Capacitance matters. TI recommends keeping the load under 70 pF for the full data rate. Long jumper wires and connectors add to it.
- OE must be tied high. TI's guide to TXS translators says to tie OE to VCCA if you do not need to control it. Leaving it floating can cause extra supply current.
None of this rules the TXS0108E out. It is a good fit for short wires to a module with ordinary push-pull or open-drain pins and no extra resistors. For I²C at up to 400 kbit/s, though, the BSS138 board comes with fewer conditions, and for one-way signals a 74AHCT125 is simpler still.
Which one to use
| Signal | Recommended fix |
|---|---|
| 5 V digital output into the ESP32, slow (echo, button, open contact) | resistor divider to about 3-3.3 V |
| 5 V analog output into the ESP32 ADC | divider sized so the maximum stays below about 2.45 V |
| ESP32 output into a 5 V TTL-compatible input (VIH about 2 V) | direct connection |
| ESP32 output into a 5 V CMOS input (VIH 0.7 × VDD) | 74AHCT125 or 74HCT125 powered from 5 V |
| I²C between 3.3 V and 5 V | BSS138 module (AN10441 circuit), up to 400 kbit/s |
| fast push-pull bus, short wires, no pull-ups | TXB0108 or TXS0108E, following the datasheet limits |
Mistakes that come up again and again
- No common ground. A level shifter compares voltages against ground. If the 5 V module has its own supply, join the grounds.
- HV and LV swapped or one left unpowered. The MOSFET board needs both reference voltages, with the higher one on HV.
- Trusting "5 V tolerant" claims. The ESP32 datasheet lists 3.6 V as the maximum high input at 3.3 V. Forum posts saying a pin "survived" 5 V do not change that.
- Using a divider on a fast or bidirectional line. It works for an echo pulse, not for I²C, and not reliably for SPI.
- Putting a TXB0108 on I²C. TI explicitly rules it out for open-drain buses.
- Ignoring the module's own pull-ups. Look at the board before you connect it. Two small resistors next to the SDA and SCL pins are a hint worth following up.
If the module you want comes in a 3.3 V version, buying that version is usually the cheapest level shifter of all.