ESP32 DevKit with 2 external relays

Wiring guide for a classic ESP32 DevKit driving two external relay modules (GPIO26 and GPIO27), and how to confirm the ON level.

Status: firmware 1.3.0, offered on the Flash page. Outputs stay OFF until you confirm each relay's ON level on the board's /hw page. Run the tests below with no load connected before you trust a relay.

Safety first. Disconnect every load. Keep mains disconnected while flashing and for the first tests. Keep one power source connected. Use GPIO26 for relay 1 and GPIO27 for relay 2. Each relay input needs hardware that keeps it OFF while the ESP32 is off or restarting. Signals must stay at or below 3.3 V. Never power a relay coil from a GPIO. Check every GPIO and ON level on the board's local page before you confirm. If a relay turns ON unexpectedly, disconnect power and correct the wiring or the ON level before trying again.

What this target is

  • A classic ESP32 DevKit (ESP32-WROOM-32 or similar dual-core module, 4 MB flash or more, no PSRAM use) with two external relay modules. Single-core modules (such as SOLO-1) and ESP32-S2, S3, C3 and C6 boards are not supported by this build.
  • Firmware model text: ESP32 DevKit (external 2-relay). Projects for it use the board id esp32-devkit (projects saved earlier for the generic esp32 board are still accepted; their pins go through the same guard and confirmation).
  • Updates are by USB only. The board's /update page is disabled.
  • No LDR, kit button or status LED in this release. GPIO2 is never used.

Choose your board layout: 30-pin or 38-pin

There is one firmware for both boards. You tell the board which layout it is on its /hw page (step 1 below), and the choice is stored on the board. On the Flash page the two entries install the same file. The board then refuses any pin that is not usable on that layout, both in its own output guard and when it checks a project. Without a stored layout it drives nothing.

GPIO Use 30-pin (DevKit V1 / DOIT) 38-pin (DevKitC / NodeMCU-32S)
4, 13, 18, 19, 21, 22, 23 Output or input on header on header
25, 26, 27, 32, 33 Output or input (ADC1: 32, 33) on header on header
34, 35, 36 (VP), 39 (VN) Input only, no internal pull, analog (ADC1) on header on header
14 Not offered until its boot signal is measured on header on header
0, 2, 12, 15, 5 Strapping pins: never outputs or default inputs 2, 5, 12, 15 0, 2, 5, 12, 15
1, 3 USB serial, reserved on header on header
16, 17 PSRAM on WROVER boards, closed on header on header
6, 7, 8, 9, 10, 11 Flash. Never use not on header on header (SD0 to SD3, CMD, CLK)

So both layouts offer the same twelve output pins (4, 13, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33) and four input-only pins (34, 35, 36, 39). The 38-pin board has extra pins on its header, but all of them are closed. Always use the number printed on your board.

Find the pins by their printed labels

Check the GPIO labels printed on your board. Carrier boards and clones have different layouts, and 30-pin and 38-pin boards place pins differently. Use the number printed next to the pin (for example IO26 or 26), never its position. If a label is missing or you are not sure, stop.

Function GPIO Notes
Relay 1 26 Output. Stays an input (not driven) until you confirm
Relay 2 27 Output. Can stay unset if you use one relay
Ground GND Common ground with the relay module (see below)
3.3 V 3V3 Logic level only. Not for relay coils
BOOT button 0 Onboard button only. Connect nothing else
USB serial 1, 3 Reserved

Never use GPIO 6 to 11 (these are the flash pins, including CMD, CLK and SD0 to SD3 on some carriers), 0, 2, 5, 12, 15, 1, 3, 16 or 17 as outputs. GPIO 34 to 39 are inputs only. GPIO14 is not offered until its boot signal has been measured. A pin being exposed on a header does not make it safe.

Wiring rules

  1. Logic is 3.3 V. The ESP32 GPIO must never see 5 V. Many 5 V relay modules pull their input towards 5 V and need an interface circuit even if they click. Use a module confirmed to work with 3.3 V logic.
  2. Common ground. Connect the relay module's signal ground to the ESP32 GND. If the module is optically isolated, follow its datasheet: joining the grounds can remove the isolation.
  3. Separate relay power. Power the relay module (coil) from a supply rated for all coils, with flyback protection built into the module. Never power a coil from a GPIO, and do not assume the board's 3V3 pin can supply coils.
  4. One power input at a time. Use micro-USB or USB-C or the DC jack, never two. Until the carrier's schematic is known, measure the V pins before you connect a module, and set any 3.3 V / 5 V jumper with power off. Keep 5 V away from every signal pin.
  5. Pull resistors keep the relay OFF. The firmware cannot hold a pin before it starts, while the chip resets or while it is off. A resistor on each relay input does that:
    • Active-high module (ON at HIGH), recommended: a 4.7 kΩ pull-down from the GPIO to GND.
    • Active-low module (ON at LOW): a 4.7 kΩ pull-up from the GPIO to 3V3, never to 5 V, and only if the module's input never exceeds 3.3 V. If the relay module can have power while the ESP32's 3V3 is off, a pull-up to 3V3 does not keep it OFF: use a driver that stays OFF without ESP32 power, or do not use that module.
    • The module has its own input circuit (a typical internal pull is about 45 kΩ). Against that alone, 4.7 kΩ gives about 0.31 V (pull-down) or 2.99 V (pull-up); 10 kΩ gives about 0.60 V or 2.70 V. Check your module's thresholds and measure its input.
Active-high module, pull-down                Active-low module (3.3 V input only), pull-up

  ESP32 GPIO26 ──┬────────► IN                3V3 ──[4.7k]──┬──── IN
                 │                                           │
             [4.7k]                          ESP32 GPIO26 ─────┘
                 │
  ESP32 GND ─────┴────────► GND (common)      ESP32 GND ───────────► GND (common)

  Relay module power: its own supply, rated for all coils. Never from a GPIO.

A transistor or MOSFET driver whose input is pulled to its OFF level also works. Choose its parts from the datasheets.

Set the ON level and confirm (required)

Until you confirm, the firmware drives no relay pin. Relays show as OFF, and commands from the cloud, the board's web page, MQTT, the button and rules are refused. This is deliberate: a wrong ON level would switch a relay ON.

  1. Disconnect every load and mains. Power the board and connect it to Wi-Fi (or use USB serial). Choose your pin layout (30-pin or 38-pin, see above) and press Save layout; the board restarts. Changes made from the web page only apply after you press the BOOT button on the board within 30 s (a request from the network alone changes nothing; only one request can wait at a time, and the page shows exactly what BOOT will apply); serial commands apply at once. Serial: variant 30pin or variant 38pin. Changing the layout deletes any confirmation. A board with no stored layout cannot be confirmed and drives nothing. Boards updated from 1.2.0 have no saved setup yet: choose the layout, set the ON levels and confirm. A project already stored on the board is kept.
  2. Open the board's own page http://<board IP>/hw (or http://edextron-xxxx.local/hw). Check each GPIO and its ON level against your relay module. The page has no login, so anyone on your network can open it.
  3. Choose the ON level of each relay (high or low), press Save levels. The board restarts.
  4. Open /hw again, read the output map, then press Confirm this map and restart. After the restart the relays are OFF.
  5. Serial alternative (115200 baud): outputs, variant 30pin, relay 1 high, relay 2 low, then confirm <hash shown>.

If a project is installed, its pins and ON levels come from the project (fix them in the project editor). A project's default high is not a confirmation: you still confirm the map locally. Changing the outputs, or removing the project, deletes the confirmation. The board never falls back to GPIO26/27 on its own. A rules-only change keeps it. A saved rule can switch a relay ON after the restart, so disconnect all loads before confirming.

A factory reset and a full erase clear the confirmation. Unpairing from the cloud keeps it, because the wiring has not changed.

First tests

  • No mains, no load. Watch the relay module's LED while you power on, press EN, and open the serial monitor. It must stay OFF.
  • If a relay turns ON unexpectedly: disconnect power, then correct the wiring, the pull resistor or the ON level before trying again.
  • Mains wiring must be done by a qualified person, with a suitable enclosure, fuse and clearances.

Tank water alarm: float switch, water sensor and buzzer

The starter project Tank water alarm (Projects → new project → pick a DevKit) uses these pins on both layouts:

Part GPIO Notes
Float switch 32 Input, internal pull-up, active low (switch closes to GND when the water is high), debounce 50 ms
Water sensor (optional) 34 Analog, ADC1, input only (no internal pull). Needs 3.3 V and GND
Buzzer 25 Output, active high
Relay 1 (pump or valve) 26 Output. Switches ON together with the buzzer
Relay 2 27 Free, no rule

The rule: when the float stays active for 2 s, the buzzer and relay 1 switch ON; they switch OFF after the float has been inactive for 5 s. A splash shorter than 2 s does nothing. The optional water sensor sounds the buzzer only. Nothing is driven until you confirm the output map on /hw, and the buzzer pin is part of that confirmed map: a new or changed buzzer pin deletes the confirmation.

Float switch: one wire to GPIO32, the other to GND. No resistor is needed (the pull-up is internal). Use a normally-open float that closes when the water is high, or turn the logic round in the project editor.

Water sensor module: VCC to 3V3 (not 5 V: its output would exceed what the pin tolerates), GND to GND, S (analog out) to GPIO34. Add it only when it is really connected: an analog pin with nothing on it floats and can read "wet".

Buzzer: use an active buzzer (it beeps by itself when powered). A passive buzzer needs a tone signal and stays silent or buzzes faintly with this on/off output. If the buzzer draws more than about 20 mA, do not connect it to the GPIO directly: use a transistor.

GPIO25 ──[1 kΩ]──► base of NPN (for example 2N2222 / BC337)
                   emitter ──► GND (common with the ESP32)
3V3 or 5 V ──► buzzer (+)       buzzer (−) ──► collector
Flyback diode across a magnetic buzzer: cathode to (+), anode to (−).

Keep 5 V away from every signal pin. As with relays, set and confirm the output map on /hw before you rely on the alarm, and test with the pump disconnected.

Flash size

This build needs 4 MB of flash or more. A smaller flash is not supported and there is no fallback image. If a board with less than 4 MB was flashed and does not boot, recover over USB with firmware that fits that flash. On 8 or 16 MB boards the space above 4 MB is unused.

Why a reset needs 3 presses

USB auto-reset circuits can hold GPIO0 LOW. On this board, holding BOOT for 15 seconds only arms the reset: press BOOT briefly 3 times within 10 seconds to erase Wi-Fi, the cloud link and the output setup. Holding BOOT for 5 seconds still opens Wi-Fi setup.