IoT Home Automation With ESP8266 and NodeRed + MQTT

by puneet1984 in Circuits > Electronics

65 Views, 0 Favorites, 0 Comments

IoT Home Automation With ESP8266 and NodeRed + MQTT

screen1.jpg

Everyone loves to sit on the couch and get things done with voice commands, it's like the dream come true which we have all seen in only movies or using the commercial IoT devices available in the market.

Today, we will get to see how to make at least few wishes to come true when it comes to getting basic electrical devices responding to our commands and wish with this DIY IoT WiFi Relay.

This project requires a fully populated PCB as per the schematic, esp8266 development board, installed and working copy of NodeRED and MQTT server on your home network.

To avoid any risk of hacking of the IoT devices i have not implemented controlling the devices over the internet. But this can be easily achieved using many online services available and also by using secured VPN and port forwarding.

Supplies

Esp8266 -1

resistor 1k -5

resistor 330 ohm -5

PC817 opto coupler -5

relay 5V -5

LED red -5

3-terminal connector -5

1n4007 diode -5

DHT11 module -1

1000UF capacitor -1

Schematic Design

Schematic_5 relay+esp8266-wifi V2_Sheet_1_20200213020732.png

I have used EasyEda to design the 2-layer PCB.

It’s easy and fun to use and has the footprint libraries of most of the components. If anyone wants i can always post the gerber files for you.

PCB Layout and Designing

PCB_5 RELAY+ESP8266-WIFI copy_20200213020807.png

Its a two layer PCB.

Signal traces are 0.3mm thick and Relay traces are 3 mm thick.

if you want you can increase the power trace size.

Ordering the PCBs

JLCPCB image.jpg
jlc3.jpg
JLc2.jpg

Now we have got the PCB design and it’s time to order the PCB’s. For that, you just have to go to JLCPCB.com , and click on “QUOTE NOW” button.

JLCPCB are also sponsor of this project. JLCPCB (Shenzhen JLC Electronics Co., Ltd.), is the largest PCB prototype enterprise in China and a high-tech manufacturer specializing in quick PCB prototype and small-batch PCB production.

You can order a minimum of 5 PCBs for just $2. To get the PCB manufactured, upload the gerber file you downloaded in the last step. Upload the .zip file or you can also drag and drop the gerber files. After uploading the zip file, you’ll see a success message at the bottom if the file is successfully uploaded. You can review the PCB in the Gerber viewer to make sure everything is good. You can view both top and bottom of the PCB. After making sure the PCB looks good, you can now place the order at a reasonable price. You can order 5 PCBs for just $2 plus shipping. To place the order, click on “SAVE TO CART” button.

My PCBs took 2 days to get manufactured and arrived within 20 days using standard registered post delivery option. There are fast delivery options also available.PCBs were well packed and the quality was really good.

JLCPCB is now offering SMT assembly service that too at a very reasonable price and after trying it I must say that they are doing excellent work and their craftsmanship is comparable to any other commercial PCB manufacturing and assembly service all over the world.

Their backend team is so efficient and through that they will check each and every design and component placement and will inform the customer about required changes in design or about wrong placement and polarity of the components and correct the minor issues at their end itself.

Esp8266 NodeMCU - Arduino Code

The ESP8266 code is attached along.

The code is only for a single room/board, to add more rooms and board, change the room number and light number as needed.

Running NodeRED and Code

nodered flow.png
boolean to number conversion.jpeg
temp conversion.png
switch properties.jpeg
mqtt broker node settings.png
mqqt out node.png
homekit node1.png
humidity conversion.jpeg
homekit node.png

You need to install NodeRED and MQTT on a server to be run 24X7. I have installed both of them on my RaspberryPi.

The nodeRED workflow code in XML and Graphical workflow is attached for your reference.

prerequisites for NodeRED to work

1) dashboard UI

2) Home kit if using iphone

The humidity and temperature readings from the ESP8266 has to be converted to nodered syntax and I have included the screenshots for them.

The homekit gives results in boolean and conversion to number is required and have included the code to get this done.

similarly to get proper results for temperature and humidity for homekit, the readings from DHT11 sensor is required to be processed before entering in the homekit, the code is included.

Downloads

Assembly and Working

screen1.jpg
DIY Esp8266 home automation with NodeRED and MQTT broker

The PCB design is totally through hole and thus its easier to assemble at home using minimum tools.

Remember to use only red LEDs for indication as the Vf of other colours is different and thus the optocoupler will not work.

Take care regarding the ratings of the relays and electrical load you are putting on them, mine are rated for upto 2.5KW AC (250V @ 10A) which i highly doubt.

The input voltage should be 5V DC with minimum of 2 Amps capacity if you want to engage all 5 relays simultaneously.

Please checkout the demo video on the youtube.