Voice Control NodeMCU ESP8266 Over Internet Using Firebase

About: I am a professional blogger from India.

In this instructable, I am going to show how to create an Android application to voice control Nodemcu esp8266.

Requirements:-

  1. NodeMCU ESP8266 development board
  2. Breadboard
  3. LED (to check if the project is working)
  4. Firebase (to create a database)
  5. MIT app inventor 2 (to create Android application)

Step 1: Setup Firebase and Get Secret Key

We are going to use a real-time database by Google firebase. This real-time database will act as a midway broker between Nodemcu and Android device.

  • First of all, navigate to firebase site and log in using your google account.
  • Create a new real-time database.
  • Get real-database URL and secret key to access the database from the app. For a detailed tutorial, you can check out how to use firebase with MIT app inventor.

Step 2: Create Voice Controllable Android App

We are going to use MIT app inventor 2 to create our Android app. Its very simple to use and easy to integrate win Google firebase.

You can do it in two ways:-

Way one:-

  • Create a new app, and then make the layout (as shown in screenshot 1).
  • After that, create code logic (as shown in screenshot 2).

Way two:-

  • Alternatively, you can download the project (.aia file) attache below
  • Then go to MIT app inventor >> projects >> import project. Select the file from your computer and upload it.

Once layout and code logic is ready, go to layout window, click on firebaseDB1 (located at bottom of the workspace), enter database URL and key (as shown in screenshot 3).

After that, click on the build button and save app file (.apk file) to your computer. Later transfer that file to your Android device (screenshot 4).

Step 3: Configure Arduino IDE for Nodemcu Esp8266

  • After that, add these two libraries (reference screenshot) :-

1. Arduino Json

2. Firebase Arduino

Step 4: Code Time

#include "ESP8266WiFi.h"
#include "FirebaseArduino.h"

#define FIREBASE_HOST "test.firebaseio.com"        // Enter Firebase database URL here without 'https://' and last '/' (ex. test.firebaseio.com)
#define FIREBASE_AUTH "secter-key-here"            // Enter Firebase database secret key here
#define WIFI_SSID "Wifi-SSID"            // Enter WiFi SSID to which you want to connect NodeMCU ESP8266
#define WIFI_PASSWORD "Wifi-PassWord"    // Enter password of WiFi
int data,data1,count=0;

void setup()  {

  Serial.begin(9600);                                                   
  pinMode(D2,OUTPUT);
  pinMode(D3,OUTPUT);
 digitalWrite(D2,LOW);
 digitalWrite(D3,LOW);

WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

Serial.print("Connecting to Wifi");
  
  while (WiFi.status()!=WL_CONNECTED){
    Serial.print(".");
    delay(500);
  }

  Serial.println();
  Serial.print("connected:");
  Serial.println(WiFi.localIP());
 Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);                      
}

void loop() {
 
  if (Firebase.failed()) {
    
      Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
      Serial.println(Firebase.error());
      
      delay(1000);
      Serial.println("Error Failed Connection To Firebase!");
    
    count++;
    if (count==10) {count=0; ESP.reset(); }
      return;
      
    }

   else { 

      Serial.println("Everything is ready!");
      delay(30); Serial.println("Everything is ready!");
      delay(30); Serial.println("Everything is ready!");

      delay(30);}

data=Firebase.getString("/data").toInt();  // Fetch data from real-time database

delay(100);
Serial.println(data);
 

data1=data;
Serial.println(data1);    

delay(100);

 if(data1==1)                          // If data is 1, trun on LED 

{                                      
      digitalWrite(D2,HIGH);
       digitalWrite(D3,LOW);
      Serial.println("light 1 ON"); }
    
    else 

    if (data1==0)             // If data is , trun off LED
     {
      digitalWrite(D2,LOW);
       digitalWrite(D3,HIGH);
      Serial.println("light 1 OFF");
    }    delay(300);
}

Step 5: Upload After Some Changes

You must do some necessary changes in code before uploading to Nodemcu.

  • At line 3, enter database URL without 'https://'.
  • At line 4, enter database secret key.
  • At line 5 and 6, don't forget to update WiFi SSID and Wifi password (to which you want to connect NodeMCU ESP8266)

Step 6: Getting Everything Ready

  • Install the app on your Android device.
  • Put NodeMCU esp8266 on the breadboard, connect through PC and upload the program.
  • Connect the positive terminal of LED to D2 pin and the negative terminal of LED to D3 pin (Please comment below if you want circuit diagram).
  • Now run the app and say "turn on lights" or "turn off lights".
  • Enjoy The Magic!

Step 7: Recognize More Languages

Hope everything worked fine for you till step 6.

By default speech recognizer of MIT App Inventor 2 can recognize the English language only. Now if you want to use another language in speech recognition then you need an extension. Just follow a quick workaround.

  • Download Taifun Speech recognizer extension for MIT app inventor.
  • Import this extension in your project.
  • Drag and drop TaifunSpeechRecognizer in place of the default speech recognizer.

That it!

I had tested this extension and it supports 25+ languages including Hindi, Spanish, French, German and many more. For documentation of this extension, you can check its official site.

Need any help regarding this instructable? Please comment below.

Share

    Recommendations

    • Trash to Treasure

      Trash to Treasure
    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest

    5 Discussions

    0
    None
    enoch71905

    Question 1 day ago on Step 7

    Why is the program provided by Inventor 2 not running on the phone?

    未命名55.png
    1
    None
    randofo

    4 weeks ago

    Cool. Do you have any further plans for this tech?

    1 reply
    0
    None
    Rishi Rishi randofo

    Reply 4 weeks ago

    Hi there,

    Thanks for leaving the comment :)

    It is just a part of my college project (voice controlled + remote-controlled robot). Furthermore, I am planning to use GSM module like sim900 at NodeMCU end (to eliminate the need of WiFi for the board).

    Regards