5V ESP8266 WiFi Relay Module Documentation
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.
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++)
| 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 |
### 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.
5V ESP8266 WiFi Relay Module
Power supply (5V, 10A)
Computer or mobile device with internet connection
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.
5V ESP8266 WiFi Relay Module
DHT11 temperature and humidity sensor
LED
Breadboard and jumper wires
Power supply (5V, 10A)
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.