Press ESC to close

2454 25

IOT with Firebase : Connecting Arduino NodeMCU

IOT with Firebase

Google Firebase helps developers build real-time applications for the Internet of Things but is not without limitations. IOT developers share a lot of common implementation requirements across a wide range of IoT applications. Collecting data, delivering low latency content, and securing communications between devices and back-end services are just three of those common needs. While meeting common needs can be challenging at times. IoT development platforms such as Google Firebase provide services that allow developers to meet many of these requirements.

 

Let’s Get Started With Tutorial :

Here I will begin my large IOT with Firebase Tutorial using Arduino NodeMCU that many people have been asking for. I decided to teach IOT with Firebase through problem solving. This first video covers basic setup guide for connecting Arduino NodeMCU with Google Firebase. It also includes step by step configuration of Firebase Console & Arduino IDE, and much more.
This tutorial is light on problems, I hope you enjoy it.
 
If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials
Transcript / Cheat Sheet :

Software setup

  1. Firstly, Install Arduino 1.6.9
  2. Secondly,  Install Arduino ESP8266 core
  3. Thirdly, Download FirebaseArduino library
  4. Fourthly, Start Arduino
  5. Fifthly, Click Sketch > Include Library > Add .ZIP Library...
  6. And lastly, Choose firebase-arduino-master.zip downloaded in step 3.
Here i will suggest to only use arduino ide 1.6.9 version on Linux machine. Then only this tutorial will work like charm otherwise you will get error.
Now Include firebase library to arduino ide navigate to : Sketch>Include Library > Add .zip Library > {Library _location}
For checking whether the library is installed or not just navigate to Sketch>Include Library >Manage Library & search for firebase library now we are ready to rock. Let’s run our first example on arduino just navigate to : File>Examples>Firebase Arduino>Firebase_Demo_ESP8266.

Code : 

//
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example.
#define FIREBASE_HOST example.firebaseio.com
#define FIREBASE_AUTH token_or_secret//Change line with your WiFi router name and password
#define WIFI_SSID SSID
#define WIFI_PASSWORD PASSWORD
void setup() {
Serial.begin(9600);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(connecting);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(.);
delay(500);
}
Serial.println();
Serial.print(connected: );
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
int n = 0;
void loop() {
// set value
Firebase.setFloat(number, 42.0);
// handle error
if (Firebase.failed()) {
Serial.print(setting /number failed:);
Serial.println(Firebase.error());
return;
}
delay(1000);
// update value
Firebase.setFloat(number, 43.0);
// handle error
if (Firebase.failed()) {
Serial.print(setting /number failed:);
Serial.println(Firebase.error());
return;
}
delay(1000);
// get value
Serial.print(number: );
Serial.println(Firebase.getFloat(number));
delay(1000);
// remove value
Firebase.remove(number);
delay(1000);
// set string value
Firebase.setString(message, hello world);
// handle error
if (Firebase.failed()) {
Serial.print(setting /message failed:);
Serial.println(Firebase.error());
return;
}
delay(1000);
// set bool value
Firebase.setBool(truth, false);
// handle error
if (Firebase.failed()) {
Serial.print(setting /truth failed:);
Serial.println(Firebase.error());
return;
}
delay(1000);
// append a new value to /logs
String name = Firebase.pushInt(logs, n++);
// handle error
if (Firebase.failed()) {
Serial.print(pushing /logs failed:);
Serial.println(Firebase.error());
return;
}
Serial.print(pushed: /logs/);
Serial.println(name);
delay(1000);
}

Configuration of IOT with Firebase

  1. Start Arduino
  2. Open File > Examples > FirebaseArduino > FirebaseRoom_ESP8266
  3. In above FirebaseRoom_ESP8266: Replace WIFI_SSID and WIFI_PASSWORD with WiFi credentials
  4. Go to https://firebase.google.com/console/ and create a new Firebase Project
  5. Go to Database
  6. Copy the Database hostname (Database URL without https:// and trailing /)
  7. In Above code FirebaseRoom_ESP8266: replace FIREBASE_HOST with the Database Hostname
  8. Go to ⚙ > Project Settings > Database > Database secrets
  9. Click Firebase Secrets > Show
  10. Copy the Database Secret
  11. In FirebaseRoom_ESP8266: Replace FIREBASE_AUTH with Database Secret
  12. Select the board Board > ESP8266 Modules > NodeMCU 1.0
  13. Then Select the serial port Port > /dev/tty...
  14. Select the upload speed Upload Speed > 115200
  15. Click Sketch > Upload
After Uploading the sketch, Open you Serial monitor and select baud rate of 9600. If everything goes well you should able to see output screen below .
That’s end up with great tutorial on getting started IOT with Firebase using Arduino NodeMCU. And if you guys are facing any issues let me know in comment section below 🙂
 
 
 
 
 

25 Comments

  1. shehaballnews on March 26, 2018

    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

  2. kavin sharma on March 26, 2018

    generally we get this error when there is some connection with arduino. Navigate to tools-> port you should be able to detect Arduino in Usb. If it doesn't work try uploading some basic code in nodemcu like led blink

  3. Anonymous on April 11, 2018

    In the above example I am getting error as "setting / number failed" can you please help me to remove it.

  4. Anonymous on June 2, 2018

    same problem getting this error setting / number failed.. what should we do??

  5. Chemwen0 on June 5, 2018

    Hi, im also getting an error. setting/number failed

  6. Kavin Sharma on June 20, 2018

    this error arises when, we are using a wrong Arduino ide , i vll suggest to download Arduino ide 1.6.9

  7. Anonymous on July 26, 2018

    what if, internet got disconnected will all the appliances will shut down ?

  8. Unknown on August 2, 2018

    Sir you are connecting node mcu to firebase realtime datebase in this video. I want to ask whether it is possible to connect node mcu to firebase storage so that we can save images through node mcu.

  9. Unknown on August 3, 2018

    I'm using the same setup as you, Ubuntu with Arduino IDE 1.6.9 – I'm starting to think that is a problem with Firebase… right?

  10. Unknown on August 3, 2018

    I'm using the same setup as you, Ubuntu with Arduino IDE 1.6.9 – I'm starting to think that is a problem with Firebase… right?

  11. Kavin Sharma on August 5, 2018

    no

  12. Unknown on August 25, 2018

    same whit me

  13. Unknown on September 4, 2018

    Hey..I'm too facing this same,Kindly Help me

  14. Unknown on September 6, 2018

    I am also facing that problem, I think problem with firebase. anyone has solved?

  15. Unknown on September 10, 2018

    here is a problem.. nodemcu esp8226 not work when wifi disconnect and not reconnect till i re power
    it have anyone solution for this?

  16. MADHU on September 14, 2018

    I am getting Setting/number failed,
    I included all libraries, host and authtoken is also correct, and it got connected to my hot-spot.

  17. Anonymous on October 13, 2018

    C:UsersuserAppDataLocalTempbuild8b84799429a172a39e2d158330851881.tmplibrariesfirebase-arduino-masterFirebaseArduino.cpp.o: In function `String::substring(unsigned int) const':

    c:usersuserdownloadsarduino1.6.8-espduino-2.1portablepackagesesp8266toolsxtensa-lx106-elf-gcc1.20.0-26-gb404fb9-2xtensa-lx106-elfincludec++4.8.2bits/basic_string.tcc:732: undefined reference to `__cxa_guard_acquire'

    C:UsersuserAppDataLocalTempbuild8b84799429a172a39e2d158330851881.tmplibrariesfirebase-arduino-masterFirebaseArduino.cpp.o: In function `FirebaseArduino::readEvent()':

    c:usersuserdownloadsarduino1.6.8-espduino-2.1portablepackagesesp8266toolsxtensa-lx106-elf-gcc1.20.0-26-gb404fb9-2xtensa-lx106-elfincludec++4.8.2bits/basic_string.tcc:732: undefined reference to `__cxa_guard_release'

    C:UsersuserAppDataLocalTempbuild8b84799429a172a39e2d158330851881.tmplibrariesfirebase-arduino-masterFirebase.cpp.o: In function `operator+, std::allocator >':

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_acquire'

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_release'

    C:UsersuserAppDataLocalTempbuild8b84799429a172a39e2d158330851881.tmplibrariesfirebase-arduino-masterFirebase.cpp.o: In function `ArduinoJson::JsonArray::invalid()':

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_acquire'

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_release'

    C:UsersuserAppDataLocalTempbuild8b84799429a172a39e2d158330851881.tmplibrariesfirebase-arduino-masterFirebase.cpp.o: In function `ArduinoJson::JsonObject::invalid()':

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_acquire'

    C:UsersuserDownloadsarduino1.6.8-ESPDuino-2.1portablesketchbooklibrariesfirebase-arduino-mastersrc/Firebase.cpp:39: undefined reference to `__cxa_guard_release'

    collect2.exe: error: ld returned 1 exit status

    this is the error. How I can fix this, sir? Please help me thank you.

  18. nurul izzati on November 22, 2018

    kavin sharma…i still error.

  19. Unknown on February 5, 2019

    Arduino: 1.6.8 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

    In file included from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/lwip2/include/lwip/opt.h:51:0,

    from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/lwip2/include/lwip/init.h:40,

    from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3coresesp8266/IPAddress.h:27,

    from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3librariesESP8266WiFisrc/ESP8266WiFi.h:31,

    from C:UsersTUSHAR~1AppDataLocalTemparduino_modified_sketch_340892FirebaseDemo_ESP8266.ino:20:

    C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/lwip2/include/lwipopts.h:1301:2: error: #error TCP_MSS must be defined

    #error TCP_MSS must be defined

    ^

    C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/lwip2/include/lwipopts.h:2381:2: error: #error LWIP_IPV6 must be defined

    #error LWIP_IPV6 must be defined

    ^

    C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/lwip2/include/lwipopts.h:3534:2: error: #error LWIP_FEATURES must be defined

    #error LWIP_FEATURES must be defined

    ^

    In file included from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3librariesESP8266WiFisrc/ESP8266WiFiSTA.h:29:0,

    from C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3librariesESP8266WiFisrc/ESP8266WiFi.h:34,

    from C:UsersTUSHAR~1AppDataLocalTemparduino_modified_sketch_340892FirebaseDemo_ESP8266.ino:20:

    C:UsersTusharSinghPatelAppDataLocalArduino15packagesesp8266hardwareesp82662.5.0-beta3/tools/sdk/include/user_interface.h:34:2: error: #error LWIP_OPEN_SRC must be defined

    #error LWIP_OPEN_SRC must be defined

    ^

    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    help ?????

  20. mjsharma on March 2, 2019

    Whoever are getting error after compiling, don't use newer versions(beta) of "ArduinoJson" by "Benoit Blanchon" library, rather install lower versions like 5.13.5 . It will work fine.

  21. today on March 18, 2019

    Hi bro thanks for this great article i really like this post and i love your blog you;—————> JAZZ MOBLINK 2019 NEW TRICK 10000% WORKING <—————

    —-Zong FREE INTERNET 2019 WORKING TRICK—-

    —UFONE FREE INTERNET 2019 100% WORKING TRICKS–
    <———————————————————————————————————–
    –Earn money easy daily 20$

    ————————————————————————————–
    GET FREE RECHARGE ON ALL SIMS NETWORKS
    ————————————————————————————————————————–
    –EARN FREE 100$ WITHOUT INVESTMENT

    ——————————————————————————————————
    How to Protect your articls on blogger

    ——————————————————————————————————–
    FREE LIVE TV ON ALL SIMS 100WORKING NEW METHOD

    =============================================================================================================
    Free do follow backlinks 110+ genrate YOUR WEBSITE

    =============================================================================================================
    Top 15BEST Google Adsense Alternatives

    ===============================================================
    BEST TRICK INCRESS GOOGLE ADSENSE
    —————————————————————————————–
    Top 15 Highest Paying Affiliate Programs Plaforms List
    —————-
    FREE WEBHOSTING LIFE TIME BEST HOSTING NO AD UNLIMITED FREE

  22. gua on February 24, 2020

    same,anyone know the solution?

  23. Swapnamoy@CIEM on April 1, 2020

    Yes I have faced same problem

  24. Unknown on May 5, 2020

    Arduino: 1.8.12 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

    In file included from C:UsersuserDocumentsArduinolibrariesFirebaseArduinosrc/Firebase.h:30:0,

    from C:UsersuserDocumentsArduinolibrariesFirebaseArduinosrc/FirebaseArduino.h:22,

    from C:UsersuserAppDataLocalTemparduino_modified_sketch_333960FirebaseRoom_ESP8266.ino:21:

    C:UsersuserDocumentsArduinolibrariesFirebaseArduinosrc/FirebaseObject.h:109:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6

    std::shared_ptr> buffer_;

    ^

    In file included from C:UsersuserDocumentsArduinolibrariesFirebaseArduinosrc/FirebaseArduino.h:22:0,

    from C:UsersuserAppDataLocalTemparduino_modified_sketch_333960FirebaseRoom_ESP8266.ino:21:

    C:UsersuserDocumentsArduinolibrariesFirebaseArduinosrc/Firebase.h:86:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6

    std::shared_ptr> buffer_;

    ^

    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

Leave a Reply