Google Assistant home automation with Nodemcu ESP8266
Hello, welcome back. In this tutorial, we will learn how to make a Google Assistant home automation project using the Nodemcu ESP8266 board. Also, this tutorial includes how to turn ON and OFF an LED using Google Assistant. But, once you understand the basic principle here, you can control every electrical appliance in the house using relays. Also, this project is based on IoT technology. This project mainly needs two applications. That is the Blynk app and the IFTTT web app. OK, now let’s learn how to do this project step by step.
What is the Google Assistant
Simply put, this is an artificial intelligence service created by Google. Through this service, we can interact using our voice. Additionally, this service is available on all smart devices, including smartphones, smartwatches, tablets, and smart home devices.
What is the IFTTT
IFTTT is a service designed to respond to events. Essentially, it is an app with a wide range of software that connects devices and services together. Additionally, the IFTTT application works closely with various service providers. We primarily use this application for purposes such as home automation and posting the same content across several social media platforms. To achieve this, we can use the ‘applets’ within the application. For more details, click this Wikipedia link.
OK, let’s do this project step by step. The required components are given below.
- Nodemcu ESP8266 board x 1 — Our Store / Amazon
- LED x 1 — Our Store / Amazon
- 180-ohm resistor x 1 — Our Store / Amazon
- Breadboard x 1 — Our Store / Amazon
- Jumper wires — Our Store /Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, connect these components. To do this, use the circuit diagram below.
Step 3
Thirdly, let’s set up the Blynk app. For that, follow the steps below.
- First, download and install the Blynk app on your smartphone and sign up the app using your email. Now, click the “New project” button.
- Then, enter the project name you’d like. After, select the device and connection. Finally, click the “Confirm” button.
- OK, now we can see the project interface. Next, let’s add the widget to the project. To do so, click the “+” icon and include a one-button widget.
- Next, let’s set up the settings of this button widget. To do so, click the button and enter the name you like. After, change the PIN to D2 and mode to switch.
- Lastly, customize this interface as you like. OK, the Blynk app is ready for our project.
Step 4
Next, let’s set up the IFTTT application. For that, follow the steps below.
- First, go to the IFTTT web page and sign up using your Gmail address.
- Then, click the “Create” button and follow the steps below.
- In this step, select the address where you want to use Google Assistant.
- OK, now we need to provide the necessary commands to turn the LED on. First, issue the command to turn the LED ON, such as ‘LED bulb ON.’ You can also add two more optional commands if desired. Next, give the voice command that you can get from Google Assistant; for example, ‘OK, the LED bulb is ON.’ Choose a name for your command as well. Once you’ve completed these steps, click the ‘Create Trigger’ button at the end. Then, follow the steps again.
- Now, all we have to do is fill in the details. First, we will create a URL. We need to create this link as follows.
http://blynk cloud ip/blynk auth token/update/relay pin
- First, let’s get the Blynk cloud IP. For that, run the command prompt (CMD) on your computer. Next, type ping blynk-cloud.com and press Enter. Then, we can see the details related to the Blynk cloud. From here. All we need is the IP address.
- OK, now let’s get the Blynk auth code from the Blynk app registered Gmail.
- Now we can create the above URL. It is as follows.
http://188.166.206.43/Y_zYDj7j8rlp1DfihdOHZXhAHgnY4oOz/update/D4
This URL does not work for you. It should be made as mentioned above. Now, we add this information to the web application. Enter the URL first. Then, change the method to PUT. Change the content type to Arduino / JSON. Enter [“1”] for the body. After, follow the steps again.
- Next, we have to create the voice command to turn off the LED. For that, do the same steps as mentioned above.
- Now, let’s create a voice command to turn off the LED. I have given it as “LED bulb OFF”. Enter this as you like. Then, enter the voice command given to us by Google Assistant as “OK, The LED bulb is OFF”. After, click the “Create trigger” button. Then, follow the steps again.
- Now, let’s connect an LED off command with this app. For that, we use the same URL we created above. Here we need to change the value entered the body. For that, use [“0”]. Now, click again the “Create action” button. Then, follow the steps below. Now, you can see the two voice commands that we have created.
Step 5
OK, all apps are ready. Let’s now create the program for this project. It is as follows.
/*Google Assistant with Nodemcu
* https://srituhobby.com
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "";
char ssid[] = "";
char pass[] = "";
#define LED D2
void setup() {
Blynk.begin(auth, ssid, pass);
pinMode(LED, OUTPUT);
}
void loop() {
Blynk.run();
}
Code explanation
Firstly, libraries are included.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Now, include the Blynk auth token and WI-FI connection details.
char auth[] = "Y_zYDj7j8rlp1DfihdOHZXhAHgnY4oOz";
char ssid[] = "SriTu Hobby";
char pass[] = "12345";
Next, the LED pin is defined.
#define LED D2
In the setup function,
void setup() {
//The blynk library is beginning
Blynk.begin(auth, ssid, pass);
//The LED pin is set as an output pin
pinMode(LED, OUTPUT);
}
In the loop function, the blynk library is run.
void loop() {
Blynk.run();
}
Step 6
Now, select the board and port. Afterward, upload this code.
Finally, run the Google Assistant service on your smartphone and try the voice commands we entered above. OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.
Google Assistant home automation with Nodemcu ESP8266