Okay Google! Light ON


By Paras Chowdhary, Intern, Raylog Industries

A Product based on IoT (Internet of Things).

Imagine a world in which every device in the home, workplace and car are connected. A world where the lights automatically turn on when the car approaches the driveway, the coffee starts brewing when the morning alarm goes off and the front door automatically unlocks when approached by a member of the household, but stays locked when a stranger arrives on the front step. That is the type of world the “Internet of Things” can create. So this product plays an important role in future as the world of “Home Automation” is spreading day by day.

Here, we are going to build a product which turns on your light when you say a phrase to the Google assistant for e.g. “OK Google Turn on my light”.

In today’s world it’s not just important to do different things but also much more important to know and learn what we do. Before beginning the construction of this product we will know that what all the different things we are going to learn. First and fore most part of this product is the IoT platform that is “Adafruit io” which allows us to connect different things together, the “IFTTT”(if this then that) which acts normally a trigger between the google assistant and adafruit.io it does a simple task that is if this happens then that has to be done, and then we will also learn about “WEMOS D1 WIFI” controller which is an Arduino compatible, which is going to turn on light whenever a change happens in the data in adafruit.io.


The following are the steps to follow.

Step 1:
Requirement list:
  1. Wemos D1 WiFi (Arduino compactable)
  2. Micro B type USB cable
  3. Relay (5v, 10amp)
  4. LED – 3 nos each (red, blue, green)
  5. Buzzer
  6. Bulb (20w, 220/240v)
  7. Bulb holder
  8. Jumper wires 8nos(male to male 5,male to female 3)
  9. Breadboard


Step 2:
Description of Hardware:
1. Wemos D1 WiFi:

The WeMos D1 is an ESP8266 WiFi based board that uses the Arduino layout with an operating voltage of 3.3V.


Here are the specification of the board:

Microcontroller ESP-8266EX
Operating Voltage 3.3V
Digital I/O Pins 11
Analog Input Pins 1
Clock Speed 80MHz/160MHz
Flash 4M bytes
Length 68.6mm
Width 53.4mm
Weight 25g


The Wemos d1 is WiFi development board based on ESP8266 12E. the functioning is similar to that of  NODEMCU, except that the hardware is built resembling Arduino UNO.

The D1 board can be configured to work on Arduino environment using BOARDS MANAGER. So, it is not necessary to use a separate Arduino board, the D1 itself can be programmed on Arduino IDE. This is handy in using with IoT projects. Further many Arduino SHIELDs are compatible with the D1 board. Different versions of D1 boards are available in the market    R1  ,  R2  , MINI. As the name implies D1 Mini is a smaller version and also differs in cost.

As the ESP12 chip has only one ANALOG pin, on board there is only A0 & other analog pins are dummy. In summary, the board is controlled by the ESP8266 chip (a 32-Bit processor) and has a larger flash memory compared to an Arduino Uno. It consists of 11 digital I/O pins and 1 analog (input) pin. The board can be connected using a Micro-B type USB cable.


Few digital Pins description required in our product

Hardware        software

D4        =        D2

D6        =        D6

D5        =        D5

D8        =        D3

D9        =        D4


2. Relay(240v, 20 amp):

A relay is an electromagnetic switch operated by a relatively small electric current that can turn on or off a much larger electric current.

The heart of a relay is an electromagnet (a coil of wire that becomes a temporary magnet when electricity flows through it). You can think of a relay as a kind of electric lever: switch it on with a tiny current and it switches on (“leverages”) another appliance using a much bigger current.

Why is that useful? As the name suggests, many sensors are incredibly sensitive pieces of electronic equipment and produce only small electric currents. But often we need them to drive bigger pieces of apparatus that use bigger currents. Relays bridge the gap, making it possible for small currents to activate larger ones. That means relays can work either as switches (turning things on and off) or as amplifiers (converting small currents into larger ones).

In our product we use relay for converting a low power current coming out of controller to high power current required to turn on the bulb.

It consists of three input terminals and three output terminals, the input terminals are vcc(voltge) , gnd(ground), and the data in pin. The output terminals are NO(normally open), NC(normally close) and COM(common). Any of the two combination can be used NO and COM or NC and COM. The concept of normally open and close is that a switch is said to be normally open when on closing it current passes and normally close when on opening it current passes.


Step 3:
Configuring the Cloud
1. Configuring the Adafruit.io to create a feed called light :

Adafruit.io is a cloud service – that just means we run it for you and you don’t have to manage it. You can connect to it over the Internet. It’s meant primarily for storing and then retrieving data but it can do a lot more than just that!

What can Adafruit IO do for me?

  • Display your data in real-time, online
  • Make your project internet-connected: Control motors, read sensor data, and more!
  • Connect projects to web services like Twitter, RSS feeds, weather services, etc.
  • Connect your project to other internet-enabled devices
  • The best part? All of the above is do-able for free with Adafruit IO


Step 1: Go to the www.adafruit.io website and sign up account and then sign in using username and password.


              Step 2: Create a new dashboard by giving it any name from actions button.



              Step 3: Create a new feed in your dashboard by any name for eg: light, create a toggle block for the feed.



              Step 4: Go to view AIO KEY and remember the username and active key, you will need this in your code.


2. Configuring IFTTT(if this than that) for making changes in adafruit.io through google assistant.

If This Then That, also known as IFTTT, is a free web -based service to create chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as GmailFacebookTelegramInstagram, or Pinterest. For example, an applet may send an e-mail message if the user tweets using a hashtag, or copy a photo on Facebook to a user’s archive if someone tags a user in a photo. In addition to the web-based application, the service runs on iOS and Android.


               Step 1: Go to the https://ifttt.com/  sign up with your google account and sign in then go to my applets and create new applet



              Step 2: click on if this , select google assistant and write a simple phase then create.



              Step 3: Click on “That” , select adafruit and give 1 as send data to light feed and create action.



              Step 4:  In the same way create a one more applet for turning off your lights and give 0 as to send data to light feed and IFTTT is now configured then sign out from IFTTT.


3. Configuring Arduino ide software for programming the Wemos controller:


               Step 1. Go to the website https://www.arduino.cc/ then, go to software-downloads and scroll down and select “ windows zip file for non admin install” and click on just download.



              Step 2: Open the zip file downloaded and extract it to the required location in your system then open the      software.



              Step 3:  Now you need to install CH340 driver, As the serial chip used on D1 is CH340 , go to github website and download the driver then in the software you need to select the board  ESP8266 12E from the list of boards and select the com port in control setting of your system.



Step 4:

Circuit diagram:

Make the connections as per the circuit shown below.


Below are the connection:

  1. Vcc of relay     ->    3 v Wemos
  2. Gnd of relay    ->    gnd of Wemos
  3. Relay input pin     ->    digital pin D4 of Wemos
  4. D9 of Wemos    ->    anode of red LED
  5. D8 of Wemos    ->    anode of buzzer
  6. D6 of Wemos    ->    anode of green LED
  7. D5 of Wemos     ->    anode of blue LED
  8. Gnd of Wemos    ->    common ground to all LED and buzzer
  9. Com of relay     ->    one terminal of power supply
  10. NO of relay     ->    one terminal of bulb and other to power supply


Led and Buzzer interfaces:-

Sometimes it is very much important to know whether the different programs are executing by the controller or no. In our product we have programs such as WiFi connection and whether the relay has been triggered or no so; we use different interfaces to indicate all these. We use red LED for power indication, blue LED for WiFi connectivity indication, green LED and buzzer for trigger indication.


Brief working of our product:-

The Wemos controller is coded and code is dumped into it. A complete code with explanation is mentioned below. After powering up the controller, the red LED glows and its first job is to check for the WiFi connectivity for given username and password, once the connection has been established the blue LED goes high showing connectivity of WiFi and then it gets subscribed from MQTT server to the adafruit.io using the username and AIO key given in the code, continuity checks for any changes in the feed “light” if there any changes occurs in the server ,the signal is passed to relay’s input and simultaneously the green LED glows , buzzer sounds. The current passed out by the controller is in terms of milli amperes which is not sufficient by the bulb to glow so, the output of the controller is given to the relay which converts the low current to the required current by any ac appliance for example bulb.


Code explanation:

Complete Wemos code is given at the end; here is the explanation of few important part of it.


->We include following libraries required for our program at beginning of program, as we are using a medium of WiFi for connecting to internet the “ESP8266Wifi” should be installed and one more library that is “Adafruit_MQTT” should also be installed to perform the MQTT subscribe functions.

#include <ESP8266WiFi.h>

#include “Adafruit_MQTT.h”

#include “Adafruit_MQTT_Client.h”


->Set your WiFi name, password, adafruit username, Aio key, MQTT server and port

#define WIFI_SSID “xxxxxxxxxx”

#define WIFI_PASS “*********”

#define MQTT_SERV “io.adafruit.com”

#define MQTT_PORT 1883

#define MQTT_NAME “user_name”



->Following lines of codes help to set up MQTT, WiFi clients and also set up the feed you’re subscribing to

WiFiClient client;


Adafruit_MQTT_Subscribe light = Adafruit_MQTT_Subscribe(&MQTT, MQTT_NAME “/f/light”); //  light is feed name given in adafuit.io


-> The below code is written in void setup which runes only once, following codes are used for connecting to WiFi

Serial.print(“\n\nConnecting Wifi… “);


while (WiFi.status() != WL_CONNECTED){





->Subscribe to light feed:



-> Ping the server to keep the MQTT connection alive and MQTT connect:

void MQTT_connect()


int8_t ret;

// Stop if already connected.

if (MQTT.connected())




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)


// basically die and wait for WDT to reset me

while (1);



Serial.println(“MQTT Connected!”);


if (!MQTT.ping())





Download the complete code here.

Study article by Paras Chowdhary, Intern, Raylog Industries