Sunday, May 3, 2020

Reading connected Sensor Data from Google IoT Cloud



In the last blog  Sending Room Temperature and Humidity Data to Google Cloud, we have sent the room temperature and humidity data to google cloud using the Google IoT core platform. This makes us complete our first steps of connecting to the Google IoT cloud and send the sensor data from the device to the cloud. Now next step is to read those data from the Google cloud environment and put it into useful information or any kind of application that we wanted to control using these sensor data.

Here basic use case will be if the temperature of the room goes beyond a certain degree we can able to turn on the cooling devices.

Here we will use the ESP8266 Nodemcu microcontroller to read the sensor data from Google Cloud.
https://en.wikipedia.org/wiki/NodeMCU

Let's begin with the following sequence :
  • Installation of Arduino and ESP8266 configuration.
  • Library Configuration for Google IoT Cloud 
  • Hardware setup configuration.
  • Source code
  •  Demo
Hardware Requirement:
  • ESP8266 NodeMCU 
  • FAN
  • Relay Board (1 channel relay Board )
  • Breadboard
  • Jumper wire
Software Requirement:
  • Arduino IDE.
  • Fritzing Software 
Programming Language:
  • C/C++
  • Python
  • OpenSSL Command line

Introduction:

ESP8266 NodeMCU :

ESP8266 NodeMCU is a single-board microcontroller and low-cost open-source IoT platform. NodeMCU included firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems. ESP8266 is a bite-sized and low const WiFi-enabled microcontroller, it can monitor and control things from anywhere in the world and it just perfect for just about any IoT project.


Specification of ESP866 NodeMCU: 


  • ESP-12E Chip Tensilica Xtensa® 32-bit LX106
  • 80 to 160 MHz Clock Freq.
  • 128kB internal RAM.
  • 4MB external flash.
  • 802.11b/g/n Wi-Fi transceiver ()









Power to the ESP8266 NodeMCU is supplied via the on-board MicroB USB connector. Alternatively, if you have a regulated 5V voltage source, the VIN pin can be used to directly supply the ESP8266 and its peripherals.




The ESP8266 NodeMCU has a total of 30 pins that interface it to the outside world. The connections are as follows:



LCD Display with I2C Interface: 

This I2C 16x2 Arduino LCD Screen is using an I2C communication interface. It means it only needs 4 pins for the LCD display: VCC, GND, SDA, SCL. We Will use the LCD display to display the sensor data temperature and humidity taken via ESP8266 Nodemcu.


You can get this display device from online Roboelements.com.

Sketch Diagram:

The below diagram shows the complete circuit connection for setting up the project. The LCD display will display the temperature and humidity data which is collected using the ESP8266 Nodemcu using the I2C interface. This display information will provide the current temperature and humidity details in-room environment.








Relay is to control the FAN when the digital signal received from the ESP8266 Nodemcu. This trigger is generated based on the temperature data i.e. if the room temperature reached above the threshold value (like 30% above) then FAN will get ON to cool the room temperature.

In Previous blog Part 1: Sending Room Temperature and Humidity Data to Google Cloud we are able to send the DHT data from the Raspberry PI to Google IoT Core.



From the previous blog, we have already created Device Registry "iot-sensor",  pub/sub topic "iot_sensor_dht"  and subscription "pub_sub_iot_sensor_dht" which collects the sensor data from device "" using the MQTT protocol.

Now, same sensor data we need to retrieve from the Google Cloud and send to other LCD display device using the ESP8266 Nodemcu. To-Do so we need to connect our ESP8266 Nodemcu to Google Cloud and fetch the data from Google Cloud using the MQTT protocol.



In this section, we will create another device to store the sensor data for ESP display and then send this device data to ESP8266 using the MQTT over this device. To store the data inside this new device we all create the Cloud function which will read the data from the DHT device and send the related temperature and humidity data to the new ESP device using Cloud Pub/Sub mechanism. This cloud function will ensure that whenever DHT device sends the sensor data to the cloud it will trigger the cloud function to store the result data in the new ESP device 

To connect the ESP device to Google Cloud we need to generate the certificate which can be used to secure the communication between IoT core device to the ESP8266 Nodemcu program.

Objective:

  • Generate the Encryption certificates using the OpenSSL command line.
  • Create a Device topic for ESP8266 "iot_sensor_esp".
  • Create a Cloud Function to store data to a new Device topic. 
  • Logging Cloud function events.

Generate Encryption certificates:

To generate the certificate we will use the Google Cloud Console platform. use the OpenSSL utility to generate the ECC certificate using the below commands.

openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem

Now download the ec_private.pem and ec_public.pem into your local directory which can be used for configuring the Google IoT device and ESP8266 Nokdemcu.

Keep both certificates at a secure place to avoid the disclose your account settings.


Create a new device topic :


  • Go to google cloud IoT page in the Google cloud console (Link).
  • Then go to the "IoT Core" tab available in the left navigation bar.
  • Click on the created Device registry "iot_sensor"  and then click on Devices tab.
  • Click on "+ Create Device" under Devices Tab.



  • Create a device with Device Id "sensor_esp_display"  as display device for sensor data. 
  • The upload generated a Public key certificate in the Authentication Field using the upload option. Then click on the "create" button to finish the device creation. Keep the rest of the field as it is. 

Now you will be able to see the new "sensor_esp_display" device under the device tab. So we have successfully created the new display device for LCD.

Create a Cloud Function to store data to a new Device topic:

Cloud Functions is Google Cloud’s event-driven serverless compute platform. Run your code locally or in the cloud without having to provision servers. We will use this funciotn to read the device "sensor_dht" and send the temperature and humidity information to device "sensor_esp_display".

To add the cloud function follow the below steps:

  • Go to Google cloud console (Link).
  • Then go to the "Cloud Function" tab available in the left navigation bar.


  • Then click on the "Create Function" button in the Menu field.




  •  Then provide Name "function-esp-display" to cloud function and remaining field details as shown below figure.  


  • Then we will add source code from python Main.py (source code link) content from the git repo to the Source code portion. Thin function run by google cloud when device "sensor_dht" data is updated. 
  • Also, update the REQUIREMENTS.TXT with python dependency. 


  • Add the below environment variable and click on the deploy button.


After successful deployment, we will able to send the DHT sensor data to the ESP display device.


Now let's begin with reading the sensor data from google platform using the ESP8266 Nodemcu which then can control FAN and display devices using Arduino programming.


Installation of Arduino software:


To configure and setup ESP8266 we need to download and install the Arduino software. Please download and install the Arduino software from the link Arduino Software.


Click on the Highlighted portion to download the window installer. Open the downloaded installer and install the Arduino software with system admin settings. Once you successfully install Arduino you will be able to open Arduino Application from the start menu.



Once you installed the IDE successfully open the Arduino program from the start menu. Connect your ESP8255 Nodemcu microcontroller board to PC using USB-Serail Port. The matching COM port will be shown in Ardunio SOftware when you connect the ESP8266 Nodemcu with the PC using USB-Serial Cable.

Now you need to install the ESP8266 Board Package. 
  • Go to File -> Preferences from the Arduino Software
  • Add link http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field in the Arduino preferences. 
With this, we are adding this new ESP8266 microcontroller board to Arduino IDE.


  • Open Board manager to install the ESP8266 package. [Tools --> Board (esp8266 Module) -> Board Manager]. Make sure your ESP8266 is connected to PC using USB cable.
  • Install ESP8266 Nodemcu library using the "esp8266" key in the search bar.



  • After the install process, you should see that the esp8266 package is marked INSTALLED. 
Now we need to install the Google IoT Core library which will help in connecting the ESP8266 device to the Google Cloud IoT Platform. To install the library we need to open the library manager
  • Go to   Libary Manager. with path [Tools --> Manager Libraries -> Libary  Manager].
  • Install the "Google Cloud IoT Core JWT" Library using the below search key "Google iot cloud" in the search bar.

  • Close the Boards Manager window once the install process has completed.
Now libraries are installed we are ready to get the run source program to connect the Google IoT core and display sensor information to LCD display.

Coding:

  • Download the source code from my git repository Reading-Sensor-Data-from-Google-IoT-Cloud
  • Open Arduino file Google_IOT_Sensor_ESP.ino using Arduino Software.
  • Edit the file credentials.h with wifi credentials to connect your ESP8266 device to internet service using local wifi connect
  • Also, edit the Google Cloud project parameters which are created with Google IoT Console.

// WiFi parameters
#define WLAN_SSID       "ssid" // use wifi ssid
#define WLAN_PASS       "password" // use wifi password
#define PROJECT_ID  //"<Your Project ID>"
#define REGION  //"<Your Project's Region>"
#define REGISTRY  //""<Your Registry name>"
#define DEVICE  //"<Your device name>"
  • Now update the Certificate private key in which we have created with OpenSSL from Google Cloud shell Console.

  • Copy above private key content to the Arduino file "ciotc_config.hpp".
  • Once after updating the Project and Key details we build the code using Arduino IDE build command.
  • After Build successful Upload the code to connected ESP8266 NodeMCU using USB-serial cable. Arduino IDE will automatically upload the code to ESP8266. 
  • Then ESP8266 will reset itself and start running with uploaded code.
  • you can monitor the console log enabled in using connecting to serial monitor using Arduino IDE. 

Now Arduino code is running we can see that LCD display will show the temperature and Humidity data fetch from the DHT sensor connected to Raspberry Pi. Make sure the Raspberry Pi is running the python program which publishes the Sensor data to Cloud. (Please see the Previous Blog to make sure your DHT sensor is sending the data to Cloud.)

Logging Cloud function events: 

You can log the Cloud sensor data using the below command on Google Cloud shell console. Please run below command to check the data on device "sensor_esp_display".


(prefab-builder-267610)$ gcloud functions logs read function-esp-display

Let's see the Sensor Data from DHT connected from Raspberry Pi to LCD display connected ESP8266 Nodemcu using Google IoT.

Now you have successfully done all this so if you have successfully connected the sketch diagram correctly then you will be able to LCD will start showing the Sensor data temperature and Humidity.





I hope you like the this blog. Please do like, comment, and share this post to everyone who are interested in the IoT project. 






Monday, April 13, 2020

Sending Room Temperature and Humidity Data to Google Cloud




In the last Blog Using Google Cloud IoT Core Platform with a Raspberry Pi, we have seen How to connect the Raspberry Pi as Device Gateway to the Goole IoT Platform. We were able to connect the LED and able to configure the status of LED from Google IoT service. 

In this blog Using the DHT sensor data like humidity and temperature can be collected from the room environment. This sensor data are given to connected Raspberry Pi and then sends this sensor information to the Google IoT Platform using the MQTT Bridge protocol.



Cloud IoT Core is a fully managed service that allows you to easily and securely connect, manage, and ingest data from millions of globally dispersed devices This Device gateway will send the sensor data to the google cloud platform for data storage and processing which can be further use in may services related to IoT.


Hardware Requirement:
  • Raspberry Pi 3 Model.
  • DHT11 Sensor.
  • Jumper Wire
Software Tool Requirement:
  • Xshell Software
  • WinSCP
  • Openssl 
  • Python3

Circuit Diagram:

In this circuit diagram, Raspberry Pi will collect the room temperature and humidity information using the DHT sensor connected via the GPIO pin. Python program running on Raspberry pi will read this sensor information and send it to the Google Cloud using the MQTT protocol (MQTT Bridge).

Please find below basic information related to cloud IoT Project 
  • Create an IoT cloud project and enable Cloud IoT Core and Cloud Pub/Sub APIs (quickstart).
  • Creating registries and devices (Link)
  • Setting up your Raspberry Pi (Tutorial Link).

In my previous blog (Using Google Cloud IoT Core Platform with a Raspberry Pi) I have shown how to connect the Raspberry Pi as Device Gateway with an example of connecting LED light to Google IoT Core.  So I hope you are aware of basic information related to creating the project related to Google IoT core. 


Objective:
  • Create a Device Registry and Device topic.
  • Create Subscription on created device topic.
  • Set up your Raspberry Pi with DHT.
  • Sending DHT sensor data from Device to Google Cloud IoT.
  • Show Received Data with Subscription message.

Create a Device Registry and Device topic:
Let start the below steps to create at least one device registry for this project.


  • Go to google cloud IoT page in the Google cloud console (Link)
  • Then go to the "IoT Core" tab available in the left navigation bar.


    • Click on "Create Registry" to create the new Device Registry "iot-sensor" and  and select the region "asia-east1".

    • Now add the topic to this registry by selecting the option in "Cloud Pub/Sub topics" dropdown. Create the new device "iot_sensor_dht" and then click "Create Topic".

    • Select default HTTP and MQTT protocol.
    • Leave the remaining option as it is and then click below "Create".

    Create a subscription to the registry's Pub/Sub topic:

    Now we will add the new subscription to the created registry topic "iot_sensor_dht".  This is used to subscribe to the data exchange on this device topic.
    • Go to google cloud IoT page in the Google cloud console (Link)
    • Then go to the "Pub/Sub" tab available in the left navigation bar and click on topics.


    • Once you click on Create Subscription you need to provide the subscription details for the topic "iot_sensor_dht".
    • Give the subscription name "pub_sub_iot_sensor_dht" send the delivery type to pull to receive data on this device.
    • Leave the remaining option as it is and then click below "Create". 
    • Now we can able to see our subscription name in the Pub/Sub subscription details.


    Now we have successfully created the Device registry "iot_sensor", Device topic "iot_sensor_dht", and subscription "pub_sub_iot_sensor_dht", next step is to send the sensor data to this topic from Raspberry pi. So lets set up and configure Raspberry pi to establish communication with Google IoT.

    Secure Account Service:


    Service account intended to represent user that needs to get authentication and authorizatoin to access google cloud API's or google cloud service. it is a way of secure communication between the google cloud service and the end-user human or non-human. It simplifies the process of authentication of the end-users devices which can be communicated using this secure way of communication by providing authentication and authorization.

    There are different ways to impersonate a service account to access Google APIs:
    • Authentication using RSA private keys (Uses the Encryption Algorithm)
    • Authorization using Cloud IAM policies

    Authorization using Cloud IAM policies: 

    All service accounts have Cloud IAM policies that grant access to the service account. Some permissions allow users to impersonate, or become, the service account based on the users' credentials.

    Here we will create the service account to access the specific google service need to access the resource by creating Cloud IAM policies. Let's see how to create a service account and download the service account access file.

    • Open Google Cloud Console and then got to the IAM & admin tab available in navigation bar in the left. Click on the "Service Accounts" link.

    • Now create a Service account by clicking on "CREATE SERVICE ACCOUNT" from the IAM & Admin console.



    • Now furnish the details with Name field "serviceaccount" and then click "create"




    • In the next step, we will create the rules to give different access to a user from this service account.  Here we will add roles for "Cloud IoT Admin" and "Pub/Sub-admin" from the Role select bar.
    • Now click on the "Create Key" for the created service account to download the service account file for user.

    • Select the JSON format for the service account file.



    • Service account JSON file will get download to your local directory which will use for authorization and authentication of the device to the google cloud service. Keep this file very securely as it gives you access to your Cloud Service Platform.
    • Now copy this file to your device directory [Raspberry Pi] so that this file can be used in the device program while communication to Google Cloud service.


    • I used WinSCP to copy this JSON file to the Raspberry pi Directory.

     Set up your Raspberry Pi with DHT sensor:


    Connect to your raspberry pi using the SSH connection. Before connecting to Raspberry pi make sure your raspberry pi is connected to a local wifi network and able to access the internet service. Please find details regarding the SSH connection. Once your Raspberry Pi device is in the local network you will be able to access it using VNC Viewer or SSH connection (How to set up WiFi and enable SSH on your Raspberry Pi).
    Here I am using the XHELL software to connect to the raspberry pi using the Wifi IP address assign to the Raspberry Pi device. Provide the connection related information before setting up the ssh connection which includes the username and password credential of Rasberry Pi user.


    Once you were able to connect via SSH you will be able to see below screen after a successful connection to Raspberry Pi.


    • Go to Desktop and create the new folder "DHT".
    • Now you can use the virtual environment to keep the installation local to the workspace instead of installing libraries into the raspberry pi system library which causes extra space and overload on the system.
    • Use below command to create the virtual environment for running the DHT Sensor Program to send sensor data to Google Cloud:
    pip install virtualenv
    virtualenv env
    source env/bin/activate
    •   Once successfully virtual environment is created you will be to below screen over the console.

    • Now run below commands to download and install the required package for creating device setup on the raspberry pi.
    sudo apt update && sudo apt upgrade
    sudo apt install git
    sudo apt install python
    sudo apt install build-essential python3-dev
    • Now download the DHT Adafruit library "Adafruit_Python_DHT", Python library to read the DHT series of humidity and temperature sensors on a Raspberry Pi.
    git clone https://github.com/adafruit/Adafruit_Python_DHT.git
    • Now install this library using the below command
    cd Adafruit_Python_DHT
    sudo python setup.py install

    After successful, this will build and install the library to the system.


    • Now go back to the previous folder "DHT" and download the program to publish the DHT sensor data to google cloud.
    (env) pi@raspberrypi:~/Desktop/IOT/DHT $ git clone https://github.com/sonwaneganesh/Sensor-data-to-google-cloud
    (env) pi@raspberrypi:~/Desktop/IOT/DHT $ cd Sensor-data-to-google-cloud
    (env) pi@raspberrypi:~/Desktop/IOT/DHT/Sensor-data-to-google-cloud $ export GOOGLE_APPLICATION_CREDENTIAL="/home/pi/Desktop/IOT/DHT/prefab-builder-267610-85095c6e6a55.json"
    (env) pi@raspberrypi:~/Desktop/IOT/DHT/Sensor-data-to-google-cloud $ export TOPIC_NAME="iot_sensor_dht"
    (env) pi@raspberrypi:~/Desktop/IOT/DHT/Sensor-data-to-google-cloud $ export PROJECT_ID=prefab-builder-267610
    
    

    • Before running the program we need to do some configuration for setting the Project details and Topic details using an export environment variable to system configuration. We have export TOPIC_NAME and PROJECT_ID details which have created using Google Cloud Console.
    • Additionally, you need to copy the downloaded service account JSON file to raspberry pi and provide the path the variable "GOOGLE_APPLICATION_CREDENTIAL"
    (env) pi@raspberrypi:~/Desktop/IOT/DHT/Sensor-data-to-google-cloud $ export GOOGLE_APPLICATION_CREDENTIAL="/home/pi/Desktop/IOT/DHT/prefab-builder-267610-85095c6e6a55.json"
    • Now download the DHT sensor code from my below git repo Sensor-data-to-google-cloud. Please follow the README file to update the DHT sensor and PIN configuration with Raspberry Pi.
    • You are ready to run our python program to send the sensor data by importing the google cloud and Adafruit DHT library function.
    (env) pi@raspberrypi:~/Desktop/IOT/DHT/Sensor-data-to-google-cloud $ python publish_dht.py
    • After this script will show the result data which have been sent continuously to the Google Cloud.

    • To verify whether data is on google cloud you can pull the data using subscription command on google cloud shell.
    • Run below command for pull data from the DHT sensor device.
    rakhishamkure@cloudshell:~$ gcloud pubsub subscriptions pull pub_sub_iot_sensor_dht --auto-ack --project=prefab-builder-267610 --limit=100
    • You will see the Data received on the google console successfully.


    Now we are able to see sensor data Temperature and Humidity from the DHT sensor connected to Raspberry pi is visible on the google IoT shell console.

    We have successfully able to send sensor data to the Google cloud environment where this information can be processed and analyze to take further different actions based on application we wanted to develop.
    Let's see one use case where if the temperature reaches a certain degree then we can turn on AC or FAN to maintain the conditional temperature environment in the room.

    In the next blog we will use Google Cloud service to control other devices, So please keep yourself updated with my blogs.

    SO please do like, comment and share this to make available to everyone are interesting in making such an interesting IoT project.


    Wednesday, April 8, 2020

    OK google! Turn on Light



    Let's begin with a small tutorial on how to control your home Bulb using the Google Voice assistance which you used in a Mobile device or smart TV at the home.

    Find below the Video link for the complete sequence to create this project at your home.



    Objective:

    With the Internet of Things, we can able to connect every device to the Internet and able to interact with it using the different services available over the internet. This device can be any sensor that can be able to generate any information in the form of an analog or digital signal. this device information can be used in different internet service using data communication and use available service to control these devices from the online service.

    Let's begin with the following sequence :
    • Installation of Arduino and ESP8266 configuration.
    • Adafruit IO service 
    • IFTTT applet service.
    • Hardware setup configuration.
    • Source code
    •  Demo
    Hardware Requirement:
    • ESP8266 NodeMCU 
    • Bulb
    • Relay Board (1 channel relay Board )
    • Breadboard
    • Jumper wire
    Software Requirement:
    • Arduino IDE.
    • Fritzing  
    Installation of Arduino software:

    The Arduino Software (IDE) allows you to write programs and upload them to your Microcontroller board used to connect any sensor device. 

    It easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. Please find the Software Download link for the windows. Now Install the Arduino Desktop IDE for windows using step-by-step instructions using my video reference. 


    Once you installed the IDE successfully open the Arduino program from the start menu. Connect your ESP8255 Nodemcu microcontroller board to PC using USB-Serail Port. The matching COM port will be shown in Ardunio SOftware when you connect the ESP8266 Nodemcu with the PC using USB-Serial Cable.

    Now you need to install the ESP8266 Board Package. 
    • Go to File -> Preferences from the Arduino Software.

    •  Add link http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field in the Arduino preferences. 
    With this, we are adding this new ESP8266 microcontroller board to Arduino IDE. Next, use the Board manager to install the ESP8266 package. [Tools --> Manage Libraries -> Board Manager].

    • Install ESP8266 Nodemcu library using the "esp8266" key in the search bar.


    After the install process, you should see that the esp8266 package is marked INSTALLED. Close the Boards Manager window once the install process has completed.


    Blink Test :


    We'll begin with the simple blink test so it will make sure that our connection to the ESP8266 board is correct and working fine.

    
    void setup() {
      pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
    }
    
    // the loop function runs over and over again forever
    void loop() {
      digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
      // but actually the LED is on; this is because
      // it is active low on the ESP-01)
      delay(1000);                      // Wait for a second
      digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
      delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
    }
    

    Build and upload the code to the connected ESP8266 Microcontroller. Once successful upload ESP8266 will start blinking its LED with a delay of 1 sec.

    Adafruit IO Service:

    Now we have configured ESP8288 with Arduino software we are ready for the next step to create service using the Adafruit IO service. Adafruit IO is the easiest way to get your projects onto the Internet of Things. Using Adafruit IO service you can connect your device our the internet service. Adafruit IO uses MQTT (message queue telemetry transport) as a transport protocol for device communication that Adafruit IO supports. 



    Adafruit IO: Feeds

    Feeds are the core of Adafruit IO which takes part in exacting data communication to and from Adafruit IO service. This feed data can be used to control the sensor device using the microcontroller device like ESP8266. Using an MQTT library or client you can publish and subscribe to a feed to send and receive feed data. you can read more from Adafruit IO site on how to create, edit, and delete your very own feed. 

    Adafruit IO : Dashboard

    The second part is Dashboards allow you to visualize and control Adafruit IO connected projects from any modern web browser. Widgets such as charts, sliders, and buttons are available to help you quickly get your project up and running without the need for any custom code.

    Adafruit IO Key:

    To use the Adafruit service over the internet we need a few connection details when establishing the connection to Adafruit IO service. use the following details to connect an MQTT client to Adafruit IO:
    • Host: io.adafruit.com
    • Port: 1883 or 8883 (for SSL encrypted connection)
    • Username: your Adafruit account username (see the accounts.adafruit.com page here to find yours)
    • Password: your Adafruit IO key (click the AIO Key button on a dashboard to find the key)
    Note: Your Adafruit IO Key should be kept in a safe place and treated with the same care as your Adafruit username and password.


    Below are the parameters which need to be set in the Arduino source code. 
      #define IO_USERNAME  "account_username"
      #define IO_KEY       "aio_key"
    
    

    IFTTT service:

    IFTTT ( If This Then That), is a web-based service that creates chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, or any app service which can be used daily basis.
    With this you’ll have access to an ecosystem of over 600 world-class services, thousands of active developers and millions of consumers.
    Using applets we can able to connect the multiple services together and trigger any action based on the condition set to the trigger. For more details please go to the documentation page of the IFTTT site.

    Our applets will connect the Adafruit feed service to the google voice assistance service. For that, you need to register this service using your Google account details. With google voice assistance we can create the trigger to Adafruit using the trigger command set which can be done easily with IFTTT applet service. So we have created two applets to feed voice data for turning on light and turning off light to Adafruit feed we have created.



    Once we have created service ready we can able to start with setup details and coding part.

    Setup Diagram:



     Component Description:


    ESP8266 NodeMCU :

    NodeMCU is a low-cost open-source IoT platform. NodeMCU included firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems. ESP8266 is a bite-sized and low const WiFi-enabled microcontroller, it can monitor and control things from anywhere in the world and it just perfect for just about any IoT project.
    Specification of ESP866 NodeMCU:
    • ESP-12E Chip Tensilica Xtensa® 32-bit LX106
    • 80 to 160 MHz Clock Freq.
    • 128kB internal RAM
    • 4MB external flash
    • 802.11b/g/n Wi-Fi transceiver
    Power to the ESP8266 NodeMCU is supplied via the on-board MicroB USB connector. Alternatively, if you have a regulated 5V voltage source, the VIN pin can be used to directly supply the ESP8266 and its peripherals.

    The ESP8266 NodeMCU has total of 30 pins that interface it to the outside world. The connections are as follows:

    For more details please visit NodeMCU Link.

    Relay: A relay is an electrically operated switch and like any other switch, it can be turned on or off the electrical device. It can be controlled with low voltages, like the 3.3V or 5V which can be provided by the ESP8266 GPIOs and allows us to control high voltages like 12V, 24V or mains voltage 230V from home AC line. 

    Below is the Fritzing sket of the circuit diagram. You can download this from my git repo google-voice-assistance-with-ESP8266-nodemcu




    Here we controlling 230V bulb using the GPIO pin connected from ESP8266 Micontoller using Arduino code.  The two connectors (with three sockets each) on the left side of the relay module connect high voltage bulb, and the pins on the right side (low-voltage) connect to the ESP8266 GPIOs. 

    Connect D1 pin of ESP8266 to Relay to control as shown in the circuit diagram.


    Coding:


    • Download the source code from my git repository google-voice-assistance-with-ESP8266-nodemcu
    • Open ardino file ESP8266_BULB.ino using Arduino Software.
    • Edit the Wifi Credential to connect your ESP8266 device to internet service using local wifi connection.

    // WiFi parameters
    #define WLAN_SSID       "ssid" // use wifi ssid
    #define WLAN_PASS       "password" // use wifi password
    

    • Then edit the Adafruit connection Details described with Adafruit service.

    // Adafruit IO server details.
    #define AIO_SERVER      "io.adafruit.com"
    #define AIO_SERVERPORT  1883
    #define AIO_USERNAME    "username" // user username 
    #define AIO_KEY         "aio_key"  // use aio key Obtained from account info on io.adafruit.com
    

    • Build the code using Arduino IDE build command.
    • After Build successful Upload the code to connected ESP8266 NodeMCU using USB-serial cable. Arduino IDE will automatically upload the code to ESP8266. 
    • Then ESP8266 will reset itself and start running with uploaded code.
    • you can monitor the console log enabled in using connecting to serial monitor using Arduino IDE. 
    Now your home electric bulb is connected to your google voice assistance.  So you can start your google voice assistance mobile device and send the voice command which you have registered as a command to IFTTT applets.
    Visit below my youtube link here.




    I hope you enjoyed the small IoT project at your homeplace. Please provide your feedback about this project. Please do like, comment, and share my project to reach more people who wanted to learn such interesting projects.






    Smart Home Gardening solution with IOT

    Food is an essential part of day-to-day life. So with agriculture, we can cultivate the plant and made food for a living. We have a very ...