MQTT ESP8266 Home Automation Project 2021

by techstudycell in Circuits > Microcontrollers

3016 Views, 13 Favorites, 0 Comments

MQTT ESP8266 Home Automation Project 2021

vlcsnap-2021-07-05-18h38m26s832.png
vlcsnap-2021-07-05-18h40m13s768.png
vlcsnap-2021-01-17-19h59m11s931.png
thumb 11.jpg
MQTT ESP8266 NodeMCU Home Automation System with cheapest Cloud MQTT broker Reyax RYC1001 - IoT 2021

In this IoT project, I have shown how to make an MQTT ESP8266 Home Automation project to control a 4-channel relay module from the manual switch & smartphone.

During the article, I have shown all the steps to make this home automation system.

This NodeMCU ESP8266 control smart relay has the following features:

1. Control home appliances through the internet.

2. Control home appliances manually with pushbuttons.

3. Monitor real-time feedback on the smartphone.

So, you can easily make this home automation project at home just by using an ESP8266 NodeMCU and relay module. Or you can also use a custom-designed PCB for this project.

Supplies

You can make this project just by using NodeMCU and 4-channel relay module. But if you use PCB then you need the following components.

  • NodeMCU ESP8266
  • Relays 5v (SPDT) (4 no)
  • BC547 Transistors (4 no)
  • PC817 Optocuplors (4 no)
  • 510-ohm 0.25-watt Resistor (4 no) (R1 - R4)
  • 1k 0.25-watt Resistors (5 no) (R5 - R9)
  • LED 5-mm (5 no)
  • 1N4007 Diodes (5 no) (D1 - D5)
  • Push Buttons (4 no)
  • Terminal Connectors
  • 5V DC supply

Circuit Diagram of the NodeMCU Home Automation Project

vlcsnap-2021-06-06-19h21m04s477.png

This is the complete circuit diagram for this home automation project. I have explained the circuit in the tutorial video.

The circuit is very simple, I have used the GPIO pins D1, D2, D5 & D6 to control the 4 relays.

And the GPIO pins SD3, D3, D7 & RX connected with push buttons to control the 4 relays manually.

I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors.

I have used a 5V mobile charger to supply the smart relay module.

The D3 pin should not be connected with GND during the booting process of NodeMCU.

MQTT Control Relay With Reyax & IoT ON OFF App

vlcsnap-2021-07-05-18h55m47s977.png

If the NodeMCU is connected with WiFi, then you can control the home appliances from "IoT ON OFF" app or any other MQTT client.

Here I have used Reyax RYC1001 as an MQTT broker and "IoT ON OFF" app as an MQTT client, but you can use any other applications.

You can also use multiple smartphones to control the appliances. For that, you have to connect same MQTT broker. In this way, all smartphones will act as MQTT client.

You can control, monitor the real-time status of the relays from anywhere in the world.

Control Relays Manually With Switches

vlcsnap-2021-07-05-18h52m44s084.png

You can also control the relays from the pushbuttons.

You can monitor the real-time feedback on the phone.

Please refer to the circuit diagram to connect the pushbuttons

Design the PCB for This Smart Home System

vlcsnap-2021-01-17-19h58m26s121.png
vlcsnap-2021-01-17-19h58m40s950.png
vlcsnap-2021-01-17-19h58m50s543.png

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the smart relay module.

You can download the PCB Gerber file of this home automation project from the following link:

https://drive.google.com/uc?export=download&id=1Jx...

Then order the PCB from PCBWay.com

About PCBWay and Its Services

PCBWay1.JPG

PCBway manufactures various types of PCB boards at very affordable prices. They produce not only FR-4 and Aluminum boards but also advanced PCBs such as Rogers, HDI, Flexible and Rigid-Flex.

Visit pcbway.com/orderonline for the instant quote page. Aside from the basic visual inspection, all boards pass the most stringent tests at PCBWay.

In order to make sure the quality of the final product is good, a variety of inspection and testing equipment is used, such as a Flying Probe Tester, an X-Ray Inspection Machine, and an Automated Optical Inspection (AOI) Machine.

You can also explore their open source community to get different types of PCB projects with all required details pcbway.com/project/.

For more details please visit the following articles.

Why PCBway

Steps to Order PCB From PCBWay

PCBWay2.JPG
PCBWay3.JPG

To order the PCB first visit PCBWay.com.

Then enter the following details:

  1. PCB Size (Length & Width) and PCB quantity.
  2. Select the masking color for the PCB.
  3. Select country and shipping method.
  4. Click on the "Save to Cart" button.
  5. Click on the "Add Gerber Files" to upload the Gerber file.
  6. Click on the "Submit Order Now" to place the order for PCB.

After that, they will review the PCB Gerber file and accordingly confirm the order. I have used their services for my different electronics projects,

I always received the PCB on time and the quality is very good in this reasonable price range.

Solder All the Components on PCB

vlcsnap-2021-01-17-19h59m20s552.png
vlcsnap-2021-01-17-19h59m26s786.png
vlcsnap-2021-01-17-19h59m32s188.png

After that, I have soldered all the components as per the circuit diagram.

Then connect the NodeMCU board with the PCB.

What Is MQTT? How It Works?

vlcsnap-2021-07-05-18h45m10s167.png

MQTT is designed for high-latency, low-bandwidth, unreliable networks, it is a lightweight publish/subscribe messaging protocol built on top of the TCP/IP network stack. With MQTT, you can send a high volume of sensor messages to an analytics platform or cloud services.

In the tutorial video, I have explained in detail how we can send and receive data to control the relays with MQTT.

MQTT Broker & MQTT Client

vlcsnap-2021-07-05-18h56m41s315.png
vlcsnap-2021-07-05-18h57m30s006.png
vlcsnap-2021-07-05-18h57m21s253.png
vlcsnap-2021-07-05-18h47m24s395.png
vlcsnap-2021-07-05-18h50m35s224.png

In this project, I have used Reyax RYC1001 MQTT broker.

And the IoT OnOff app and NodeMCU will act as MQTT clients.

You can use any other MQTT broker.

In the tutorial video, I have explained how to configure the MQTT broker and how to publish and to subscribe to any topic.

Program ESP8266 NodeMCU Using Arduino IDE

vlcsnap-2021-07-05-18h45m22s174.png
vlcsnap-2021-07-05-18h45m56s942.png

First, download the code & install the PubSubClient library and ESP8266 board as mention in the code.

Then enter the WiFi credentials MQTT details

const char* ssid = "WiFi Name"; //WiFI Name
const char* password = "WiFi Password"; //WiFi Password
const char* mqttServer = "iot.reyax.com";
const char* mqttUserName = "Reyax_UserID"; // MQTT username

const char* mqttPwd = "Reyax_Password"; // MQTT password
const char* clientID = "EspClient00002"; // client id

Now select the NodeMCU 1.0 board and proper PORT.

Then upload the code to NodeMCU Board.

Turn ON the Supply

vlcsnap-2021-07-05-18h51m53s211.png

Turn on the 110V/230V supply and 5V DC supply.

Finally!! the Smart Home System Is Ready

vlcsnap-2021-07-05-18h39m13s519.png
vlcsnap-2021-07-05-18h38m40s542.png

Now you can control your home appliances in a smart way.

I hope you have liked this new ESP8266 MQTT home automation project. I have shared all the required information for this project.

I will really appreciate it if you share your valuable feedbacks. Also if you have any query please write in the comment section.

Thank you & Happy Learning.