Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

Relay module with ESP32-C3 SuperMini — safe wiring and code

Switch a 3.3 V-trigger relay module from GPIO7 of an ESP32-C3 SuperMini, held off at boot, coil on 5V — with clear limits on what the contacts may switch.

Arduino C++Verified — core esp32 3.3.12, 3 Nov 2026Compile-only

Community draft — report a mistake

A relay lets the SuperMini switch a separate circuit — a 12 V pump through a contactor, a fan, a small lamp. This guide covers the low-voltage side: coil power from 5V, the trigger on GPIO7, and a relay that stays off while the C3 boots.

Type 1 or 0 in the Serial Monitor to switch it. What you connect to COM/NO is the part that can hurt: keep to low-voltage loads, use a contactor for motors, and leave mains wiring to an electrician.

Wiring

ESP32-C3 SuperMiniOnly the pins used are shown · 3.3 V logic1-channel relay module (5 V coil)5VGND7 · 7DC+DC−INCOM (not connected)NO (not connected)NC (not connected)
Every connection
ESP32-C3 SuperMini1-channel relay module (5 V coil)WireNotes
5VDC+redCoil supply from USB 5 V (~70 mA per relay). Not from 3V3.
GNDDC−black
7INyellowUse a module sold as “3.3 V trigger” (opto-isolated, active-LOW).

5 V coil part, 3.3 V board. The coil runs on 5 V, but the IN pin only drives an optocoupler LED. Pick a module rated for a 3.3 V trigger when using ESP32 or Pico — some 5 V-only modules never fully release from a 3.3 V HIGH.

Board quirks

  • GPIO7 is quiet during boot. Avoid GPIO2/8/9 (strapping pins), and GPIO21, which carries the ROM’s boot messages and makes a relay chatter at reset.
  • The sketch writes the pin HIGH (relay off) before making it an output, so the relay never clicks on while the board starts.
  • Feed the coil from 5V, not 3V3: the SuperMini’s 3.3 V regulator is small and a relay coil plus Wi-Fi bursts can brown it out.
  • Many 5 V modules need more than 3.3 V on IN to switch fully off. Buy one marked “3.3 V trigger”, or one with a JD-VCC jumper.
  • COM/NO/NC are the switched side. Use the relay for low-voltage loads or a small lamp within its rating; pumps and motors go through a contactor, and any 230 V wiring (with MCB, RCCB and earth) is for an electrician.

Code

relay-esp32c3.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// 1-channel relay module (3.3 V-trigger, active-LOW) on an ESP32-C3 SuperMini.
// DC+ → 5V (USB 5 V), DC− → GND, IN → GPIO7.
// GPIO7 is not a strapping pin (2/8/9) and is quiet during boot, unlike GPIO21 (UART0 TX),
// so the relay doesn't chatter at power-up.
// Type 1 / 0 in the Serial Monitor. Low-voltage or small resistive loads only; motors and pumps
// go through a contactor, and any 230 V wiring is for an electrician.
constexpr uint8_t RELAY_PIN = 7;
constexpr bool RELAY_ACTIVE_LOW = true;

void setRelay(bool on) {
  digitalWrite(RELAY_PIN, (on != RELAY_ACTIVE_LOW) ? HIGH : LOW);
  Serial.println(on ? "Relay ON" : "Relay OFF");
}

void setup() {
  digitalWrite(RELAY_PIN, RELAY_ACTIVE_LOW ? HIGH : LOW);  // off before the pin becomes an output
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(115200);
  delay(1500);  // let the native USB serial port enumerate
  Serial.println("Send 1 = on, 0 = off");
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == '1') setRelay(true);
    if (c == '0') setRelay(false);
  }
}

Expected serial output

Serial Monitor · 115200Output
Send 1 = on, 0 = off
Relay ON
Relay OFF

Common errors

Relay clicks but the load doesn’t switch

The load is on NC instead of NO, or not through COM at all. Full fix.

Relay never turns off

The module needs a 5 V trigger. Use a 3.3 V-trigger module.

Board resets when the relay clicks

Coil current on a weak USB port. Use a better cable/adapter, or power the module separately with a common GND. Brownout fix.

↑↓ to move · Enter to open