Home Automation With Google Assistant, Node Mcu, Android App, Ir Remote, Control 8 Relay Switches

3.4K1134

Intro: Home Automation With Google Assistant, Node Mcu, Android App, Ir Remote, Control 8 Relay Switches

Features

  • Control over Internet from anywhere in the world
  • Voice Control using Google Assistant
  • Control from Android App using WiFi
  • Control from any IR remote
  • Save the switch state even after micro controller restarts.

If you lose Internet

you won't be able to control over internet and from Google Assistant.
Android app and IR Remote will work.

If you lose WiFi

only IR Remote will work.

Internet and WiFi connection will be restored automatically if disconnected.

Things you need

  1. Internet Connection
  2. Android Mobile
  3. Arduino IDE on your computer
  4. NodeMCU
  5. Breadboard
  6. LED
  7. Buck Converter (or any other 5V voltage regulator)
  8. IR Receiver
  9. Relay Module (4ch relay module x 2 OR one 8ch relay module)
  10. Jumper Wires
  11. 1K Resistance

STEP 1: Get the Board Ready

THIS CODE IS FOR NODEMCU BOARD NOT ARDUINO

First download and install Arduino IDE from HERE

Then go to File -> Preferences, then on additional board manager urls, add this

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Then go to Board manager and install esp8266 by ESP8266 Community.
go to library manager and install IRRemoteESP8266.

Then connect the IR receiver to nodemcu board, connect VCC, GND, OUT of IR Receiver to 3.3V, GND, D4 of NodeMCU respectively.

upload the sketch IRRemote Value given below, open serial monitor and press remote key to get the values of each key, write it down somewhere. Note at least 8 key values for 8 relays.

STEP 2: Set Up Blynk

If you doesn't want to control over Internet, then go to next step.

Download Blynk from Google Play Store, and open the app and register on Blynk

Click on New Project, give a name and click on create

the new blynk auth token will be sent to your registered email id. Use that auth token in the code in next step.

open the project and swipe from right to open widget box. Click on Button, it will place a button, now click on it, name the button as your wish, click on pin, select Virtual on left side and V1 on right side. Then the value beside pin will be 1 and then 0. check the attached image to understand. Then, change the mode to Switch.

Continue this process for 8 buttons, the only things you will change is the pin Virtual number which will be V1, V2. V3, V4, V5, V6, V7, V8.

Once completed, click on play button on top-right corner.

Now download the blynk library for arduino IDE from http://blynk.cc and load it manually.

Download the zip file and extract the content of library folder to the Arduino Installation Directory/library, extract the content of tools folder to the Arduino Installation Directory/tools.

Restart Arduino IDE

STEP 3: Schematics and Code

Download the attached image and make the circuit accordingly.
If your Relay is powered by 12v, then make the changes as required. Relay module mostly works on active low. If your relay works on active high, then the change the code as required.

Then upload the code or sketch.

Before uploading, change the IR values in the code, with the values you got on previous step.

If you just want to use it WITHOUT Internet and Google Assistant, then use the code my home.ino

If you want all features then use the code Home Control.ino

NOTE: WHILE UPLOADING THE SKETCH MAKE SURE NOT TO CONNECT ANYTHING TO THE PIN D0, D8, TX, RX. OR SIMPLY PULL OFF THE JUMPER WIRES FROM THOSE PINS.

STEP 4: Android App

After successful sketch upload, the nodemcu will run, then go to your router settings and assign a static local ip to your nodemcu, and write down the ip.
This android app will be used for controlling in local wifi network. (internet connectivity not necessary)

The Apk file is designed using MIT App Inventor, you can use the attached aia file to upload to MIT app inventor and make changes to the android app.

Test it out

After installing the app, set the IP Address you noted on the app and test it out.

Also test from the IR Remote and Blynk App.

you can also the open the IP Address in your web browser on any device connected to same wifi to control relays.

STEP 5: Google Assistant

Download the app IFTTT from play store or ios store.

open the app, register yourself, search for google assistant, go to service tab, click on google assistant and connect with google.

Search for webhooks, go to service tab, click on webhooks and register.

Now go to My Applet Tab (bottom-right corner)

click on +

click on this, select google assistant -> say a simple phrase -> now type what you want to say to google like "switch on the light" and also write the response google will give, and then create trigger.

now click on that select webhooks -> make a web request on the URL field http://188.166.206.43/your_blynk_auth_token/update/V1

where V1 is the virtual pin number, change the pin number according to your need. Select method PUT, select content type "application/json", on the body field write ["0"] if you want relay to switch on or ["1"] if you want device to switch off. click on save -> click on finish.

Now open google assistant and check it and continue this process for all devices and for switch on and switch off.

In case of problem, contact me on Facebook, i will help as far as i can.

28 Comments

Everything works fine but the only problem is when there is power cut from esp, after the power resume the esp gets restarting until i give it the hotspot to connect.after connecting to the hotspot every thing works fine. So whats the solution of that
it kind of gets slow when it can't connect to wifi.
use a wifi router
No its not slowing down it is restarting until i give it wifi to connect
fantastic IDEA.
I want to use this concept to open a magnetic door from distance.
I would like that the relay remains energised for a period of 15 sec to keep the door opened, once it is triggered by wifi or IR sensor,
What modification would be required in the code,
Thanks in advance
actually a lot of changes needs to be done.
Which is best
Hi-Link 24V 5W AC to DC Power Supply
Hi-Link 24V 3W AC to DC Power Supply
Depends on your requirements
Home +control is not opening. Error says sketch could not be created.
What can be the problem.
Android app could not install in almost every phone which is above android version 5.0
i am using it on Android nougat and Android pie.
Moreover, its built using MOT appinventor. i have given aia file, you can go there and edit Android app design and logic

nice work, for relay is energize when Low?

relay module works on active low

ok thank you, and two question, can the code integrating with wifi manager, for selecting wifi? and can we add the 433 Mhz receiver?

I got everything done but the IR stuff.. After hours of debugging, I realized that my IR Reciever requires 5V to work.

use a logic level convertor between output of IR receiver and nodemcu.
nodemcu works in 3.3V, so 5V ouput signal from IR receiver may damage the nodemcu

Too late :p
Already destroyed a GIPO pin.

Thanks though

BTW, forgot to say---

Thanks!!

Very informative post.

Is there anyway you can re upload the hone control.ino?

More Comments