Before you start
- Board and software
- Classic ESP32-WROOM-32/32E DevKit with the named GPIOs exposed and unused; Arduino IDE 2.x and esp32 by Espressif Systems 3.x. Other ESP32 families need their own pin map. Serial Monitor: 115200 baud.
- Supported relay
- The complete example supports the Adafruit STEMMA Non-Latching Mini Relay (product 4409), with red Vin, black GND and white Signal leads. It is active HIGH and accepts a 3.3 V signal. Use a regulated external 5 V supply rated at least 100 mA for this relay alone (about 50 mA energized per manufacturer). Do not substitute a latching relay or an unidentified active-LOW board. The generic page photo does not identify this supported model.
- Parts and load
- Use only a separate 3 V battery supply, one ordinary red LED and a 330 ohm series resistor as the contact-side load. No mains, motors, heaters or unattended operation are covered. The contact-side battery circuit needs no connection to ESP32 ground. Also use a STEMMA 3-pin JST-PH breakout cable, 10 kΩ signal pull-down, breadboard and jumper wires.
- Verification status
- Documentation and code-path review only. This update was not compiled for an ESP32 or tested on hardware. This is a supervised demonstration, not a fail-safe controller.
Overview
A relay uses a coil to move a mechanical contact. A driver module lets a GPIO command the coil without powering it from the pin. The control supply and the load supply do different jobs.
COM connects to NC with the supported relay de-energized. Energizing it connects COM to NO. Using NO makes this LED load off when the coil is off; it does not make a circuit fail-safe if contacts weld or software fails.
Technical Specifications
Arduino library: Built-in Arduino digitalWrite
| Specification | Value | Why it matters |
|---|---|---|
| Supported input | STEMMA 4409: active HIGH, 3–5 V signal | ESP32 supplies a 3.3 V command; this does not apply to generic relay boards. |
| Control supply | STEMMA 4409: 3–5 V DC; example uses external regulated 5 V | Manufacturer reports about 50 mA while energized. GPIO supplies signal, not coil power. |
| Contacts | COM, NO and NC | Separate 3 V battery/LED circuit uses COM and NO. |
| Startup | LOW command plus 10 kΩ Signal pull-down | Keep relay command OFF during startup; not a safety guarantee. |
Pinout
- Red Vin Control power External regulated +5 V Supported STEMMA connector; not generic pin positions.
- Black GND Control return External supply negative and ESP32 GND USB powers the ESP32 separately.
- White Signal Active-HIGH input GPIO26; 10 kΩ to GND 3.3 V command for the supported board only.
- COM Common contact Separate 3 V battery positive Read terminal labels, not the generic photograph.
- NO Normally open contact 330 ohm resistor → red LED anode LED cathode returns to battery negative.
- NC Normally closed contact Leave unused Connected to COM when the coil is off.
Wiring Diagram
Logical connections for the explicitly supported STEMMA board; not a physical pin-position drawing. Supply and contact circuits are separate. Follow the terminal labels and manufacturer pinout.
Open wiring diagram at full size (new tab)
-
1
Disconnect USB, the external relay supply and the load battery before wiring.
-
2
Connect the supported relay red Vin lead to regulated external +5 V; connect its black GND lead to that supply negative and ESP32 GND. Do not join external +5 V to the USB-powered DevKit 5 V pin.
-
3
Connect the relay white Signal lead to GPIO26. Add a 10 kΩ resistor between Signal and control-side GND to hold the command LOW while GPIO26 is not driven.
-
4
Wire the separate 3 V battery positive to COM. Wire NO through a 330 ohm resistor to the red LED anode; LED cathode returns to battery negative. Leave NC unused.
-
5
Initially leave the load battery disconnected. Upload the example, open Serial Monitor at 115200 baud and check the relay command and contact operation.
-
6
Disconnect all supplies before adding the battery. Reconnect and confirm that the LED lights only when the relay is commanded ON.
Wiring and matching Arduino code
Arduino: supported active-HIGH relay test
#include <Arduino.h>
// Adafruit STEMMA Non-Latching Mini Relay 4409 only: active HIGH.
constexpr uint8_t RELAY_PIN = 26;
constexpr uint8_t RELAY_ON = HIGH;
constexpr uint8_t RELAY_OFF = LOW;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_OFF);
Serial.begin(115200);
Serial.println("Relay OFF. Low-voltage LED load only.");
delay(2000); // Observe the initial OFF command before the first toggle.
}
void loop() {
digitalWrite(RELAY_PIN, RELAY_ON);
Serial.println("Relay ON");
delay(2000);
digitalWrite(RELAY_PIN, RELAY_OFF);
Serial.println("Relay OFF");
delay(2000);
}
Complete Arduino sketch; no third-party library is required. ESP-IDF and PlatformIO alternatives are deferred rather than presented as working examples. OFF is LOW for this supported board only. The external pull-down covers the high-impedance startup interval; software alone does not establish safe power sequencing.
Expected Output
After reset the command is OFF for two seconds. Relay ON and Relay OFF then print alternately every two seconds. With the separate LED battery connected, the red LED lights during ON and goes dark during OFF. A click alone is not proof that the load circuit is correctly wired.
How it works
The supported STEMMA input is active HIGH: GPIO26 HIGH commands ON, and LOW commands OFF. A 10 kΩ Signal-to-GND resistor helps keep it OFF while the ESP32 pin is high impedance. Firmware sets OFF before starting its slow toggle.
Other relay boards can have different supply voltages, input thresholds, pull-ups, polarity and jumper arrangements. A coil marking alone does not establish GPIO compatibility. Before substitution, find the exact board schematic and documentation, establish its input voltage/current limits and OFF state, and select a suitable driver interface if needed. Never connect a 5 V-pulled input directly to ESP32 GPIO. Do not guess by trying opposite polarity.
Mechanical contacts are unsuitable for fast PWM. Motors and solenoids additionally need load-specific protection and contact ratings; they are outside this LED example. Module contact separation is not a certification of an assembled circuit or permission to wire mains.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| Relay does not operate | Wrong relay model, absent control supply or incorrect Signal/GND connection. | Disconnect the load. Verify the model and documented 3–5 V input, then check external 5 V and shared control GND. Do not invert polarity to guess compatibility. |
| Relay responds but LED stays off | Missing battery, reversed LED, wrong contact or open wiring. | Disconnect all power. Trace battery + → COM → NO → 330 ohms → LED anode → cathode → battery −. |
| Load turns on with an OFF command | NC selected, unsupported relay polarity, or a failed contact. | Remove load power. Check COM/NO labels and supported board identity. Do not keep testing an unidentified module. |
| ESP32 resets or relay chatters | Weak supply, loose control ground or wiring noise. | Check the external relay supply and short ground connections; do not power the coil from GPIO or feed external 5 V into the USB supply rail. |
| Unexpected operation during reset | Missing Signal pull-down or incorrect power sequencing/module. | Disconnect the load, check the 10 kΩ pull-down and model. Verify startup with the low-voltage load before reuse; this is not a fail-safe design. |
Where you use it
- Learn COM/NO/NC contact behavior
- Practice low-voltage digital output control
- Build the documented sound-triggered LED relay project
Continue learning
Related projects
FAQ
No. It is a generic illustration of the category. The example names the supported STEMMA 4409 board; use its manufacturer documentation and actual terminal labels.
Not unchanged. Verify the exact supply, input circuit and OFF state first, and design any required interface. Changing constants alone cannot establish electrical compatibility.
Disconnect the load battery before using a continuity meter. With the relay de-energized, COM–NC should be closed and COM–NO open. Do not use continuity mode on a powered load circuit.
ESP32 ground and the relay control-supply negative are shared in this example. The separate battery/LED contact circuit does not need to share that ground.
Do not power a coil from GPIO. This supported module includes its driver; mechanical contacts are unsuitable for fast PWM.
No. This tutorial covers only a separate 3 V battery LED load and does not establish mains safety, certification or fail-safe operation.
Technical references
- Adafruit STEMMA relay pinouts — Supported power/signal ranges, active-HIGH input and contact labels.
- Adafruit STEMMA relay usage — Module operation and coil-current guidance; this site limits the load to a battery LED.
- Espressif Arduino GPIO API — GPIO direction and digital output API.

