How To ON/OFF a bulb by Google voice assistant

Today i am telling you to How To ON/OFF a bulb by Google voice assistant with help of Adafruit IoT Platform and IFTTT.  Adafruit Industries is an open-source hardware company based in New York City. IFTTT is a free platform that helps you do more with all your apps and devices

Adafruit was founded in 2005 by MIT hacker & engineer, Limor “Ladyada” Fried. Her goal was to create the best place online for learning electronics and making the best designed products for makers of all ages and skill levels. Adafruit has grown to over 100+ employees in the heart of NYC with a 50,000+ sq ft. factory. Adafruit has expanded offerings to include tools, equipment, and electronics that Limor personally selects, tests, and approves before going in to the Adafruit store. Adafruit is a 100% woman owned company. –By Adafruit.com

IFTTT is the free way to get all your apps and devices talking to each other. Not everything on the internet plays nice, so we’re on a mission to build a more connected world.

Things used in this tutorial

  • NODEMCU -ESP8266
  • White LED bulb
  • Two Connecting wires

STEP 1

Visit https://io.adafruit.com and sign up. Now create a Feed and dashboard. You can give any name for feed and dashboard.

STEP 2

Click on dashboard and create a new block by clink on plus sign button for configuration. Select a toggle and select feed what you create. Now click on next step. Here you can give any name for block, fill ON in the button on text and fill OFF in the button off text.

STEP 3

Note your AIO key, username and feed name for Led Program.

STEP 4

Flash this code in ESP8266 help of Arduino IDE.

#include”Adafruit_MQTT.h” // Adafruit APIs for MQTT server talks
#include”Adafruit_MQTT_Client.h” // Board Specification APIs are defined inside this one
#include

WiFiClient client1;
/————————————————————
* Arguments:
* 1. Address of WiFiClient Object
* 2. Port Address : 1883 or 8883
* 3. Username of the Adafruit A/c (String)
* 4. API Key value from the A/c (String)
*————————————————————-
/
char NAME[]=”Your adafruit username”;    // replace
char API_KEY[]=” Your AIO key”;               // repalce
char URL[]=”io.adafruit.com”;
Adafruit_MQTT_Client mqtt(&client1,URL,1883,NAME,API_KEY);

/———————————————————–
* Arguments
* 1. Address of the Adafruit_MQTT_Client
* 2. Adafruit Username
* 3. link of the ‘Feeds’ we have cretaed in Adafruit
* 4. MQTT_QoS_0/1/2 => Quality of Service (Optional)
*————————————————————
/
Adafruit_MQTT_Publish mypub=Adafruit_MQTT_Publish(&mqtt,”ADAfruitusername/feeds/adafruitfeedname”);   //replace

Adafruit_MQTT_Subscribe mysub=Adafruit_MQTT_Subscribe(&mqtt,”DAfruitusername/feeds/adafruitfeedname”);  //replace

void setup() {
// put your setup code here, to run once:
pinMode(D0,OUTPUT);

WiFi.begin(“wifi hotspot name”,”password”);    //replace
Serial.begin(115200);

while(WiFi.status() != WL_CONNECTED)
{
Serial.println(“Connecting”);
delay(1000);
}

Serial.println(LED_BUILTIN);
/*————————————————————–
* String Pool Note
* Serail.println(F(“”)) will be stored in Flash memory
*/

//Printg the Local IP
Serial.println(WiFi.localIP());

//Subcsribe to topic Feed
mqtt.subscribe(&mysub);

mqtt.connect();
}

void loop() {
// put your main code here, to run repeatedly:

if(mqtt.connected())
{
/*———————————————————
* publisher code:
* 5 Max subscription
* To change goto HEader file
* “#define MAXSUBSCRIBE 5”
*/
Serial.println(“MQTT Connected”);
}
else if(mqtt.connect()==0)
{
Serial.println(“Connecting to the MQTT….”);
}
Serial.println(“MQTT Connected”);
//mypub.publish(“hi”);
Adafruit_MQTT_Subscribe *sub;
while(sub=mqtt.readSubscription(5000))
{
if(sub==&mysub)
{
if(strcmp((char *)mysub.lastread,”ON”)==0)
{

Serial.println(“LED is on”);
Serial.println((char*)mysub.lastread);
digitalWrite(D0,HIGH);
}
else
{
Serial.println(“LED off”);
analogWrite(D0,LOW);
}
}
}
Serial.println(“.”);
delay(1000);
}

 

STEP 5

LEDWIRE

STEP 6

Download IFTTT android app and create two applets. First applet for ON LED and second applet for OFF LED. Open IFTTT app and select google voice assistant and adafruit for creating applet. Remember – write ON in the DATA TO SAVE field in adafruit section.

STEP 7

Now You can control LED bulb by Google voice assistant using your smartphone.

 

Harshvardhan Mishra

I am an IoT (Internet of Things) Enthusiast and Blogging is my Passion. Follow and send tweets me on @harshvardhanrvm

9 thoughts on “How To ON/OFF a bulb by Google voice assistant

Leave a Reply

%d bloggers like this: