Introduction: Home Automation Using MQTT and NodeMcu or Arduino

Picture of Home Automation Using MQTT and NodeMcu or Arduino

Home automation is a new buzz now a days ..there is so many open source hardware available to build your own home automation. So many tools, its easy to confuse you to decide which is best /suitable for you. Keeping cost in mind and the basic requirement in mind you can find the best and cost effective solution in this instructable to get started with your first automation project.

Introduction to tools used in this instructable:

Target of this instruct able is to control your home appliance by your android phone.

When the you pews the button in your phone light or fan in your home turns on or off.

Step 1: Tools

Picture of Tools

MQTT protocol:

in a simple language when you want to communicate to your controller through mobile or a web browser you need a communication protocol and MQTT does that magic. MQTT is a message queuing telemetry transport. It is specifically designed for automation. So where does it do magic?? its a light weight protocol, what is light weight means?? Well it's having a very low footprint to send and receive data. So it uses very less amount of data to send and receive and mobile app using MQTT also consumes less battery.
So MQTT is the best for This project.

There is a lot more info at MQTT. org for those who already familiar with MQTT can skip following peragraph, for biginers read for MQTT introduction.

MQTT works on publish subscribe events. It requires MQTT broker in between. Forgot all these thing I explains MQTT with our example.
When you press the switch in your mobile or any web device you are telling your controller that you want to turn on the switch. Now as in MQTT protocol MQTT broker seats in between your mobile device and controller. Broker take care of successfully transfer your command to the controller. this is the basic. MQTT is very vast subject. To learn more about MQTT visit

Step 2: Mobile App.

Picture of Mobile App.

Download the android mobile app attached here. and install in your mobile.

Go to MQTT Setting Tab and add your broker name and Port.

It require a web socket so enter the web socket port of your broker. For web socket enabled port is 8080.

Step 3: Mobile App Configuration

Picture of Mobile App Configuration

Open App in your mobile and

1. Go to device setting.

2. Select new device.(when you do configuration 1st time only new device option is available).

3. Device name: you can give any name for your device in my case its lamp.

4. Device type: switch(leave as it is).

5. Topic: give topic for MQTT.

6. On command: This payload will be send when switch turn on.

7. Off command: This pay load will be send when you toggle switch to off.

8. Pess DONE button.

9. Go to Dashboard. you can see your device is generated.

10. follow all step for FAN configuration.

Step 4: Test Configuation

Picture of Test Configuation

For testing configuration many tools are available but i prefer MQTTlens. It a chrome addon.

Go to

- launch MQTTlens.

Add connection

connection name: any



save detail

Subscribe with the topic you inserted in device setting.

toggle switch in your mobile you can see response in MQTTlens.

Step 5: Hardware

So software part is over here. Hardware is the most common and so many instructables are available. If you interested in my HW than leave comment. I will explain. But trust me lot of material out there to build NodeMcu based hardware.


jarsservices17 (author)2017-11-26

please provide the android source code into my mail.(

nsponlineproducts (author)2017-07-27

Hi, I have a project that is very similar to the one that you had created. Would you or anybody be interested in hearing more?

marcelode1 (author)2016-08-17

Hi, very nice project.
Where could i have access to the app code sorce? I would like to add and change commands, is it possible?

vorav (author)marcelode12017-01-23

what changes you need to do??

have u done any work on that??

siddhc (author)2016-08-20

Great post.
This is a request for guidance.
ESP8266 module connects to “” and subscribes to a
topic say “b1”. What ever is published to “b1”, it can read it
Problem happens when my second ESP8266 module subscribes to “” to “b1”. It continuously returns :

WiFi connected
IP address:
Attempting MQTT connection…connected
Message arrived [b1] 0
Attempting MQTT connection…connected
Message arrived [b1] 0
Attempting MQTT connection…connected
Message arrived [b1] 0
Attempting MQTT connection…connected

Could you kindly suggest what might be going wrong. I look forward to your advice.

vorav (author)siddhc2017-01-23

Sorry guys, i was not able to be in touch with this instructable. R u still facing the problem??

please let me know..

Wagner FilipeG (author)2016-06-21

Hello Vorav, thank you for sharing your project.

My project is very similar, but I don't know which components use in my electronic circuit, I saw in your sketch that probably you used an opto and a TRIAC, correct? Can you share this part of your project? Many thanks!

DIY Hacks and How Tos (author)2016-04-02

Welcome to Instructables. Thanks for sharing with the community.

About This Instructable




More by vorav:Home AutomationHome automation using MQTT and NodeMcu or arduino
Add instructable to: