Blink a light with Google Assistant

Photo by BENCE BOROS on Unsplash

Basic Requirements

  • NodeMCU
  • LED
  • Connecting wires
  • Account in IFTTT
  • A Smart Phone with Google Assistant-enabled

Circuit Connection


Setting Up IFTTT

  • Click Start for free. Then create an account from any of the options. Then click Create. After that, you will see a screen as shown below
  • Click on Add then choose a service. In this case, select Google Assistant. Then click on the 1st card that is “Say a simple phrase” then a window will appear as shown.
  • Complete it according to your ideas.
  • 1st column is the voice command that will activate the process
  • After you finished it we need to add the Then part. Before doing that we need to code the program for our NodeMCU.
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WIFI_SSID “Name”
#define WIFI_PASS “password123”
#define MQTT_SERV ""
#define MQTT_PORT 1883
#define MQTT_NAME "sathyanarayanp"
#define MQTT_PASS "Your Auth Key from adafruit”
int led = D6;WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, MQTT_NAME "/f/amigos");
Adafruit_MQTT_Publish LightsStatus = Adafruit_MQTT_Publish(&mqtt, MQTT_NAME "/f/light status");
void setup()
//Connect to WiFi
Serial.print("\n\nConnecting Wifi>");
digitalWrite(LED_BUILTIN, LOW);
while (WiFi.status() != WL_CONNECTED)
Serial.println("OK!");//Subscribe to the onoff topic
pinMode(led, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(led, LOW);
}void loop()
//Connect/Reconnect to MQTT
//Read from our subscription queue until we run out, or
//wait up to 5 seconds for subscription to update
Adafruit_MQTT_Subscribe * subscription;
while ((subscription = mqtt.readSubscription(5000)))
//If we're in here, a subscription updated...
if (subscription == &onoff)
//Print the new value to the serial monitor
Serial.print("onoff: ");
Serial.println((char*) onoff.lastread);
//If the new value is "ON", turn the light on.
//Otherwise, turn it off.
if (!strcmp((char*) onoff.lastread, "ON"))
//active low logic
digitalWrite(led, HIGH);
else if (!strcmp((char*) onoff.lastread, "OFF"))
digitalWrite(led, LOW);
// if (!
// {
// mqtt.disconnect();
// }
void MQTT_connect()
// // Stop if already connected
if (mqtt.connected() &&
// mqtt.disconnect();
int8_t ret;mqtt.disconnect();Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) // connect will return 0 for connected
Serial.println("Retrying MQTT connection in 5 seconds...");
delay(5000); // wait 5 seconds
if (retries == 0)
Serial.println("MQTT Connected!");
  • Now let's move to the Then part

Setting Up Adafruit

Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, MQTT_NAME "/f/amigos");

Upload the Code to the Board

If you want to Turn your LED off using a voice command




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Beginners Series Updated!

Build a Machine Learning Model API Using YOLOv5 With FAST API

Swarm communication has moved to Discord

2020/May  —  Reading List

Condition Monitoring for Industrial SMEs — Build or Buy?

Top 20 Tools for Android Development

Website & Web hosting

Android Studio: Constraint Layout

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Which types of customers are out there for an IoT modem manufacturer?

IoT modems for different RF options from varying modem suppliers.

9 Ways IoT Is Redefining Web Design & Development Process

Ferran Torres — Barcelona’s Latest Reinforcement