Stufin
Home Quick Cart Profile

5V ESP8266 WiFi Relay Module

Buy Now on Stufin

Pin Configuration

  • 5V ESP8266 WiFi Relay Module Pinout Explanation
  • The 5V ESP8266 WiFi Relay Module is a compact and versatile board that combines the power of ESP8266 WiFi capabilities with relay control. Here's a detailed explanation of each pin on the module:
  • Pinout Structure:
  • The module has a total of 14 pins, divided into two rows of 7 pins each. The pins are labeled as follows:
  • Left Row (from top to bottom):
  • 1. VCC: 5V Power Input
  • Description: This pin is used to power the module with a 5V DC voltage source.
  • Connection: Connect to a 5V power supply or a battery with a suitable voltage regulator.
  • 2. RxD: Receive Data (UART)
  • Description: This pin is used for receiving data from a serial communication device, such as a computer or another microcontroller.
  • Connection: Connect to the transmit (TX) pin of a serial communication device.
  • 3. TxD: Transmit Data (UART)
  • Description: This pin is used for transmitting data to a serial communication device.
  • Connection: Connect to the receive (RX) pin of a serial communication device.
  • 4. D3: GPIO3 (Digital Input/Output)
  • Description: This pin can be used as a digital input or output for various applications, such as controlling external devices or reading sensor data.
  • Connection: Connect to a digital device, sensor, or module as required by the application.
  • 5. D2: GPIO2 (Digital Input/Output)
  • Description: This pin can be used as a digital input or output for various applications, such as controlling external devices or reading sensor data.
  • Connection: Connect to a digital device, sensor, or module as required by the application.
  • 6. D1: GPIO1 (Digital Input/Output)
  • Description: This pin can be used as a digital input or output for various applications, such as controlling external devices or reading sensor data.
  • Connection: Connect to a digital device, sensor, or module as required by the application.
  • 7. GND: Ground
  • Description: This pin is the ground reference point for the module.
  • Connection: Connect to a reliable ground point or a common ground bus.
  • Right Row (from top to bottom):
  • 1. RELAY_1: Relay 1 Control
  • Description: This pin is used to control the first relay ( normally open/closed).
  • Connection: Connect to a digital output pin of a microcontroller or a suitable voltage source to control the relay.
  • 2. RELAY_2: Relay 2 Control
  • Description: This pin is used to control the second relay (normally open/closed).
  • Connection: Connect to a digital output pin of a microcontroller or a suitable voltage source to control the relay.
  • 3. CH_PD: Chip Enable (Power Down)
  • Description: This pin is used to enable or disable the ESP8266 chip.
  • Connection: Normally connected to VCC (5V) to enable the chip. Connecting to GND will disable the chip.
  • 4. RST: Reset
  • Description: This pin is used to reset the ESP8266 chip.
  • Connection: Connecting to GND will reset the chip. Normally connected to VCC (5V) during operation.
  • 5. EN: Enable
  • Description: This pin is used to enable or disable the ESP8266 chip.
  • Connection: Normally connected to VCC (5V) to enable the chip. Connecting to GND will disable the chip.
  • 6. Vin: Input Voltage
  • Description: This pin is used to input a voltage to the onboard voltage regulator.
  • Connection: Connect to a suitable voltage source (e.g., 5V or 3.3V) to power the module.
  • 7. GND: Ground
  • Description: This pin is the ground reference point for the module.
  • Connection: Connect to a reliable ground point or a common ground bus.
  • Important Notes:
  • Make sure to handle the module with care, as it is sensitive to static electricity.
  • Use a suitable voltage regulator or power supply to ensure a stable 5V power input.
  • When using the relays, ensure that the load voltage and current do not exceed the relay's specifications.
  • Follow the datasheet and application notes for the ESP8266 chip for proper usage and configuration.

Code Examples

5V ESP8266 WiFi Relay Module Documentation
Overview
The 5V ESP8266 WiFi Relay Module is a compact, low-cost Internet of Things (IoT) component that integrates a WiFi enabled microcontroller (ESP8266) with a relay module. This module allows users to control devices remotely using WiFi connectivity and provides a simple way to automate devices using the ESP8266's microcontroller capabilities.
Features
WiFi enabled ESP8266 microcontroller
 On-board relay module (max 5V, 10A)
 Supports HTTP, UDP, and TCP protocols
 Compatible with various programming languages (e.g., MicroPython, Lua, C++)
Pinouts
| Pin | Function |
| --- | --- |
| VCC | Power supply (5V) |
| GND | Ground |
| RX | Serial receive (TX on ESP8266) |
| TX | Serial transmit (RX on ESP8266) |
| S | Relay switch control |
| IN | Input for relay module |
Code Examples
### Example 1: Remote Relay Control using HTTP Requests
This example demonstrates how to control the relay module remotely using HTTP requests. We'll use a simple web server running on the ESP8266 to control the relay.
Hardware Requirements
5V ESP8266 WiFi Relay Module
 Power supply (5V, 10A)
 Computer or mobile device with internet connection
Software Requirements
MicroPython firmware installed on the ESP8266
 Web browser or HTTP client software (e.g., Postman)
Code
```python
import machine
import network
import urequests
# Initialize WiFi
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Your_WiFi_SSID', 'Your_WiFi_Password')
# Initialize relay module
relay = machine.Pin(4, machine.Pin.OUT)
# Create a simple web server
def web_server():
    while True:
        req = urequests.get('http://localhost:80/control')
        if req.status_code == 200:
            data = req.json()
            if data['cmd'] == 'on':
                relay.value(1)
            elif data['cmd'] == 'off':
                relay.value(0)
web_server()
```
How to use
1. Connect to the ESP8266's WiFi network using your computer or mobile device.
2. Send an HTTP GET request to `http://localhost:80/control?cmd=on` to turn on the relay, or `http://localhost:80/control?cmd=off` to turn off the relay.
### Example 2: Automatic LED Lighting Control using ESP8266 and DHT11 Sensor
This example demonstrates how to control an LED connected to the relay module using temperature and humidity data from a DHT11 sensor.
Hardware Requirements
5V ESP8266 WiFi Relay Module
 DHT11 temperature and humidity sensor
 LED
 Breadboard and jumper wires
 Power supply (5V, 10A)
Software Requirements
MicroPython firmware installed on the ESP8266
 DHT11 library for MicroPython
Code
```python
import machine
import dht
import time
# Initialize DHT11 sensor
d = dht.DHT11(machine.Pin(5))
# Initialize relay module
relay = machine.Pin(4, machine.Pin.OUT)
while True:
    # Read temperature and humidity data
    temp, hum = d.read()
    
    # Check if temperature is above 25C
    if temp > 25:
        # Turn on LED
        relay.value(1)
    else:
        # Turn off LED
        relay.value(0)
    
    # Wait 1 minute before taking another reading
    time.sleep(60)
```
How to use
1. Connect the DHT11 sensor to the ESP8266 as shown in the diagram.
2. Connect the LED to the relay module as shown in the diagram.
3. Power on the circuit and the ESP8266 will automatically control the LED based on the temperature reading.
These examples demonstrate the basic functionality of the 5V ESP8266 WiFi Relay Module. You can modify the code to fit your specific use cases and create more complex automation projects.