Make Google Assistance to Control a Device in Simple Way

by RishabhL in Circuits > Arduino

714 Views, 17 Favorites, 0 Comments

Make Google Assistance to Control a Device in Simple Way

download.png

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..!!!

What You Will Need:

QluwTVU7FQIvaC8dZy6x2JaM.jpg
Dot_5.6x6.7_000_1708p.jpg
P_20161220_152919.jpg
relay-2.jpg
download (4).png
download.jpg
R6715468-01.jpg

1. Esp8266-12E nodemcu

2. Relay 12v or any

3. ULN2003 ic

4. LED

5. 10k ohm resistor

6. PCB

7. 1n4007 diode

Circuit Be Like..

ckt.png

Setting Up Adafruit IO:

1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
7.jpg
8.jpg
ckt.png

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.

Setting Up IFTTT:

11.png
12.png
13.jpg
14.jpg
15.jpg
16.jpg
17.jpg
18.jpg
19.jpg
20.jpg
21.jpg

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.



Arduino Coding:

555.png
#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!");
}

Final Run:

P_20180601_103703.jpg
P_20180601_103644.jpg
P_20180601_104201.jpg
P_20180601_104152.jpg
Make Google Assistance to Control a Device in Simple Way
Make Google Assistance to Control a Device in Simple Way 2

Upload the code into your ESP8266-12e nodemcu.