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
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:
- Dynamic WLAN configuration for ESP32 Board | AutoConnect
- ArduinoOTA ESP32: Wi-Fi (OTA) Wireless Update from the Arduino IDE
- ESP32 with LoRa using Arduino IDE
- How To Use Grove-LCD RGB Backlight with NodeMCU
- How To ON/OFF a bulb by Google voice assistant
- Arduino IDE | Arduino | Open Source Hardware/Softawre | Arduino Vs RPi
- WiFi LoRA 32 (V2) ESP32 | Overview | Introduction
- DHT11 sensor with ESP8266/NodeMCU using Arduino IDE
- Arduino Support for ESP8266 with simple test code
You may like also:
- Raspberry Pi – Introduction | Overview | Setup and Management | Tutorials
- MQTT | What is MQTT | MQTT in Depth | QoS | FAQs | MQTT Introduction
- How to set up Windows 10 IoT Core on the Raspberry Pi
- Best IoT Visual Programming Tools
Pingback: What is IFTTT? - IoTbyHVM
Pingback: Getting Started with the ESP32 Development Board
Pingback: ESP8266 as a MQTT Broker | How To Make ESP8266 as a MQTT Broker
Pingback: IFTTT Alternatives To Automate Your Online Workflow 2019 | IFTTT ?
Pingback: ESP32 BLE Tutorials | How to use ESP32 with BLE
Pingback: GPIO pins of ESP8266 and How to use efficiently -IoTbyHVM
Pingback: Heroku | How To use | Getting started with Heroku ...
Pingback: Install Ubuntu Core on Raspberry Pi 2 or 3 - IoTbyHVM
Pingback: NodeRed Alternatives - Visual programming tools -IoTbyHVM
Pingback: Portable OS - Your pocket operating systems - TopX
Pingback: ROCK Pi 4 Backup and Restore uSD card or eMMC module