loading

The Node MCU is an open source ESP8266 based Wifi enabled IoT platform for everyone. What we have done is created a four relay board for it and the coolest part is that board also has a 100-240V-AC to 5V-DC Power supply on board so you will be able to connect it directly to AC mains while creating a Wifi enabled switch board. It also has a header where you will be able to connect i2c based devices(Something like an I2C based OLED ) although we will still need to test this .

A brief specification of the board is as mentioned below

  • It comes with a header where you can plug in Node MCU Module .
  • Four Relays to connect four AC/DC loads and both NC/NO connectors of the relay are provided
  • SSID and Password can be set directly from the mobile app
  • Can be pre-programmed with MQTT for Networking/Home automation integration.
  • 100-240VAC or 5VDC select able input.
  • LED for Testing which is connected to a GPIO and also as indicator when the relay go on /off
  • Dimensions of the board are 145 X 60 X 18 mm

Step 1: Wiring the Relay Board to Four Two Way Switches and Four 3 Pin Sockets

I have created a few diagrams to help you out with the wiring .The first diagram is a logical diagram .You will find on one side a red colored vertical line that is the AC phase/Line and on the right there is another vertical line which is the neutral. On the four relay board both NC (Normally Closed Circuit) and NO (Normally Open Circuit) of the relay are available. The two way switch has three terminals - NC, NO, Common and is usually as shown in one of the diagrams.The reason for using a two way switch is to have both physical as well as using you mobile phone to turn on/off some appliance.

The logical diagram shows how the connections are made. Let me show you the status and the load condition based on the status of relay and the switch

Relay Switch Load Relay & Switch

NO NC NO NC Status Status

0 1 0 1 OFF BOTH OFF

1 0 0 1 ON RELAY ON

1 0 1 0 OFF BOTH ON

0 1 1 0 ON SWITCH ON

I hope this is clear. The load here in my case will be the three pin socket you may also connect the load(Fan, TV, light etc) directly but make sure you take appropriate measures while connecting to the main .

Step 2: TCP/IP Based Android - Arduino Code to Control the Switch Board

You can find both android app and the arduino code on our GITHUB page

I have shared some images and video for your understanding

The initial set up is simple just install the apk on your android phone

Search for ESP/AI-Tinker Hot spot on your phone.Connect to it. After that start the app Wifi Four Relay board

Enter 192.168.4.1 in the ip text box

Enter 80 in the port text box and then press connect .Here you will find four buttons you can click it and the light/load should turn on/off

If you want to connect it to your wifi router without changing the program you will need to send the following command

SSID:xxxx:yyyy:

xxxx will be your Wifi SSID

yyyy will be your Wifi Password

Step 3: Mqtt Basic

MQTT (Message Queuing & Telemetry Transport) is a publish-subscribe based "light weight" messaging protocol for use on top of the TCP/IP protocol.
It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker(Some thing like a server). The broker is responsible for distributing messages to interested clients based on the topic of a message.

For details you can visit this site http://mqtt.org/

In My application I have used a board called Onion Omega

Its a good board if you wish to install just the MQTT Broker but if you wish to develop a full fledged Home automation system I suggest you do it using Raspberry Pi and Open HAB

Onion Omega runs a flavor of linux called Open WRT (Its a custom Linux flavor which is popularly used on many routers) .You will need to install the broker on this using terminal via ssh (Use Putty on Windows)

Refer this link to install MQTT broker Mosquitto on OpenWRT

http://mosquitto.org/2011/08/mosquitto-on-openwrt/

Here are the steps

opkg update
opkg install mosquitto mosquitto-client libmosquitto

This will install the broker and client on Onion Omega. After it installs you can try simple commands using two terminal /putty windows.On one of the window/terminal just type

mosquitto_sub -d -t msg/box

And on the other just type

mosquitto_pub -d -t msg/box -m "Hello World"

you should get "Hello World" on the other first window(Where you entered mosquitto_sub -d -t hello/world).

Here "msg/box" is called a Topic this can be any thing (eg. can be sensor/analog or sensor/digital or RelayControl etc) .One can either subscribe to a topic(first command did that) or can publish to a topic(second command published "Hello World" to the topic msg/box) once that is sent to the broker all the devices will receive message "Hello World" if and only if they have subscribed to that topic.

Also note if you are using some other device where your broker is not installed on you will need to add the broker ip in the command as shown below

mosquitto_sub -h YOUR_BROKER_IP -d -t msg/box

mosquitto_pub -h YOUR_BROKER_IP -d -t msg/box-m "Hello World"

Step 4: MQTT Code and Linking It With Other Devices Like Onion Omega or Pi

Please Watch the video to get some idea

What I am trying to achieve here is I have two types of Esp8266 based board one is the node mcu four relay board and the other is Attiny85 +Esp-01 based board ,both of them should communicate with each other through the broker .You can refer to this instructable for details regarding the Attiny85+Esp-01 Board.I have loaded both with MQTT client code.

Attiny85+Esp-01 Board has an additional gpio free which I have used and have connected a PIR sensor .One of the image will show how the box looks.

The Broker is installed on Onion Omega which runs Open WRT .

The preferred android mobile app is My Mqtt but most of it is text based . I also do have a modified app but its is not full proof. Will upload the code once it is usable

Here are the commands I have integrated

+ATon --will turn on the relay of the Attiny85 +Esp-01 board

+AToff --will turn off the relay of the Attiny85 +Esp-01 board

+ATstatus --Will give you the status of the PIR sensor (High /Low)

+ATstart ---Will start notifying to the topic "Relay_Control" change in status of the PIR sensor (you will receive PIR HIGH ,PIR LOW message on your mobile ) .It also turns on/off the relay of the Attiny85+ Esp-01 board

+ATstop ---This will stop the above notification and also makes the relay independent from the PIR sensors output

R4_ON ---Node MCU four relay boards first relay turns ON

R12_ON---Node MCU four relay boards second relay turns ON

R13_ON ---Node MCU four relay boards third relay turns ON

R14_ON ---Node MCU four relay boards fourth relay turns ON

R5_ON ---Node MCU four relay boards led turns ON

R5_OFF ---Node MCU four relay boards led turns OFF

R4_OFF---Node MCU four relay boards first relay turns OFF

R12_OFF---Node MCU four relay boards second relay turns OFF

R13_OFF--Node MCU four relay boards third relay turns OFF

R14_OFF ---Node MCU four relay boards fourth relay turns OFF

the number attached to R represents Gpio on nodemcu/esp

The above commands can also be sent or see by publishing or subscribing from a mqtt client machine using the below command

mosquitto_sub -h YOUR_BROKER_IP -d -t Relay_Control // to subscribe to Relay_Control Topic

mosquitto_pub -h YOUR_BROKER_IP -d -t Relay_Control -m "xxx" //to send commands to Relay_Control Topic

xxx here will be any of the previously mentioned commands eg off01, on01 etc

plz make sure you have installed at least mosquitto-client, libmosquitto packages on the client computer

I will still need some time to update the content will do that as I develop the application .As of now just posting it .If you have any question plz do comment and probably I will modify the instructable to clarify your doubts

Thank you

Step 5: Safety Warning

Safety Warnings

You probably already know all this but in the interest of your safety, we feel compelled to state all this clearly. So take a few minutes to read it carefully .

AC mains are very dangerous -- Even a 50 V AC supply is more than enough to kill you. Please switch off the mains before making or changing connections, be very very careful.If your are not sure of anything related to the Ac supply lines please call an electrician ask him to help you our with it . Do not attempt to interface to mains unless you have adequate training and access to appropriate safety equipment. Never work on high voltages when you are alone by yourself. Always ensure that you have a friend/partner who can see and hear you and who knows how to quickly turn off power in case of an accident. Use a 1A Fuse in series with the input to the board as a safety measure. Basic Wiring diagram is available on our instructables page and github. Please go through it. If you are not very sure on how to wire it but wish to play with it use and external 5V DC 1Amps adapter with a micro usb connector and connect it to the boards micro usb connector to power the board on . Test it by configuring the board (Youtube Link https://www.youtube.com/watch?v=imY7AlIaPLQ ) and triggering the relays without any load Also use appropriate external snubber circuits on connecting inductive loads

Fire Hazard:

Making wrong connections, drawing more than rated power, contact with water or other conducting material, and other types of misuse/overuse/malfunction can all cause overheating and risk starting a fire. Test your wiring and the environment in which it is deployed thoroughly before leaving it switched on and unsupervised. Always follow all fire safety precautions.

<p>it is not helpfull :(</p>
<p>hello armtronix,</p><p>Can i show status of light bulbs in mobile app?</p>
<p>Two way communication is possible through this board .when on or off <br>through physical switch then any notification message in mobile.</p>
<p>The electrical box says &quot;Oreva&quot;. Where did you get this box? I tried to find a similar box in the U.S., but could not find any.</p>
<p>we can provide it or you can get it form the manufacturer</p>
<p>Awesome..!</p>
<p>Can someone please provide me with the PCB design schematics for this project?? </p>
Related documents that can be shared<br>https://github.com/armtronix/NodeMCU_four_relay_board
<p>There's another Instructables that shows how to create an IoT holiday light controller using this board: https://www.instructables.com/id/Arduino-ESP8266-IoT-Light-Controller/</p>
can you please clear the connection because i cant understand the electrical connection properly.<br>
<p>Can u connect it to the WiFi and use it with Blynk?</p>
<p>Blynk https://www.youtube.com/watch?v=cbLxlekzt9I</p>
<p>Yes you should be able to do that as their site shows esp8266 support but I haven't tried it </p>
<p>Hi,</p><p>How do you make remember the state of each relay to ESP on unexpected restart?</p><p>Thank You</p>
<p>Any resets when switching AC inductive loads?</p><p>Please post schematic of Relay board if available</p>
<p>if you are using esp-01(blue colour pcb) or a very old esp yaa it resets as there is no bypass cap if you want to prevent it on esp 01 cut the reset pin and solder a cap 0.1uf to reset pin and ground of esp01 . If not try using rc snubbers across the load ideally for ac loads 0,01 Ac cap with some 30-40 E resistor </p>
<p>Hi,</p><p>Great project!!!</p><p>Can you give me details of that converter block you have used..</p>
<p>Nice project</p><p>Checkout my android app for the same purpose and having connectivity with cloud broker. May be useful to you.</p><p>https://www.instructables.com/id/Home-Automation-Using-MQTT-and-NodeMcu-or-Arduino/</p>
<p>Simply Aswm .....can u control this via cloud connecting?</p>
<p>Yes it should be possible</p>

About This Instructable

37,527views

75favorites

License:

More by Armtronix:OpenHAB http binding with Armtronix Dimmer/Speed Control Board  Accessing Devices Connected to Router From Remote Place (using Pi and OpenHab) How to Configure Static IP Address for Raspberry Pi 
Add instructable to: