Introduction
The ESP8266 4-Channel WiFi Relay Module is a low-cost, open-source friendly device for DIY home automation projects. It combines an ESP-01 WiFi module (based on the ESP8266 chip) with a separate 8-bit microcontroller to control four relay switches. This means you can remotely control lights, appliances, and other devices over Wi-Fi using this single compact board. Despite offering similar functionality to popular smart switches like Sonoff or Tuya, this module is much cheaper than those closed-source alternatives. Moreover, it gives you full control to flash custom firmware (like ESPHome or Tasmota) for integration with Home Assistant and other home automation systems, all without being locked into any vendor’s cloud platform.
Why choose this module? For hobbyists and tinkerers, it provides an affordable and flexible route into smart home control. You get the reliability of a proven ESP8266 Wi-Fi chip and the convenience of four relays on one board, at a fraction of the cost of branded smart relay units. In the following sections, we’ll dive into the module’s specifications, internal circuitry, wiring guide, and how to integrate it with ESPHome/Home Assistant. We’ll also compare it with commercial devices (Sonoff, Tuya) to highlight the benefits of this DIY approach.
Module on Robu.in: https://robu.in/product/esp8266-esp-01-5v-4-channels-wifi-relay-module-for-home-remote-control-switch/
Table of Contents
Features and Specifications
Key Specifications: The ESP8266 ESP-01 4-channel relay board comes with a number of impressive specs for its price point:
- Power Supply: 5V DC (regulated on-board for the ESP8266’s 3.3V needs). The module is powered by connecting 5V to the IN+ pin and ground to IN-.
- Relays: 4× Songle SRD series relays, each capable of switching up to 10A at 250VAC or 10A at 30VDC. This allows direct control of high-voltage appliances (lights, fans, etc.) or DC devices (motors, LEDs) within those ratings.
- Microcontroller: Onboard 8-bit MCU (e.g. an STC15 or N76E003 type) that interfaces with the ESP-01 over UART. This MCU handles the relay driving logic, making the module robust and offloading work from the ESP8266. It ships with a default firmware for out-of-the-box use (controllable via a phone app), but can be used with custom firmware as well.
- ESP8266 Module: Uses a detachable ESP-01 WiFi module (ESP8266EX chipset, 1MB flash) for Wi-Fi connectivity. The ESP8266 supports 2.4GHz Wi-Fi (802.11 b/g/n) and can operate in Station mode (connects to your router) or AP mode (phone connects directly).
- Operating Range: Works from -40°C to 85°C and 0–95% relative humidity (non-condensing), suitable for most indoor environments.
- Board Dimensions: Approximately 60 x 63 mm in size. It’s a compact board that can fit in small project enclosures.
- Indicators and Inputs: On-board LEDs indicate relay status and module mode (e.g. power, WiFi mode, and one LED per relay that lights when the relay is active). It also has two push buttons: one to toggle between operating modes (direct or via router) and one reset button.
- Isolation and Protection: The relay drive circuits are optocoupler-isolated for improved safety and interference immunity. Each relay coil has a diode for flyback protection, protecting the circuit from voltage spikes when relays deactivate. The board’s PCB and components adhere to RoHS standards for environmental safety.
Notable Features: This module supports two WiFi working modes out of the box – either your smartphone can connect directly to the module’s own WiFi hotspot (useful for initial setup or if no router is available), or you can have the module join your home WiFi network (Station mode) for integration into your broader smart home. The manufacturer provides an Android app (using Espressif’s SmartConfig/EspTouch) to configure the WiFi credentials and control the relays in the default firmware. However, for more advanced use (and to integrate with Home Assistant), most users flash custom firmware as described later.
Finally, an advantage of the design is that the ESP-01 is removable – it plugs into a header on the relay board. This means if you ever need to replace or reprogram the ESP8266 module, you can do so easily by unplugging it, without soldering. The separation of duties (ESP8266 for WiFi & networking, MCU for relay control) adds reliability; for example, resetting or flashing the ESP8266 won’t inadvertently toggle the relays because the relay states are maintained by the independent MCU.
Internal Circuitry and How It Works
Internally, this relay module consists of two main parts: the WiFi module (ESP8266 ESP-01) and the onboard microcontroller with relay drivers. The ESP8266 communicates with the MCU via a UART serial interface (using the ESP-01’s TX/RX pins). Instead of controlling relays directly with ESP8266 GPIOs, the ESP-01 sends simple serial commands to the MCU, which in turn switches the appropriate relay. For instance, to turn Relay #1 on or off, the ESP8266 sends a specific byte sequence (A0 01 01 A2 for ON, A0 01 00 A1 for OFF in hex) – these commands are defined by the MCU’s firmware. The use of a secondary MCU offloads the realtime control tasks from the ESP8266 and also expands the number of controllable outputs (since the tiny ESP-01 module itself exposes very few GPIO pins).
Each relay on the board is driven by a transistor (or transistor array) that is triggered by the MCU outputs. As mentioned, optocouplers are used to electrically isolate the low-voltage control logic from the higher voltage relay coils and connected loads. This prevents surges or spikes from the relay side from damaging the delicate ESP8266 or MCU. Additionally, flyback diodes across the relay coils absorb the voltage spike when a relay coil is de-energized, further protecting the circuit.
The board has a 5V to 3.3V regulator (a small linear regulator like AMS1117 or similar) to power the ESP-01 module from the 5V input. It also breaks out a 4-pin header (5V, GND, TX, RX) which is essentially the UART port of the MCU (and connected to the ESP-01’s serial lines). Advanced users have even reverse-engineered this design: the onboard MCU has been identified in community forums (either an STC15L101EW 8051-based MCU or a Nuvoton N76E003 in some versions). This chip is factory-programmed to handle the relay control protocol and possibly the default WiFi configuration mode. While it is technically possible to reprogram this MCU as well, most DIYers find it unnecessary – you can simply replace the ESP8266’s firmware and send the right serial commands to leverage the existing MCU firmware.
In summary, the internal architecture is cleverly designed for cost and functionality: a cheap WiFi module adds connectivity, and a cheap microcontroller adds I/O expansion and control for multiple relays. This separation also means that the relay states persist through WiFi resets or firmware updates, since the MCU will keep the relays in their last commanded state unless instructed otherwise. This is a nice feature; for example, if you reboot the ESP8266 or update its code, your connected appliances won’t inadvertently flicker on/off during that process (a common issue when relays are directly tied to an ESP8266’s GPIOs).
Wiring Guide and Understanding NC/NO Relay Outputs
One of the key aspects of using this 4-channel relay module is wiring it correctly for your application. Let’s break down the important connections and how to hook up devices:
- Powering the Board: As noted, you must supply a stable 5V DC to the module. Connect your 5V positive to the pin labeled IN+ and ground to IN- on the board. Important: If you plan to switch high-voltage (mains) devices, do not power this board directly from mains! Use a proper AC-to-DC adapter (e.g., a 5V phone charger or a buck converter) to provide the 5V input. The board does not have a built-in mains transformer, which is why it’s smaller and cheaper – but it means the responsibility is on you to provide safe power. There is a reverse-polarity protection diode on the input in some designs, but always double-check polarity when connecting 5V (IN+ is +5V, IN- is ground).
- Relay Outputs: The four relays are usually labeled as K1, K2, K3, K4 on the PCB, each with three output terminals: NO, COM, and NC. NO stands for Normally Open, and NC stands for Normally Closed. These terms describe the default state of the relay’s switch contacts when the relay coil is not energized (i.e., when the relay is “off”). In a resting state, a normally open (NO) contact is open (no connection between COM and NO), meaning no current flows through. When the relay activates, the NO contact closes, allowing current to flow. Conversely, a normally closed (NC) contact is closed in the resting state (COM and NC are connected when the relay is off), so current can flow by default; when the relay activates, the NC contact opens and breaks the circuit.
- Using NC vs NO: Which contact you use depends on the desired fail-safe behavior of your device. For example, if you’re controlling a lamp that you want off by default and only on when the relay is triggered, you would wire the lamp through the NO contact (so it gets power only when the relay closes). On the other hand, for something you want powered by default and to turn off when activated (rare, but an example might be certain safety or emergency systems), you’d use the NC contact. In typical smart home scenarios, NO is more commonly used (lights, fans, etc. are usually off until turned on). Each relay’s COM (Common) terminal is the shared connection that switches between NC and NO. So to wire a device, you connect your power source to COM, and the device’s input to either NO or NC, then the other side of the device back to the other side of the power source to complete the circuit.
- Example Wiring (AC load): Suppose you want to control a ceiling light. You could wire the live (hot) AC line through the relay: connect the AC live/hot wire to the COM terminal of a relay, then connect the lamp’s live lead to the corresponding NO terminal of that relay. The neutral wire of the lamp goes straight to the AC neutral. In this configuration, the lamp is off by default (circuit open). When you activate the relay via WiFi, the COM–NO connection closes, connecting the lamp to live and turning it on. If instead you used the NC terminal, the lamp would be on by default and turn off when the relay triggers – not typical for a light, but useful for fail-safe systems as mentioned. Always ensure all high-voltage connections are insulated and secure, and if you’re not experienced with mains wiring, get help or use a low-voltage setup for practice.
- Multiple Relays and Common Ground: Each relay output is isolated from the others (they do not share common terminals), which offers flexibility – you can switch four completely separate circuits (they can even be a mix of AC and DC, as long as each is within the relay’s ratings). The module’s low-voltage side (ESP8266 and MCU) shares a common ground internally. If you connect external sensors or a different controller to the module’s UART header (5V, GND, TX, RX pins), make sure to common-ground them appropriately. However, in most cases, you won’t need to mess with the UART pins unless programming.
In short, NC and NO give you the choice of how each relay behaves in its normal state. Most projects will use the NO (normally open) contacts for devices that should be off unless switched on. The availability of both gives you flexibility for more advanced wiring setups (for instance, “hotel mode” or interlock circuits where two switches control one load or ensuring something turns on if the control system fails). In fact, enthusiasts have noted that having NC/NO on each relay “makes this board ideal for hotel (or failsafe) wiring setups,” since you can design circuits that default to a safe state.
Comparing to Sonoff and Tuya Smart Relays
It’s worth comparing this DIY relay module with some commercial smart relay products:
- Cost and Openness: The most obvious advantage is cost. A Sonoff 4CH (4-channel) smart switch, for example, might cost around \$25–\$30, whereas an ESP-01 relay module board can cost well under \$10. Tuya-based 4-channel relays similarly tend to be in the \$20+ range. You can assemble an equivalent or better solution for a fraction of that price with this module and a spare USB charger for power. Moreover, Sonoff and many Tuya devices come with closed-source firmware that connects to their respective cloud services. If you use them as-is, you’re often dependent on an internet connection and the manufacturer’s app (e.g., eWeLink for Sonoff, or Tuya Smart Life app) to control your devices. By contrast, using the ESP8266 relay module with open-source firmware means no cloud dependency – your commands can stay entirely local (for privacy, speed, and reliability). You’re free to install ESPHome, Tasmota, ESPEasy, or write your own code, without any arbitrary restrictions.
- Hardware Differences: Commercial units like the Sonoff 4CH Pro typically include a built-in AC/DC power supply and come in a nice enclosure, ready to wire into a DIN rail or wall mount. The ESP-01 relay board is a bare PCB, so you will need to provide a 5V supply and likely mount it in a project box for safety if using with high voltage. Sonoff devices often have additional features like physical buttons, RF receiver (in the 4CH Pro R3, for instance), and certifications for electrical safety. The DIY board, on the other hand, has the basics (you do get two on-board buttons for mode and reset, and LED indicators). When it comes to relays themselves, both the Sonoff 4CH and this DIY module use 10A-rated relays, so in terms of pure switching capability, they are similar. The ESP8266 chip is actually at the heart of many Sonoff/Tuya products too (often an ESP8285, which is an ESP8266 variant). So, under the hood, the performance and wireless capabilities are comparable. The difference is mainly in how the device is packaged and the firmware it comes with.
- Ease of Hacking/Customization: With the ESP-01 module, you have a removable, breadboard-friendly controller that you can program using standard tools. Sonoff and Tuya devices can also be flashed with custom firmware, but it sometimes requires opening the case, soldering to tiny pins, or using exploits like Tuya-Convert (which may or may not work on newer firmware versions). In contrast, this relay board was practically made for DIY – you pull out the ESP-01, drop it into a USB-to-serial adapter, and flash away. Both approaches end up giving you similar end results (e.g., you can run ESPHome on a Sonoff 4CH or on this board), but the barrier to entry is lower with the ESP-01 module for a hobbyist.
- Flexibility: If you only need one or two relays, a Sonoff Basic (one channel) or Dual (two channel) might be alternatives, but then you’d need multiple units for four circuits. The 4-channel ESP8266 board gives you four switches in one unit, which is great for controlling multiple points (say, four different lights) with a single device on your network. Tuya also makes multi-relay boards, but again they often assume cloud use unless you flash them. Another neat point in favor of this DIY board is the previously mentioned MCU handling the relays – for example, during an OTA (over-the-air) update of the ESPHome firmware, the relays won’t change state. In a Sonoff running custom firmware, it’s standard practice to implement some code to avoid relay flicker during reboots, but it can still happen if not managed carefully. The isolation of function in the ESP-01 module design inherently avoids that issue.
When to choose DIY vs Commercial? If you enjoy tinkering and want maximum control and transparency, the ESP8266 4-channel relay module is a fantastic choice. It shines in a local, MQTT- or Home Assistant-based setup, where you define exactly how it behaves. It’s also excellent for learning: you get hands-on with wiring and microcontroller programming. On the other hand, if you prefer a ready-made solution with a case and safety certifications (and you don’t mind using or replacing the stock firmware), a Sonoff 4CH or similar Tuya device might be convenient. Some users actually use both – for critical or high-power applications they might use a UL-certified Sonoff in a breaker box, whereas for DIY projects on a bench or a hobby project (like automated irrigation, Christmas light control, etc.), they use the ESP-01 relay board where they can experiment freely.
In summary, the ESP8266 ESP-01 relay module offers an unbeatable combination of price and openness. It’s a bit of a “diamond in the rough” – you need to add a little polishing (i.e. custom firmware and a proper housing), but once set up, it can perform on par with, or even exceed, the functionality of branded smart switches, all while keeping you in control of your device.
Wiring to an ESP8266 and Programming (ESPHome Integration)
To unlock the full potential of this module in your Home Assistant setup, you’ll want to flash the ESP-01 with ESPHome (or another firmware of your choice). Here’s a general guide to wiring and programming the ESP-01 for ESPHome, followed by how to configure it in Home Assistant:
Flashing the ESP-01: The ESP-01 module must be removed from the relay board for programming. You’ll need an ESP8266 USB-to-UART adapter (or any USB-to-Serial converter plus some jumper wires) to flash it. Connect the ESP-01 to the programmer as follows:
- ESP-01 VCC → 3.3V output of your USB serial adapter (important: use 3.3V, not 5V, or you will damage the ESP8266).
- ESP-01 GND → GND of the adapter.
- ESP-01 TX → RX of the adapter.
- ESP-01 RX → TX of the adapter.
- ESP-01 CH_PD (EN) → 3.3V (ensure the chip enable pin is pulled up).
- ESP-01 GPIO0 → GND while resetting or powering on (this puts the ESP8266 into bootloader mode for flashing).
Some adapters have a toggle or a way to enter programming mode; otherwise, you can use a jumper on GPIO0 to GND, then reset the module (or power cycle) to initiate programming mode. Once wired, use the esphome-flasher tool or ESPHome’s built-in flashing via USB to upload your firmware. You’ll do this step only once; after you have ESPHome on the device, future updates can be done over Wi-Fi (OTA).
ESPHome Configuration: In your ESPHome YAML configuration for this board, you will use the UART component to communicate with the relay controller MCU. As shown by community examples, the ESP-01’s UART (TX on GPIO1, RX on GPIO3) should be initialized at 115200 baud to match the MCU’s expected baud rate. You’ll also want to disable the ESPHome logging over serial (set logger: baud_rate: 0) so that debug logs don’t interfere with the UART commands.
Each relay can be controlled by sending a specific hex command over UART. In ESPHome, you can configure template switches or uart switches that send these bytes. For example, a template switch’s turn_on_action could write [0xA0, 0x01, 0x01, 0xA2] to turn on Relay 1, and turn_off_action would send [0xA0, 0x01, 0x00, 0xA1] to turn it off. You would do similarly for relays 2, 3, and 4 with the appropriate codes (as listed earlier). The community-contributed ESPHome configs show that you can also use the UART Switch platform for a slightly cleaner approach in newer ESPHome versions.
Here’s a simplified example of what an ESPHome YAML might look like for this board:
esphome:
name: esp01_relay_board
platform: ESP8266
board: esp01_1m
wifi:
ssid: “YourWiFi”
password: “YourPassword”
# … (WiFi setup, static IP if desired)
logger:
baud_rate: 0 # Disable logging over serial (free UART for MCU comm)
api:
encryption:
key: “YOUR_API_KEY” # if using encrypted API
ota:
password: “YOUR_OTA_PASSWORD”
uart:
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 115200
switch:
– platform: uart
name: “Relay 1”
data_on: [0xA0, 0x01, 0x01, 0xA2] # Command to turn relay 1 ON
data_off: [0xA0, 0x01, 0x00, 0xA1] # Command to turn relay 1 OFF
– platform: uart
name: “Relay 2”
data_on: [0xA0, 0x02, 0x01, 0xA3]
data_off: [0xA0, 0x02, 0x00, 0xA2]
– platform: uart
name: “Relay 3”
data_on: [0xA0, 0x03, 0x01, 0xA4]
data_off: [0xA0, 0x03, 0x00, 0xA3]
– platform: uart
name: “Relay 4”
data_on: [0xA0, 0x04, 0x01, 0xA5]
data_off: [0xA0, 0x04, 0x00, 0xA4]
A few notes on the ESPHome setup:
- We used esp01_1m as the board type, since most ESP-01 modules have a 1MB flash. If your ESP-01 is a newer ESP-01S with 1MB, this applies as well. If by chance you have a 512k flash module, you’d adjust settings or use a minimal build.
- The uart section defines the hardware serial interface to talk to the MCU. The ESP-01’s GPIO1 is TX (transmit) and GPIO3 is RX (receive). The MCU only needs the ESP to send it commands (and possibly it might send responses, but in this use-case we often don’t even need to read responses). The baud_rate 115200 is derived from documentation and community configs, it’s the speed the MCU’s firmware listens on. (If for some reason your module doesn’t respond, try 9600 baud, as some users have reported needing that – it could depend on the MCU firmware version, though 115200 is most common).
- We configured four UART-based switches. Each has a human-friendly name (“Relay 1” etc.) and the data bytes to send on on/off. These hex codes came from the module’s documentation. The checksum byte (last byte) is the sum of the first three bytes modulo 256. If you use exactly the commands above, they should work as-is.
- You might have noticed we didn’t configure the ESP8266’s GPIO pins to any relays – that’s because, as explained, the GPIOs aren’t wired to the relay directly. Everything goes through UART commands. This is different from typical relay boards where you set a pin high/low. Here, the advantage is you could easily expand to more relays (if the MCU had them) with just software commands, no re-wiring.
- You can certainly expand the YAML to include things like status feedback if the MCU provided it. The default MCU might not spontaneously send the relay state, so we rely on optimistic: true (not shown above) or just assume the command worked. In practice, the commands are very reliable. If needed, one could use the UART text sensor in ESPHome to listen for any confirmation bytes from the MCU (for instance, it might echo back something), but the community configs often keep it simple.
Once you have compiled and flashed this ESPHome firmware to the ESP-01, you can put the ESP-01 module back into the relay board’s socket. Power up the board (5V to IN+/IN-). The ESP8266 will boot, connect to WiFi, and then you can add it to Home Assistant:
Home Assistant Integration: If you enabled the native API in ESPHome (api:), the device will automatically be discoverable by Home Assistant. Home Assistant will see something like esp01_relay_board on the network. You can then add it, and the four switches we defined will show up as entities (e.g., switch.relay_1, switch.relay_2, etc., or with the names you gave). You can control these from Home Assistant’s UI, include them in automations, expose them to Alexa/Google (via HA integrations), etc. Because everything runs locally, the responsiveness is typically instantaneous on your LAN.
For those who prefer MQTT, you could omit the ESPHome API and use the MQTT client component in ESPHome to have the device publish relay states and subscribe to commands. It’s a matter of preference; the ESPHome native API is very convenient with Home Assistant. In either case, you’ve now essentially transformed this $8 piece of hardware into a fully integrated smart home device!
Conclusion
Using the ESP8266 ESP-01 4-Channel WiFi Relay Module is a rewarding way to build your own remote control switch for home automation. You’ve learned that this board offers a rich set of features – four high-current relays, an ESP8266 for WiFi, an onboard MCU for reliable control, optocouplers for safety, and flexibility in power and wiring – all at a budget-friendly price. It embodies the spirit of DIY: with a bit of effort (flashing custom firmware and proper wiring), you get a device that rivals commercial smart switches in capability.
In comparison to closed-source solutions like Sonoff or Tuya, this DIY module stands out as open, customizable, and cost-effective. You aren’t tied to any specific app or cloud service, and you can integrate it seamlessly with Home Assistant via ESPHome, enjoying features like OTA updates, local control, and complex automation integration. The inclusion of both NC and NO contacts on each relay gives you wiring options for failsafe designs that many off-the-shelf smart relays also provide, but here you have full control over how it’s used.
Whether you’re a DIY hobbyist looking to automate lights, pumps, doors, or an IoT enthusiast experimenting with ESP8266 projects, the ESP-01 relay module is a fantastic platform to build on. It’s cheaper than many proprietary alternatives yet doesn’t compromise on core functionality. By leveraging the power of ESPHome and Home Assistant, you can create a secure, private, and feature-rich smart home system with this module at its core.
In this post, we’ve covered what the module is and its specs, examined the internal circuitry and how to wire it up (and explained those NC/NO terms), and walked through integrating it with ESPHome/Home Assistant. Armed with this knowledge, you can confidently set up your own multi-channel WiFi switch and start automating your home – without breaking the bank and while staying in complete control of your devices. Happy building!
Bonus: 3D Model Enclosure for ESP8266 4-Channel WiFi Relay Module:
Top Lid: https://bababuilds.com/3DModels/4CH-ESP8266-Relay/LC_4CH_Relay_Lid_V1.3mf
Enclosure Box: https://bababuilds.com/3DModels/4CH-ESP8266-Relay/LC_4CH_Relay_Box_V1.3mf