Voice Control NodeMCU ESP8266 Over Internet Using Firebase
Intro: Voice Control NodeMCU ESP8266 Over Internet Using Firebase
In this instructable, I am going to show how to create an Android application to voice control Nodemcu esp8266.
Requirements:-
- NodeMCU ESP8266 development board
- Breadboard
- LED (to check if the project is working)
- Firebase (to create a database)
- 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) attached below
- Then go to MIT app inventor >> projects >> import project (as shown in screenshot 3). Select the file from your computer and upload it. After that open project and navigate to screen2 (as shown in screenshot 4).
Once layout and code logic is ready, go to layout window, click on firebaseDB1 (located at bottom of the workspace), enter database URL and secret key. Also keep ProjectBucket field empty (as shown in screenshot 5).
After that, click on the build button and save app file (.apk file) to your computer. Later transfer that file to your Android device.
STEP 3: Configure Arduino IDE for Nodemcu ESP8266
- First of all, configure Arduino IDE for Nodemcu esp8266. I would recommend this step by step tutorial on NodeMCU basics by Armtronix. Thanks Armtronix for this helpful tutorial.
- After that, add these two libraries (reference screenshot) :-
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.
21 Comments
by1you1 2 years ago
Rishi Rishi 2 years ago
Yes, it means NodeMCU can't connect to firebase. MAke sure you are using latest firebase SSL fingerprints.
Thanks
by1you1 2 years ago
Rishi Rishi 2 years ago
Glad its fixed now :)
berlyv 2 years ago
Rishi Rishi 2 years ago
Working of project is as follow:-
1. Speech to text - App built using MIT app inventor uses Google speech API to convert voice/speech to text. If text matches ON/OFF then app stores 1/0 to firebase database.
2. Function of firebase realtime database - It just stores whatever value it receives from app.
3. Controller - NodeMCU fetch data from firebase and turn switch ON/OFF accordingly.
You can use any text (like turn on fan), just replace it in app .aia file.
Rishigan 3 years ago
Rishi Rishi 3 years ago
You can use same code for relay.
If relay is 5V then use VV pin of Nodemcu or external battery for relay.
Rishigan 3 years ago
Rishi Rishi 3 years ago
Ingredients:-
9V battery
5V or 9V Relay board (You can make your own relay board using transistor and diode).
NodeMCU ESP8266
Connect +VE of battery to +VE of relay and -VE of battery to -VE of relay.
Connect -VE of battery to GND of NodeMCU ESP8266.
Connect D1 pin of NodeMCU to Input of Relay borad.
Connect light bulb to output of Relay board.
That's it!!!
Rishigan 3 years ago
Rishi Rishi 3 years ago
poveirinho 3 years ago
Bom trabalho e continua...
Rishi Rishi 3 years ago
Dguerard 4 years ago
enoch71905 5 years ago
Rishi Rishi 5 years ago
I had re-uploaded project file (.aia file). It must work fine now.
ichsansan_ 5 years ago
Rishi Rishi 5 years ago
By default MIT app inventor SpeechRecognizer supports English only. But you can use an extension to recognize more languages.
Check out:- https://puravidaapps.com/speechRecognizer.php
Special thanks to Taifun for providing this extension. https://groups.google.com/forum/#!topic/mitappinventortest/iPuwrdZw34o
Regards
randofo 5 years ago