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 Mini | 1-channel relay module (5 V coil) | Wire | Notes |
|---|---|---|---|
| VBUS | DC+ | red | USB 5 V for the coil (~70 mA). |
| GND | DC− | black | |
| 35 | IN | yellow | D1 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 = falsefor 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 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);
}
}// 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
Send 1 = on, 0 = off
Relay ON
Relay OFFSend 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.