Introduction: Make Google Assistance to Control a Device in Simple Way

About: Master in Electronics Engineering

Google Assistance is very popular to give answers of your questions, but it can do lots of more things also. In this instructables I will demonstrate you how you can control your device by saying simple phrase to your google assistance. By using this you can turn on or off home appliance from any where in the world. Lets get Started..!!!

Step 1: What You Will Need:

1. Esp8266-12E nodemcu

2. Relay 12v or any

3. ULN2003 ic

4. LED

5. 10k ohm resistor

6. PCB

7. 1n4007 diode

Step 2: Circuit Be Like..

Step 3: Setting Up Adafruit IO:

Go to https://io.adafruit.com/

Make new account if you not have any account.

Sign in to your account.

then go to https://io.adafruit.com/

> Click on Dashboards > Actions > Create new Dashboard > give_any_name > Create

next step

Create a new block> Toggle > Enter new feed name > check that feed > next > Button On text to= 1 and Button Off text to=0 >Done.

Step 4: Setting Up IFTTT:

open https://ifttt.com/login

Click Continue with google >

> My Applet > new applet >click on if this button> google assistance > say a simple phrase > enter phrase you want to say > enter response to that phrase > create trigger.

similarly create for turning off device.

Click that > action service > Adafruit > click Authorise after login to adafruit > select feed name>

data to save >put 0 for off and 1 for on for two different applets.



Step 5: Arduino Coding:

#include<ESP8266WiFi.h>
 #include "Adafruit_MQTT.h"


#include "Adafruit_MQTT_Client.h"
#define WLAN_SSID       "your ssid"
#define WLAN_PASS       "your pass"
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "your username"
#define AIO_KEY         "your aio key"
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
Adafruit_MQTT_Subscribe d1 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/device1");
void MQTT_connect();
void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(D8,OUTPUT);
  pinMode(D7,OUTPUT);
  pinMode(D6,OUTPUT);
  pinMode(D0,OUTPUT);
  Serial.println(F("Adafruit MQTT demo"));
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());
  mqtt.subscribe(&d1);
}
uint32_t x=0;
void loop() {
 
  MQTT_connect();
  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {  
    if (subscription == &d1) {
    Serial.print(F("Got: "));
      Serial.println((char *)d1.lastread);
     uint16_t data=atoi((char *)d1.lastread);
     if(data==1)
      digitalWrite(D0,HIGH);
      else
       digitalWrite(D0,LOW);
    }
  }
}
void MQTT_connect() {
  int8_t ret;
  if (mqtt.connected()) {
    return;
  }
  Serial.print("Connecting to MQTT... ");
  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
       retries--;
       if (retries == 0) {
         while (1);
       }
  }
  Serial.println("MQTT Connected!");
}

Step 6: Final Run:

Upload the code into your ESP8266-12e nodemcu.

Step 7: