Relay modules are commonly used to switch lamps, pumps, fans, solenoids, motors and other external loads from Arduino, ESP32, ESP8266, RP2040 and similar microcontroller boards.
With a classic 5V Arduino Uno, many relay modules appear to work easily. But when the same relay module is connected to an ESP32, it may not switch at all, switch unreliably, stay permanently on, reset the ESP32, or prevent the ESP32 from booting.
This is usually not because the ESP32 is defective. The problem is often caused by 3.3V logic levels, relay module input circuit design, missing common ground, weak power supply, boot strapping pins, or misunderstanding active-low relay inputs.
Typical Symptoms
- The relay works with Arduino Uno but not with ESP32.
- The relay LED turns on, but the relay does not click.
- The relay clicks sometimes, but not reliably.
- The relay is on when the sketch says it should be off.
- The ESP32 resets when the relay switches.
- The ESP32 does not boot when the relay module is connected.
- The relay chatters or clicks rapidly.
- The relay module works from 5V logic but not from a 3.3V GPIO pin.
First Important Point: Many Relay Modules Are Designed for 5V Logic
Many low-cost relay modules are sold as “Arduino relay modules.” That often means they were designed with 5V Arduino boards in mind.
The ESP32 uses 3.3V GPIO. A 3.3V HIGH signal may not be high enough or low enough for every 5V relay module input circuit, depending on how the module is built.
Some relay modules work fine with 3.3V logic. Others do not. The only safe assumption is that the module must be checked, not guessed.
Common Cause: Active-Low Relay Input
Many relay modules are active-low. This means the relay turns on when the input pin is pulled LOW, not HIGH.
This can be confusing because the code looks backwards:
digitalWrite(RELAY_PIN, LOW); // Relay ON
digitalWrite(RELAY_PIN, HIGH); // Relay OFF
If you assume HIGH means on, the relay may appear to behave incorrectly.
Always test whether your relay module is active-high or active-low before writing the final logic.
Common Cause: 3.3V GPIO Cannot Drive the Module Input Reliably
Some relay modules contain an optocoupler, indicator LED, transistor, resistors and jumper options. Depending on the design, the input may need more current or a different voltage level than an ESP32 GPIO can provide reliably.
Possible symptoms:
- The relay module input LED glows dimly.
- The relay does not click.
- The relay clicks only sometimes.
- The relay works when touched or when USB is connected.
- The relay works on Arduino Uno but not on ESP32.
If the relay module is not truly 3.3V-compatible, use a transistor, MOSFET driver, logic-level interface, or a relay module designed for 3.3V logic.
Common Cause: Relay Coil Needs More Current Than the ESP32 Board Can Supply
The ESP32 GPIO pin should never power the relay coil directly. A relay coil needs more current than a GPIO pin can safely provide.
A proper relay module includes a transistor driver for the coil. But the relay coil supply still needs enough current.
Do not power multiple relay coils from the ESP32 3.3V pin. Most 5V relay modules should be powered from a proper 5V supply.
Common Cause: Missing Common Ground
If the ESP32 is powered from USB and the relay module is powered from a separate 5V supply, the input signal usually needs a common reference.
For a typical non-isolated relay module:
- ESP32 GND must connect to relay module GND.
- Relay module VCC must connect to its required supply voltage.
- Relay IN must connect to the ESP32 GPIO pin.
Without common ground, the relay module input may not understand the ESP32 signal level correctly.
Common Cause: Confusing VCC and JD-VCC
Some relay modules have pins labeled VCC and JD-VCC. These modules are often designed so the relay coil supply can be separated from the logic input supply.
The exact meaning depends on the module, but commonly:
- VCC powers the logic/input side.
- JD-VCC powers the relay coil side.
- A jumper may connect VCC and JD-VCC for simple use.
This can be useful, but also confusing. If the jumper is removed or installed incorrectly, the input LED may work while the relay coil has no power, or the coil may be powered while the input side is not referenced correctly.
Check the relay module documentation or trace the board carefully before assuming how VCC and JD-VCC are connected.
Common Cause: Boot Strapping Pins on ESP32
Some ESP32 pins affect boot mode during reset. If a relay module pulls one of these pins high or low at the wrong time, the ESP32 may fail to boot or may enter download mode instead of running the sketch.
This can make the relay problem look like a software problem, but the actual issue is pin selection.
Avoid using ESP32 boot strapping pins for relay inputs unless you understand their reset behavior.
Depending on the ESP32 board, pins such as GPIO0, GPIO2, GPIO12 and GPIO15 may require special care. Always check the exact board pinout.
Common Cause: Relay Turns On During Boot
Even if the ESP32 boots correctly, some pins may change state during reset or startup. The relay can click briefly before the sketch configures the pin.
This is dangerous if the relay controls something important, such as a heater, pump, door lock or motor.
Possible fixes include:
- Use a GPIO pin that stays in a safe state during boot.
- Add external pull-up or pull-down resistors to define the relay input state.
- Use a driver circuit that defaults to off.
- Use relay modules with proper enable control.
- Design the load so a brief relay pulse is not dangerous.
Common Cause: Relay Switching Noise Resets the ESP32
Relay coils and switched loads can create electrical noise. Even if the relay module has a flyback diode for the coil, the load being switched may still create noise.
This is especially true for motors, solenoids, pumps and inductive loads.
Symptoms include:
- ESP32 resets when the relay turns on or off.
- WiFi disconnects when the relay switches.
- OLED or LCD display glitches when the relay clicks.
- Sensor readings jump when the load switches.
Improve power wiring, use proper suppression for inductive loads, keep relay wiring away from signal wiring, and avoid powering the ESP32 from the same weak supply path as the relay load.
Common Cause: Relay Module Is Powered from the Wrong Voltage
Relay modules are usually made for a specific coil voltage, such as 5V, 12V or 24V. A 5V relay module needs a 5V coil supply. A 12V relay module needs a 12V coil supply.
If a 5V relay is powered from 3.3V, the input LED may turn on but the relay coil may not pull in strongly enough to click.
Check the markings on the relay itself. The coil voltage is usually printed on the relay body.
Basic Relay Module Wiring with ESP32
| Relay Module Pin | Typical Connection | Important Note |
|---|---|---|
| VCC | 5V supply or logic supply as required by module | Check whether the input side supports 3.3V logic |
| GND | ESP32 GND and supply GND | Required for non-isolated control signals |
| IN | ESP32 GPIO pin | Avoid boot strapping pins and unsafe startup states |
| COM | Common relay switch contact | Electrically separate from control input on most relay modules |
| NO | Normally open contact | Connected to COM only when relay is energized |
| NC | Normally closed contact | Connected to COM when relay is not energized |
Simple ESP32 Relay Test Sketch
Use a simple sketch before testing the relay inside a large project.
#define RELAY_PIN 23
void setup() {
pinMode(RELAY_PIN, OUTPUT);
// For many active-low relay modules, HIGH means OFF.
digitalWrite(RELAY_PIN, HIGH);
}
void loop() {
digitalWrite(RELAY_PIN, LOW); // Relay ON for active-low module
delay(1000);
digitalWrite(RELAY_PIN, HIGH); // Relay OFF for active-low module
delay(1000);
}
If your relay module is active-high, reverse the HIGH and LOW logic.
Testing Whether the Relay Is Active-Low
With the relay powered correctly and connected to a safe test load or no load at all, test both logic states.
- If
digitalWrite(pin, LOW)turns the relay on, the module is active-low. - If
digitalWrite(pin, HIGH)turns the relay on, the module is active-high.
Many optocoupler-style relay modules are active-low.
Use a Transistor Driver When Needed
If the relay module input is not compatible with the ESP32, a small driver circuit can solve the problem.
A basic low-side driver for a bare relay coil includes:
- NPN transistor or logic-level N-channel MOSFET.
- Base or gate resistor where appropriate.
- Flyback diode across the relay coil.
- External supply for the relay coil.
- Common ground with the ESP32.
For ready-made relay modules, the driver may already exist on the board. But if the module input still does not work with 3.3V logic, use a 3.3V-compatible relay module or add an interface stage.
Optocoupler Isolation Is Often Misunderstood
Many relay modules advertise optocoupler isolation. But the module is only truly isolated if it is wired correctly and the board layout actually supports isolation.
If VCC, JD-VCC and grounds are tied together, the optocoupler may still work as an input buffer, but the system is not truly isolated.
This is not necessarily bad. For many low-voltage projects, non-isolated wiring with common ground is normal. But do not assume the word “opto-isolated” means the module is safely isolated in every wiring configuration.
Switching Mains Voltage
Relay contacts may be rated for mains voltage, but that does not automatically make the finished project safe.
If a relay switches AC mains, the project needs proper insulation, enclosure, strain relief, creepage distance, fuse protection, wire rating and safety practices.
Breadboards and loose jumper wires are not suitable for mains voltage. For learning and troubleshooting, use low-voltage loads whenever possible.
Recommended Troubleshooting Steps
- Check the relay coil voltage printed on the relay.
- Power the relay module from the correct supply voltage.
- Confirm whether the relay input is active-low or active-high.
- Use a simple test sketch with one GPIO pin.
- Avoid ESP32 boot strapping pins.
- Connect common ground for non-isolated relay control.
- Check whether the relay module really accepts 3.3V logic.
- Use a transistor, MOSFET or proper 3.3V relay module if needed.
- Keep relay/load wiring away from I2C, sensor and reset wiring.
- Add suppression for inductive loads if the ESP32 resets when switching.
Quick Diagnostic Table
| Symptom | Likely Cause | First Thing to Try |
|---|---|---|
| Input LED on, relay does not click | Wrong coil voltage or weak relay supply | Check relay coil voltage and supply current |
| Works with Uno, not ESP32 | Relay input not 3.3V-compatible | Use 3.3V-compatible relay module or driver stage |
| Relay logic seems reversed | Active-low input | Reverse HIGH/LOW logic in the sketch |
| ESP32 does not boot | Relay connected to boot strapping pin | Move relay input to a safer GPIO |
| Relay clicks during boot | GPIO startup state triggers relay | Use safer pin or external pull-up/pull-down |
| ESP32 resets when relay switches | Switching noise or power dip | Improve power wiring and add suppression for the load |
What Not to Do
- Do not power a relay coil directly from an ESP32 GPIO pin.
- Do not assume every 5V relay module works with 3.3V logic.
- Do not use ESP32 boot strapping pins blindly for relay inputs.
- Do not forget common ground in non-isolated setups.
- Do not assume optocoupler modules are truly isolated unless wired correctly.
- Do not test mains voltage loads on a breadboard.
CANABLOX Practical Note
CANABLOX can be used to build the controller side of a relay project in a cleaner and more modular way. The controller, display, buttons, sensors and I2C modules can stay organized while the relay or output driver section is handled as a separate load interface.
When using ESP32, ESP32-C3, ESP32-C6, ESP32-S3, RP2040 or other XIAO-style controllers with CANABLOX, choose relay hardware that is compatible with 3.3V logic or use a proper driver stage. Keep high-current and high-voltage wiring outside the logic-side CANABLOX wiring.
Conclusion
If a relay module does not work with ESP32, the first suspect should not be the sketch. Check the relay module input design, coil voltage, power supply, active-low logic, common ground and ESP32 pin choice.
Many relay modules were designed with 5V Arduino boards in mind. ESP32 uses 3.3V logic and has special boot behavior on some pins, so the relay module must be chosen and wired carefully.
Once the relay module is powered correctly, controlled from a safe GPIO and matched to the ESP32 logic level, relay control becomes reliable and predictable.
