Tuesday, March 19, 2024
ESPHow ToIoT HardwaresIoT PlatformsTutorials/DIY

Controlled LED by Google voice assistant

In this tutorial we learn How To Controlled LED 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.

Controlled LED by Google voice assistant

Things used in this tutorial

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

1 – Setup Adafruit IO account

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

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.

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

2 – Arduino Sktech

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 <ESP8266WiFi.h>

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);
}

3 – Setup IFTTT App

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.

Circuit diagram

LEDWIRE

 

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


I hope you like this post “Controlled LED by Google voice assistant”. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

We have other tutorials with ESP32 that you may find useful:

You may like also:


Upvote on Reddit

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

11 thoughts on “Controlled LED by Google voice assistant

Leave a Reply

Your email address will not be published. Required fields are marked *