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

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 MQTT.org

Step 2: 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 test.mosquitto.org web socket enabled port is 8080.

Step 3: 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

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

Go to https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm?hl=en

- launch MQTTlens.

Add connection

connection name: any

Host name:test.mosquitto.org


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.



    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest
    • Trash to Treasure

      Trash to Treasure

    9 Discussions


    11 months ago

    Hi can i have more explanation on hard ware part and which code language is used ?



    1 year ago

    please provide the android source code into my mail.(jarsservices17@gmail.com)


    1 year ago

    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?


    2 years ago

    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?

    1 reply

    Reply 2 years ago

    what changes you need to do??

    have u done any work on that??


    2 years ago

    Great post.
    This is a request for guidance.
    ESP8266 module connects to “test.mosquitto.org” 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 “test.mosquitto.org” 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.

    1 reply

    Reply 2 years ago

    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

    2 years ago

    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!


    Welcome to Instructables. Thanks for sharing with the community.