Monday, December 30, 2019

Voice Controlled Home Automation With Google Assistant

Controlling Applications With google Assistant

Home Automation Project

In this project, I will make a voice Control home automation device with the help of google assistant. This will control the home Applications with the help of google assistants in your Cellphone, tablet or Google home.

First of all, Collect the Following devices - 
  • Node MCU
  • 4 Channel Relay Board
  • LM 7805 Voltage regulator
  • 7-12 Volt Dc Supply
  • 4 220Volt Ac Bulb 
  • 220 Volt Supply
In this project, I will show you step by step guide - 

(1) Make Connections According to the circuit given below.

Circuit Diagram

Sign Up Page Adafruit.io

(3) If you create our account so Sign in to adafruit.io.

Sign In Page Adafruit.io
(4) After sign in. You can see an "Action" option in the Dashboard. Click on this option than you can see "create a new dashboard" option. Click on this option and create a new dashboard. 

Comand -> Dashboard > Action > Create a new Dashboard
Create a Dashboard
(5) After this, a pop-up window opens. Where you can see a Name and description input box. You can Enter any name Which you have like. I set the name is  "Home automation" And leave the description box empty.
then click on Create.

Command -> Create a new Dashboard > Name "Home Automation" >Create


Set Name
(6) After this you can see a dashboard named Home Automation, this name is just for me, you will see the name that you gave to your dashboard in the previous step. After that click on this name and open this dashboard.

Command -> Home Automation >


Open Dashboard
(7) After clicking, you will see some such window. In this window, you can see a sign of Plus on the top right corner. Now you have to click on this Sign.

Command -> Click on [+]

Home  Automation
(8) Now you will see some blocks in a popup window. Of which you have to click on the first block. Which acts as a sliding switch.

Command -> Click on the first Block


Slide Switch Selection
(9) After this, a pop-up window will open. In which you will see an input box. The inside of which will be seen written: "Create a new feed". In this, you have to write Relay1. Which will be case sensitive. After that click on create. So that a Relay1 named feed will be added to the feed box below. After this, you have to click on the same input box again and now write Relay2 in this box. After that click on create. So that the feed box will add one more feed Relay2. Similarly, you have to add Relay3 and Relay4 as well.

Note ->  All feed name Relay1 ,Relay2, Relay3 and Relay4 are case sensitive. And Do no insert Space Between name and number.

Command -> Enter name in Create a new Feed box > Create  (4 Times )

Create Feed
After creating the four feeds, you will see some such windows.

All Feed
(10) After this, you have to mark the square box in front of Relay1 And click on "Next Step".


Command -> Check on Relay1 Checkbox >Next Step

check the CheckBox

(11) After this, you will see a window open. Which will contain three input boxes? In this, you have to write "Bulb 1" in the first input box named "Block Title". Here you can give any other name of your choice. Such as lights, TV, and fridge, etc. Now you have to write "1" in the input box named "Button on Test" below it. And also you have to write "0" in the input box named "Button off Text" below. Now in the last, you have to click on the option "Create Block" in the bottom right corner. Which will lead you to the next step?

Note -> You can also type the name of your choice in the "Block title". But you cannot change the "Button on Text and the "Button off Text".

Command -> input Block Title (Bulb 1) > Input Button On text [1] > Input Button Off Text [0] 

Set Button
(12) Now you have reached the dashboard window again. Now you have to click on the [+] sign given in the top right corner again. This will open the block window again and you have to choose the first number block again. After this, the feed window will open again. But this time you have to mark the square box in front of "Relay2" and click on "Next Step". The window before you will open. But in this, you have to write "Bulb 2" in the input box containing the "block title". You can also write another name of your choice. But it is different from the previous one. No names should be the same. After this, you have to write "1" in "Button on Text" and "0" in "Button off Text". It will be the same every time. Now again you have to click on the "Create block" option in the bottom right corner. So that you will come back to the dashboard again. Now you have to make blocks for bulb 3 and bulb 4 in the same way.

Note -> In First Time Write     Bulb 1 in Relay1,
             In Second Time Write Bulb 2 in Relay2,
             In Third Time Write    Bulb 3 in Relay3,
             In Fourth Time Write  Bulb 4 in Relay4.
(13) Finally, the dashboard window will look something like this to you.

Final Dashboard
(14) Now you can change the layout of the dashboard by clicking on the gear icon given in the top right corner. I have arranged my dashboard like this. You can do as you like. If you allow it to remain the same, then there is no problem with it.

Command -> Click on Gear Icon (edit layout ) > Save

Rearranged Dashboard
(15) Now open IFTTT in a new tab in the browser. Now click on Continue with Google option and login with your Google account. You have to log in with the same Google account. Which was added on his adafruit account? 


Command -> IFTTT > Continue With Google Account 

IFTTT Sign In

After this, you will now see some such window.
IFTTT Home
(16) Now you will see the profile picture of your Google Account in the top right corner of the window. I have not put any image on my Google account, so I am only seeing the avatar. Then click on it. Now a list of options will appear in front of you. Now you have to click on the "create" option in this list.

Command -> Profile Image (Avtar) > Create

Create
(17) Now a window will open in front of you which will say "If This Then That". So now you have to click "this".

Command -> Click on "This" 

Service add
(18) After this, a new window will open in which you will be asked to select the service, here you have to search Google Assistant in the search box given in the middle. Now when you get Google Assistant service. So now you click on it.

Command -> Search google assistant > Google Assistant

Choose Google Assistant Service
(19) Now you will see four options here. From which you have to select the first option "Say a Simple Phrase".

Command -> Say a Simple phrase

Select Simple Phrase


(20) Now a window will open in front of you. In which you will see four input boxes. In this, the first option whose title is "What do you want to say", you have to write the command on which Google Assistant will turn on your first bulb. I have written "Turn first Bulb on" here. You can write anything you like. After this, you can write another command in the input box below which is titled "What's another way to say it". To which the first bulb will turn on even when spoken. This command is optional. You can also leave it empty. I have written "First bulb on" here. Here also you can write any other command of your choice. Now in the input box below its title, "Add Another way", you can also write another command. This is also an optional command. I left it blank, you can write it if you want. Now the input box given below is titled "What do you want the Assistant to say in response?". In this, you have to write what the Google Assistant will tell you after your command is running or after you speak. I have written "Turning on First bulb" in it, you can write anything else you like. Now in the language option given below it, you have to choose that language. In which you have written the commands above. I have written in English, so I am choosing English. You choose your language. After this, now you click on the option "Create Trigger" at the bottom.


Command -> Enter First command > Enter Second Command >Enter Third Command > Enter Respone > Click Create Trigger 

Configure Voice Command

(21) Now the same window will open in front of you again. Which would have written, "If Then That". You have to click "That" in it. 

Command -> That 


Choose That Service
(22)  After which another new window will open. It will say - "Choose Action Service" and in the middle of this window, you will see a search box. In which you have to search "Adafruit". And just below this, you will see two options "Connections" and "Service". From which you have to choose the "Services" option, now you will get the "Adafruit" service. Then you have to click on it. Which will increase you for further steps?

Command -> Search "Adafruit" > Services > Click "Adafruit"

Chose Adafruit
(23) Now a page of Adafruit website will open in front of you. Between which it will be written "Authorize" and "Cancel". In which you have to click on "Authorize", after which you will automatically reach the web page of IFTTT again.

Command -> Authorize

Authorize Adafruit 
(24) Now another new window will open in front of you. In which you will see two input boxes written. The title of the former will be "Feed Name". In which you have to choose "Relay1". You have to write "1" in the second box whose title is "Data To save". After this, you have to click on "Create Action".

Command -> Relay1 in Feed name > 1 in Data to save > Create action 

Create action
(25) Now the last window will open in front of you which will say "Review and Finish". In this, you will be given the "Finish" option below. which you have to click on. Now you will come to the home page.

Command -> Finish 

Finish


(26) Now you have to set all the steps from step 14 to step 25 three more times. In the second time, wherever you have written "First Bulb" in step 19. You have to write "Second Bulb" there. And you have to choose "Relay2" in step 24. In the third step, you have to choose "Third Bulb" and "Relay3". And now in the last fourth step, you have to choose "Forth Bulb" and "Relay4". If you want, you can put any other name of your choice in place of "First Bulb", "Second Bulb", "Third Bulb" and "Forth Bulb".
(27) Now in this phase, you have to set all the steps from step 14 to step 25 four times. But this time you have to write "off" instead of "On" in step 14 for the first time. And in step 24 you have to select "Relay1" and in "Data To save" you have to write "0". And now the second time you have to write "Off" instead of "on" and choose "Second Bulb" and "Relay2" instead of "First Bulb". And in "Data To Save" you have to write "0". And now for the third time, you have to write "Off" instead of "on". And instead of "First Bulb", choose "Third Bulb" and "Relay3". And in "Data To Save" you have to write "0". And now for the fourth time, you have to write "Off" instead of "on". And choose "Fourth Bulb" and "Relay4" instead of "First Bulb". And in "Data To Save" you have to write "0".
If you want, you can put any other name of your choice in place of "First Bulb", "Second Bulb", "Third Bulb" and "Forth Bulb".

(28) Now open the Arduino software on your pc or laptop. if you do not have the Arduino software, you can download it by clicking here.


(29) So now you install the NodeMCU board on the Arduino software. If you are not able to install the board, you can click here to see how to install the NodeMCU board in the Arduino software.

(30) Now you have to add two libraries to the Arduino software. Whose link I have given you below. You can download them from here. If you do not know how to add the library to the software. So click here.


If you have added these libraries earlier then you can skip this step.
(31) Now you have to select the NodeMCU board in Arduino software. For that, first, you click on the "Tools" option above. Then select the "Board" option. Now select "NodeMCU 1.0 (ESP - 12E Module)" after this. In this way, your board will be selected in the Arduino software.

Command -> Tools > Board > NodeMCU 10 (ESP-12E Module)

Select NodeMCU
(32) Now whatever is written in the editor window of Arduino software. Erase all that and copy the code given below and paste it in the editor window of Arduino software.

Code 

Or

You Can Download Google_Assistant_Home_Automation.ino

(33) Now you have to make some changes to this code. For example, in this code, you will see "WIFI_USERID" written in the eleventh line. You have to write the username of the modem or smartphone that you will use in the hotspot instead. Like my wifi name is My WIFI. So I will replace my WIFI_USERID with "My WIFI". And in the line below it, where "WIFI_PASSWORD" is written, you have to write the password of your modem or smartphone's wifi. For example, my WIFI password is ECCIRCUIT 123. I will replace "WIFI_PASSWORD" with "ECCIRCUIT 123". Along with this, you will see the "Username" written in the eighteenth line from above. Now you have to go to the home automation dashboard on the Adafruit.io website. Here you will be able to see a key sign on the top right side. Now you have to click on it. After clicking on it, a pop-up window will open in which you will see a QR code. Below that QR code, you will see two boxes.  In which your username is written in the box above. You have to copy it. And wherever "USER_NAME" is written in the code. Have to paste it  And below this you will see another box. Whose title is "Active Key". In that box, you can see the key written. Copy it. And in the program below the line "USER_NAME", where "AIO_KEY" is written. Paste it instead. Now your code will look something like this.

Note - WIFI_USERID, WIFI_PASSWORD, USERNAME, And AUTH_KEY are case sensitive 

Command -> Change WIFI_USERNAME in your hotspot name and Change WIFI_PASSWORD in your hotspot password. as well as Change Username in program From adarfruit.io And Change Auth_key in program From adafruit.io.


Change it 
Click on Key Icon
Key open
Copy User Name and Auth Key

User name And  auth key
After Change Code 

Final Code
(34) Now connect NodeMCU to your PC or laptop that you are working on. Now you wait a bit so that your drivers will be installed. Now you will be able to see the option of "Tools" above in Arduino Software. Now you click on it. After that, you will see the option of the port. Now click on it and select the port from which your NodeMCU is connected. Now compile the code and upload it. Once uploaded, your project is ready. Now you test it.

Command -> Tools >Port > Select Your port My case Com 7


Port Select

Now Test Our Project

(35) Now, first of all, turn on your modem or smartphone hotspot. Whose id and password are entered in its code. Now you start your project. Now you will be able to see that a device has been connected to your hotspot. You can also watch it on the Arduino's serial monitor. Now you can turn your bulbs on or off with switches made on Adafruit.Io. Or you can turn the bulb on or off using the Google Assistant you have on your smartphone. But it is necessary to have the same Google Account signed in to your Google Assistant, which is signed up on your IFTTT. Now you have to follow the command given below to turn the bulb on or off with Google Assistant.


To turn on the first bulb, say             -> First Bulb on.
Speaking to turn off the first bulb      -> First Bulb off.
To turn on the second bulb, say         -> Second Bulb on.
Speaking to turn off the second bulb  -> Second Bulb off.
To turn on the third bulb, say            -> Third Bulb on.
Speaking to turn off the third bulb     -> Third Bulb off.
To turn on the fourth bulb, say          -> Fourth Bulb on.
Speaking to turn off the fourth bulb   -> Fourth Bulb off.

You will easily understand through the snapshot is given below.

Snapshot


In this way, your project has been created. And you have also tested it. If you face any problem with this project, then you can ask me by commenting on the post. I will provide you the solution to all your problems.

Thank You