In our guide on Controlling AC Powered Appliances With ESP32 and IBM Watson IoT we pointed that the relay connected with ESP32 may not properly function. There are many ways to shift the 3.3V signal to 5V signal.
A level shifter or logic-level shifter is a circuit used to translate signals from one logic level or voltage to another. The logic-level shifter can be uni-directional, bi-directional with dedicated ports, bi-directional with external direction indicator, bi-directional, auto-sensing.
Different approaches have different pros and cons. There are more than 10 types of logic level shift up circuits out there. We need to make an engineering tradeoff or cost-benefit analysis. When we want to entertain only one relay module, then we may consider single transistors (such as BJT NPN 2N2222, MOSFET 2N7000). You may try 2N2222.
---
The single-BJT level shifter would work if the input impedance of the device on the 5 Volt side is significantly higher than the resistance on 5V power supply side. However, for lower impedance inputs, the input would act as a voltage divider, attenuating the high part of the signal significantly. Any lower level becomes problematic. This is when one needs an alternative, such as a two-transistor.
A Bi-Directional Logic Level Converter (LLC) also reduces the voltage from a signal. This is the recommended method to level shift signals that require high-speed communication.
A Bi-Directional Logic Level Converter circuit features four high speed bi-directional 4 channels, allowing easy communication between devices. It can convert signals as low as 1.8 V to as high as 5 V. A Bi-Directional Logic Level Converter safely steps down 5V signals to 3.3V AND steps up 3.3V to 5V at the same time. These circuits cost $1.
Connect High voltage (5V) to the “HV” pin
Connect Low voltage (3.3V) to “HV” pin
Ground from the system to the “GND” pin.