Home Automation with ESP8266 Web Server Relay Module
Home Automation with ESP8266 Web Server Relay Module
Home Automation with ESP8266 Web Server & Relay Module Control Appliances from Local Network
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
SPONSORED SEARCHES
circuit schematic schematic diagram
Today we will build Home Automation with ESP8266 Web Server & Relay Module Control Home
Appliances from Local Network. Using relays with the ESP8266 is the best way to remotely control AC
home appliances. This tutorial describes how to control the relay module with ESP8266 NodeMCU.
Basically, We will build a web server to see how the relay module works, how to connect relay to the
ESP8266, and control a relay (or as many relays as you want) remotely.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Home Automation with ESP8266 Web Server & Relay Module Control Appliances
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Ad
Made in the UK
We Are Here To Help You Get Your Project Started As Soon As Possible
Ad EasyDAQ Ope
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
IoT Based RFID Smart Door Lock System Using NodeMCU ESp8266
Introduction to Relays
A relay is an electrically operated switch. Usually, like any other switch, it can be turned on or off, with
or without current. It can be controlled through low voltages such as 3.3V provided by ESP8266 GPIOs
and helps to control high voltages. Such as 12v, 24V, or mains voltage ( 220V or 240V).
Types of Relays
In the market or Online shopping sites, different relay modules with different numbers of channels are
found. You can find relay modules with one, two, four, eight, and sixteen channels. The number of
channels determines the number of outputs we can control.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
There are some relay modules whose electromagnets can be powered by 5V and with 3.3V. Basically,
Both are usable with the ESP8266 – you can either use the Vin pin for 5V or the 3.3V pin.
Additionally, some come with a built-in optocoupler that adds an extra “layer” of protection, optically
isolating the ESP8266 from the relay circuit.
RFID Based Attendance System Using NodeMCU with PHP Web App
ESP8266 based IoT Health Care Panic Alarm for Elderly Folks
Relay Pinouts
For demonstration purposes, let’s see the pinout of a 2-channel relay module. However, the process of
using a relay module with a different number of channels are similar.
The two connectors (with three sockets each) on the left side of the relay module is for connecting high
voltage. Other pins on the right side (low-voltage) for connecting to the ESP8266 GPIOs.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
If you have one channel relay, you’ll have just one input pin. If you have 4-channels relay, you’ll have
4input pins, and so on.
The signal that we send to the IN pins, determines whether the relay is active or not. When the input
goes below about 2V The relay is triggered. This means that you’ll see the following conditions:
“ Note: we should use a normally closed configuration when the current is needed to be
flowing most of the time. And you want to stop it occasionally.
“ Similarly, use a normally open configuration when current should flow occasionally.
(For example: Turn on lamp or fan when required).
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Now, the second set consists of GND, VCC, and JD-VCC pins. The JD-VCC pin is used for powering
the electromagnet of the relay. In the above image, you can see a jumper cap connecting the VCC and
JD-VCC pins. My relay has a yellow cap, but you may have a different color.
By default, the VCC and JD-VCC pins are connected by the cap. which means, the relay electromagnet
is directly powered from the ESP8266 power pin. Hence they are not physically isolated.
Removing the Jumper cap, Nee independent power source to power up the relay electromagnet
through JD-VCC pin. Actually, this configuration physically isolates relays from NodeMCU. It has built-in
optocoupler to prevent ESP8266 damage in the case of electrical spikes.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Hence, the safest ESP8266 pins to interface with relays are: GPIO 5, GPIO 4, GPIO 14, GPIO 12 and
GPIO 13.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
“ Warning: in this example, we’re dealing with mains voltage. Misuse can result in serious
injuries. If you’re unknown with mains voltage, ask someone who can help you out. While
programming the ESP8266 or wiring your circuit, make sure you have disconnected
everything from the main voltage.
In this example, we’re controlling a bulb. We just want to light up the bulb occasionally, so it is better to
use a normally open configuration.
We’re connecting the Input 1 pin to GPIO 5, you can use any other suitable GPIO.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Home Automation with ESP8266 Web Server & Relay Module Control Appliances
Actually, this code will light up and OFF your bulb for 10 seconds. Which means the bulb will glow for
10 seconds and goes off for 10 seconds and respectively.
void setup() {
Serial.begin(115200);
pinMode(relay, OUTPUT);
}
void loop() {
// Normally Open configuration, send LOW signal to let current flow
// (if you're usong Normally Closed configuration send HIGH signal)
digitalWrite(relay, LOW);
Serial.println("Current Flowing");
delay(5000);
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
pinMode(relay, OUTPUT);
In the loop(), we send a LOW signal to let the current flow and light up the bulb.
digitalWrite(relay, LOW);
If you’re using a NC configuration, send a HIGH signal to light up the bulb. Then, wait 5 seconds.
delay(5000);
Stop the current flow by sending a HIGH signal to the relay pin connected to ESP8266. If you’re using
an NC configuration, send a LOW signal to stop the flow of current.
digitalWrite(relay, HIGH);
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
To build the above shown web server, we use the ESPAsyncWebServer library.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
“ Alternatively, Open your Arduino IDE, Go to Sketch > Include Library > Add.ZIP
library… and select the library you’ve just downloaded.
This is the easiest any simple method to add Libraries to your Arduino IDE.
The ESPAsyncWebServer library needs the ESPAsyncTCP library to work. Follow the same library
installation process to install this library.
After installing all the required libraries, Now, copy the below code to your Arduino IDE.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
// Set all relays to off when the program starts - if set to Normally Open (NO),
the relay is off when you set the relay to HIGH
for(int i=1; i<=NUM_RELAYS; i++){
pinMode(relayGPIOs[i-1], OUTPUT);
if(RELAY_NO){
digitalWrite(relayGPIOs[i-1], HIGH);
}
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
else{
digitalWrite(relayGPIOs[i-1], LOW);
}
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
void loop() {
#define NUM_RELAYS 5
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
“ Note: The number of relays set on the NUM_RELAYS variable should match the
number of GPIOs assigned in the relay pins array.
Network Credentials
Replace with your WiFi Network Credentials in these variables.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Demonstration
Now, after completing the coding part and made necessary changes. Its time to upload the code to your ESP8266
NodeMCU board using Arduino IDE.
Open the Serial Monitor at a baud rate of 115200. Now, Press the ESP8266 RST button to get its IP address.
Then, open a browser in your local network and type the ESP8266 IP address. You will now get access to the web
server.
Additionally, should get something as shown below with as many buttons as the number of relays defined in your
program sketch.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Home Automation with ESP8266 Web Server & Relay Module Control Appliances
Home Automation with ESP8266 Web Server & Relay Module -Demonstration
“ Note: Now, you can use the buttons to control your relays remotely using your smartphone,
laptop, or PC in your Local Network.
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Home Automation with ESP8266 Web Server & Relay Module Control Appliances
“ For a final project, make sure you place your NodeMCU board and relay module inside a
case to avoid any High voltage pins exposed.
Wrapping Up
I hope you have understood that it is a great idea to control home appliances using relays with the
ESP8266. So, this was the Home Automation with ESP8266 Web Server & Relay Module Control
Home Appliances from Local Network Projects. You can also read our other Guide to control RFID
Module With NODEMCU.
Controlling a relay with the ESP8266 is very easy as controlling LEDs from Webserver, you just need to
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
I hope you love this awesome NodeMCU based smart home automation system. If you have any doubts
or queries then do let me know in the comment section below.
Share this:
Twitter Facebook
Tagged Home Automation with ESP8266 Home Automation with ESP8266 Control Home Appliances
Home Automation with ESP8266 Web Server Home Automation with ESP8266 Web Server & Relay Module
Alsan Parajuli
https://theiotprojects.com/
RELATED POSTS
How Can IoT Help Within The IoT Based RFID Smart Door Lock IoT Based Flood Monitoring System
COVID-19 Crisis System Using NodeMCU ESp8266 Using NodeMCU & Thingspeak
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Pingback: Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors
Pingback: IoT Based RFID Attendance System using ESP32 | The IOT Projects
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Leave a Reply
Search … Search
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Magazin Robotica
RECENT POSTS
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
SPONSORED SEARCHES
relay circuit
espasyncwebserver relay
12v relay
CATEGORIES
Arduino Projects
Articles
Electronics Circuits
IoT Projects
Micro controllers
Raspberry Pi Projects
POPULAR
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Enter your email address to subscribe to this blog and receive notifications of new posts by email.
Email Address
Subscribe
Subscribe
Ad newchic.com More ▼
CATEGORIES
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Share this:
Twitter Facebook
Share this:
Twitter Facebook
Share this:
Twitter Facebook
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Share this:
Twitter Facebook
Ad deutschebahn.com More ▼
RECENT POSTS
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]
Home Automation with ESP8266 Web Server & Relay Module
Copyright 2020. All rights reserved. | The IoT Projects. Privacy Policy Disclaimer DMCA Advertise With us
https://theiotprojects.com/home-automation-with-esp8266-web-server-relay-module/[08.10.2020 12:33:04]