Introduction: Internet/cloud Controlled Home Automation Using Esp8266 (MQTT, IoT)

Picture of Internet/cloud Controlled Home Automation Using Esp8266 (MQTT, IoT)

IoT the most discussed subject in the world right now!! Cloud servers and services making this possible is the attraction point of today's world...

RULING OUT THE DISTANCE BARRIER was and is the aim!!

So now control your home or office from anywhere in the world... not from only inside or a range!!

Easiest and cheapest solution from the laziest guy!!! ENJOY AND BE LAZY...

NOTE: READ THE WHOLE PROJECT FIRST IT WILL TAKE 3-4 MINUTES AND INNOVATE... DON'T HALF READ AND BRICK YOUR DEVICE...

Step 1: COMPONENTS REQUIRED

Picture of COMPONENTS REQUIRED

Only 4 components required -



1. ESP8266 NODEMCU or WEMOS D1 mini or any esp8266 wifi development board
2. RELAY (5V or 6V)
3. ULN2003 or UNL2003A (Relay driver IC)
4. Jumpers (obviously or else solder it!!)


The main structure of the project is that

ESP8266 module will receive the signal from the MQTT server (i.e. arest.io) and forward the signal to the pin or processor. ULN2003 relay driver IC connected to the Nodemcu board pins. Output pins are connected to relay or any RGB light or servo motor etc.

Step 2: Software

Picture of Software

I have used Arduino IDE as the programming software. If you are new to this Nodemcu or esp8266 development board then please refer to my previous instructable. To interface the Nodemcu or wemos board with Arduino IDE.

In the Arduino IDE after setting up previous told things, go to SKETCH -> INCLUDE LIBRARY -> MANAGE LIBRARIES -> SEARCH FOR "arest" -> INSTALL THE LIBRARIES -> NOW SEARCH FOR PubSubClient -> INSTALL THE LIBRARY.

Now its half done... almost there!!!

Step 3: CIRCUIT DIAGRAM

Picture of CIRCUIT DIAGRAM

As the above circuit depicts everything still the input side of the ULN2003 relay driver IC is connected to the pins of the esp8266 and the output is connected to relay's coil leg as when esp8266 pin gets high the output pin of ULN2003 gets low thus giving the relay a 5V potential to work.

Instead of sending the 0 or 1 to the relay esp8266 pins we can also send other values for servo but declaring servo.attach(pin) to rotate the servo to the certain value. Its easy but everyone need to innovate, read and think a little.

Step 4: CODE

Picture of CODE

I got the idea from "Marco Schwartz" project and modified it. He have use d the arest.io MQTT but we can also use adafruit.io. The main part of the program is :

Unique 6digit arest id

char* device_id = "unique_6_digit_id";

WiFi credentials

const char* ssid = "ssid_name"; const char* password = "your_password";

Choose any unique id as you like but it should be unique not my or your name unless its a telugu name!!

example of unique id: pf4h6q (just example)

there can be many changes made in the code as according to the code, we have to mention the output after every reboot of the development board.

Step 5: CONTROLLING

Picture of CONTROLLING

2 CRUCIAL steps:



1. declaring output pin
2. toggling or sending information in that pin



Declaring output pin:

http://cloud.arest.io/pf486q/mode/5/o

"pf486q" is the 6 digit unique code for arest.io

"o" as output

reply after executing this in any browser {"message":"Pin D2 set to output","id":"pf486q","name":"home cloud","hardware":"esp8266","connected":true}

Toggling or sending information in the pin:

https://cloud.arest.io/pf486q/digital/2/0

digital pin 2 is send a bit "0" or "1" as we wish

https://cloud.arest.io/pf486q/digital/2/1

Declaring pin is necessary for once after a reboot/reset/shutdown otherwise for continuous run of esp8266 it's unnecessary.

I have used an Android app HTTPRequest to create widget on home-screen with the necessary URL. As shown in my previous instructable. Please view that otherwise this will be lengthy.

Step 6: CONCLUSION

This is an IoT project for controlling home appliances, door, window, everything and can be customized according to individual's need. Its not locally controlled, this whole thing can be controlled from anywhere.

EACH COMMAND OR URL WITH ARGUMENT NEEDS SOMETIME 1-2 second/s to execute as this is not a dedicated server... but to control your house from anywhere in this world is AWESOME!!

ENJOY AND BE LAZY... BE ABSENTMINDED AND FORGET TO SWITCH OFF APPLIANCES BUT WITHOUT A HEADACHE!!!!

Thanks to "arest.io" MQTT services and to "Marco Schwatrz"...

if you like the instructable support and enjoy... and for any problem regarding this ask me.


Step 7: Video!!!

Someone special helped me to check it works from somewhere else or not... AND it works from anywhere just internet access is needed... (I'M in Kolkata,IN and she is in Ranchi,IN)... and yes she messed with me after knowing my unique code of arest.io so don't share your own created unique code!!

Comments

AndrewHoover (author)2017-10-26

It would appear that if your internet connection goes down for whatever reason that this device would not be able to operate even if the user was on the same network. Is this true?

For the used code its true but its very easy to change the code a little bit just by including wifiserver library and sending the command instead of "cloud.arest.io" to the assigned I.P. of the router. Thanks. I noticed it earlier and thought to include this but didn't just to keep it "to the point"!! Now I will include that tweaking the code.
Thanks again for noticing it.

Thanks for the clarification! Nice project. I'm just now starting to look at NodeMCU and the ESP8266 and this was helpful in understanding it. Showing how to connect to the cloud service is great but I would also like to see what would be required for the local server side of things.

Thank you!

​i will add the webserver feature of esp8266 to avoid this. like i did in my previous instructable

About This Instructable

2,079views

58favorites

License:

Bio: Nothing just a tech enthusiast and by degree an Electrical Engineer
More by Abhrodeep Chanda:IoT Push Notification Using Nodemcu on Phone(For Anything)Digital Clock Using Microcontroller (AT89S52 Without RTC Circuit)Internet/cloud Controlled Home Automation Using Esp8266 (MQTT, IoT)
Add instructable to: