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 or relay shield with LOLIN S2 Mini

Switch a relay from GPIO35 of a LOLIN S2 Mini — the D1 position the Wemos relay shield uses — with the coil on VBUS and clear limits on the load.

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

Community draft — report a mistake

Because the S2 Mini shares the D1 mini footprint, the cheap Wemos relay shield plugs straight on — its default pin lands on GPIO35. A loose relay module works the same way: coil on VBUS, IN on GPIO35.

Type 1 or 0 in the Serial Monitor. Keep what you switch within the relay’s rating, and leave any mains wiring to an electrician.

Wiring

LOLIN S2 MiniOnly the pins used are shown · 3.3 V logic1-channel relay module (5 V coil)35 · 35GNDVBUSDC+DC−INCOM (not connected)NO (not connected)NC (not connected)
Every connection
LOLIN S2 Mini1-channel relay module (5 V coil)WireNotes
VBUSDC+redUSB 5 V for the coil (~70 mA).
GNDDC−black
35INyellowD1 mini “D1” position — the relay shield’s default.

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

  • GPIO35 is where D1 sits on a D1 mini, so the LOLIN/Wemos relay shield (default jumper D1) works on this pin. The shield is active-HIGH — set RELAY_ACTIVE_LOW = false for it.
  • GPIO35 is also the default I2C SCL. If you add an I2C sensor, move the relay to another pin such as GPIO37 or GPIO39.
  • The pin is set to its “off” level before it becomes an output, so it doesn’t click on during the S2’s boot. The blue LED (GPIO15) mirrors the relay.
  • COM/NO/NC carry the load. Keep to low-voltage loads or a small lamp within the relay’s rating; pumps and motors go through a contactor, and 230 V wiring with MCB, RCCB and earth is for an electrician.

Code

relay-s2mini.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// Relay on a LOLIN S2 Mini — a 1-channel relay module, or the LOLIN/Wemos relay shield.
// DC+ → VBUS (USB 5 V), DC− → GND, IN → GPIO35. GPIO35 sits where D1 is on a D1 mini,
// which is the relay shield's default pin. That shield is active-HIGH (transistor driver);
// most blue opto modules are active-LOW — set RELAY_ACTIVE_LOW to match yours.
// 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 = 35;
constexpr bool RELAY_ACTIVE_LOW = true;  // false for the LOLIN relay shield

void setRelay(bool on) {
  digitalWrite(RELAY_PIN, (on != RELAY_ACTIVE_LOW) ? HIGH : LOW);
  digitalWrite(LED_BUILTIN, on);  // blue LED mirrors the relay
  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);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  uint32_t t0 = millis();
  while (!Serial && millis() - t0 < 3000) {}
  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 is on when it should be off

Wrong polarity setting: the relay shield is active-HIGH, blue opto modules are active-LOW. Flip RELAY_ACTIVE_LOW.

Clicks but the load doesn’t switch

Load on NC. Full fix.

↑↓ to move · Enter to open