ESP32 is a widely used WiFi + Bluetooth microcontroller, operating at 3.3V. The operating voltages for sensors vary, with many sensors requiring 5V. Directly connecting a 5V sensor to the ESP32’s I/O ports can result in excessive voltage, which may damage the ESP32.

Conversely,the ESP32’s pins can only handle a maximum voltage of 3.3V, which is inadequate for distinguishing between high and low signal levels in communication. For some sensors, a voltage above 3.7V is necessary to be recognized as a high level, otherwise, it will be considered a low level.

Therefore, we need to use a level conversion module to convert voltages between the two systems. The level conversion module integrates circuits such as voltage comparators and operational amplifiers, which can convert high voltage to low voltage and vice versa.

Experimental Results

WX20230908-1146422x

Lingshun Laboratory (lingshunlab.com) utilizes a level conversion module to facilitate voltage conversion between devices with different voltages, enabling normal connection and communication between them. For instance, in this example, the high-level voltage of the ESP32’s I/O port is increased from 3.3V to 5V (measured at 4.9V due to voltage drop). Level conversion is mostly used in scenarios where communication voltages differ between devices, rather than for load purposes, as the voltage drop can be significant.

Level conversion is primarily used in scenarios where communication voltages differ between devices, rather than for loads, as this would result in a significant voltage drop.

Component Description

WX20230908-1157332x

Product Features:

  • Four MOSFETs enable bidirectional level conversion across four channels between 3V and 5V levels.
  • The power supply input is equipped with reverse polarity protection, incorporates a 3.3V Low Dropout Regulator (LDO), and can supply a maximum of 150mA to external devices.
  • The module features a power status LED for clear operational status indication.
  • Capable of bidirectional level conversion for various bus signals, including UART, I2C, 1-Wire, and SPI, between 3V and 5V.
  • Ensures stable communications at baud rates up to 28800 bps.

Pin Description

5V - Connect to 5V power supply

3V - Connect to 3.3V power supply

GND - Connect to power negative (ground)

HVx - High voltage signal (bidirectional: input or output)

LVx - Low voltage signal (bidirectional: input or output)

Bill of Materials (BOM)

ESP32 x1

Level conversion module x1

Jumper wires (Dupont cables) x several

Breadboard x1

Wiring Diagram

In this example, the high-level 3.3V voltage from an ESP32 pin is converted to 5.0V. You only need to connect the 5V and GND. When pin D13 is set to high, the level conversion module’s HV1 terminal will output a high level of 5.0V.

WX20230908-1129482xx

Program Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// welcome to https://esptutorial.com/

// Define output pin as D13
int OUTPUT_PIN = 13;

void setup() {
// Set pin mode to OUTPUT
pinMode(OUTPUT_PIN, OUTPUT);
}

void loop() {
// Set the output pin to HIGH
digitalWrite(OUTPUT_PIN, HIGH);
delay(2000);
// Set the output pin to LOW
digitalWrite(OUTPUT_PIN, LOW);
delay(1000);
}

After uploading the code, you can use a multimeter to take measurements. You will find 3.3V at the LV1 terminal and 4.9V at the HV1 terminal.

中文版:
ESP32 使用电平转换模块把3.3V转换成5V