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 a NodeMCU and relay module. Or you can also use a custom-designed PCB for this project.
Required Components:- NodeMCU board
- 4-channel SPDT 5V Relay Module
- Push Buttons
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.
Required Components for the PCB1. Relays 5v (SPDT) (4 no)
2. BC547 Transistors (4 no)
3. PC817 Optocuplors (4 no)
4. 510-ohm 0.25-watt Resistor (4 no) (R1 - R4)
5. 1k 0.25-watt Resistors (5 no) (R5 - R9)
6. LED 5-mm (5 no)
7. 1N4007 Diodes (5 no) (D1 - D5)
8. Push Buttons (4 no)
9. Terminal Connectors
10. 5V DC supply
Required Software:1. Arduino IDE
2. IoT OnOff app
Circuit Diagram of the NodeMCU Home Automation ProjectThis 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.
Here, the D3 pin should not be connected with GND during the booting process of NodeMCU.
MQTT Control Relay With Reyax & IoT ON OFF AppIf the NodeMCU is connected with WiFi, then you can control the home appliances from the"IoT OnOff" app or any other MQTT client.
Here I have used Reyax RYC1001 as an MQTT broker and the"IoT OnOff" 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 clients.
You can control, monitor the real-time status of the relays from anywhere in the world.
Control Relays Manually With SwitchesYou 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 SystemTo 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=1Jx4D_DSV_ei1y0a82AbtxbsNhy8sjCmY
Then order the PCB from PCBWay.com
About PCBWay and Its ServicesPCBway 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.
Steps to order PCB from PCBWayTo order the PCB first visit PCBWay.com.
Then enter the following details:
- PCB Size (Length & Width) and PCB quantity.
- Select the masking color for the PCB.
- Select country and shipping method.
- Click on the "Save to Cart" button.
After that, click on the "Add Gerber Files" to upload the Gerber file.
Then 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 PCBAfter that, I have soldered all the components as per the circuit diagram.
Then connect the NodeMCU board with the PCB.
What Is MQTT? How does It work?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 ClientIn this project, I have used Reyax RYC1001 MQTT broker.
You can use any other MQTT broker.
And the IoT OnOff app and NodeMCU will act as MQTT clients.
In the tutorial video, I have explained how to configure the MQTT broker and how to publish and subscribe to any topic.
Program ESP8266 NodeMCU Using Arduino IDEDownload the code from the following link
https://drive.google.com/file/d/1lq85h5uBk9WkbzzxIPRJM-f3PhWlcLo4/view?usp=sharing
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 SupplyTurn on the 110V/230V supply and 5V DC supply.
Finally!! the Smart Home System Is ReadyNow 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.
Comments