Esp8266 Firebase Connection

Introduction: Esp8266 Firebase Connection

To start with this project, You need the following components:

  • esp8266(NodeMcu v3 Lua)
  • google account (firebase)

You can buy a esp8266 from here:

Step 1: Setting Up Arduino IDE, Install Esp8266 Board:

Install esp8266 Board:

Open Arduino IDE > File > Preferences > additional Boards Manager URLs > "http://arduino.esp8266.com/stable/package_esp8266c...> OK

Tools > Board: > Boards Manager > esp8266 > install

Step 2: Setting Up Arduino IDE, Install Arduino Json Library:

Install Arduino json library:

Install version 5.13.1

Watch install video HERE

Step 3: Setting Up Arduino IDE, ​Install Firebase Library:

Install Firebase library:

Download latest stable build HERE > unzip in "Documents\Arduino\libraries"

NOTE, There is a bug in "v0.3 Bi-directional streaming support" > update fingerprint CLICK HERE FOR INFO

Step 4: Firebase, Create Project:

Create Firebase Project:

Go To "https://console.firebase.google.com"

Step 5: Firebase, Project Rules:

Project rules:

Database(Realtime Database) > rules

{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ "rules": { ".read": true, ".write": true } }

Step 6: Firebase, Realtime Database Data:

Realtime Database data:

Database(Realtime Database) > Data

Add: "LED1" > " "0" "

Step 7: Code:

#include <ESP8266WiFi.h>

#include <FirebaseArduino.h>

#define WIFI_SSID "SSID" #define WIFI_PASSWORD "WIFI PASSWORD" #define FIREBASE_HOST "?????????????.firebaseio.com" #define FIREBASE_AUTH "AUTH KEY"

int LED1 = 4;

void setup() { Serial.begin(115200);

pinMode(LED1, OUTPUT);

delay(2000); Serial.println('\n'); wifiConnect();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

delay(10); }

void loop() { Serial.print(Firebase.getString("LED1") + "\n");

analogWrite(LED1, Firebase.getString("LED1").toInt()); delay(10);

if(WiFi.status() != WL_CONNECTED) { wifiConnect(); } delay(10);

}

void wifiConnect() { WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Connect to the network Serial.print("Connecting to "); Serial.print(WIFI_SSID); Serial.println(" ...");

int teller = 0; while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect delay(1000); Serial.print(++teller); Serial.print(' '); }

Serial.println('\n'); Serial.println("Connection established!"); Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer }

Step 8: Code, Personal Info:

personal info:

SSID > name of your wifi network

WIFI PASSWORD > password of your wifi network

FIREBASE HOST > something like "?????????????.firebaseio.com". You can find it in the "Data" tab of your Realtime Database.

AUTH KEY > Project settings > Service accounts > Database secrets

Step 9: Esp8266 Drivers:

Download:

Click HERE > unzip and install

Step 10: Test the Code:

Upload code:

use esp8266 module in board manager > click "ESP-12E module".

Open serial monitor and set it to "115200".

And you should get the same data as in your database.

Be the First to Share

    Recommendations

    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Space Contest

      Space Contest
    • Micro:bit Contest

      Micro:bit Contest

    11 Comments

    0
    Asyhier
    Asyhier

    1 year ago

    Hello sir. May I know how to store data from arduino to firebase under certain tag value? For example under tag 1 in firebase there will be several data eg:temp, humidity. And under tag 2 there will be also several data and so on.

    0
    kishorek35
    kishorek35

    Reply 7 months ago

    add your tag before values. Ex: "tag_1/value_1", "tag_1/value_2"

    0
    MahidharB
    MahidharB

    1 year ago

    sir i am geting error, when i was verify the code

    Arduino: 1.8.10 (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:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/Firebase.h:30:0,
    from C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/FirebaseArduino.h:22,
    from C:\Users\Mahidhar B\Desktop\firebaseexample\firebaseexample.ino:3:
    C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/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<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;
    ^
    In file included from C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/FirebaseArduino.h:22:0,
    from C:\Users\Mahidhar B\Desktop\firebaseexample\firebaseexample.ino:3:
    C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/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<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;
    ^
    Multiple libraries were found for "ESP8266WiFi.h"
    Used: C:\Users\Mahidhar
    Multiple libraries were found for "FirebaseArduino.h"
    Used: C:\Users\Mahidhar
    Multiple libraries were found for "ArduinoJson.h"
    Used: C:\Users\Mahidhar
    Multiple libraries were found for "ESP8266HTTPClient.h"
    Used: C:\Users\Mahidhar
    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.

    0
    rajmohan060
    rajmohan060

    Reply 1 year ago

    Try changing the line
    int LED1 = 4;
    into
    int LED1 = D2;
    And connect the LED to D2 after uploading the code.

    0
    muhammadadnantalib007
    muhammadadnantalib007

    Question 1 year ago

    In port section no port is showing??plz help me

    0
    rajmohan060
    rajmohan060

    Answer 1 year ago

    open the arduino ide...without connecting the esp8266 go to tools-ports...note the ports available there...then connect your esp8266 repeat the same procedure...u should see a new port appearing in the ports section...select that port and upload the code...
    If this doesn't work u may have a faulty esp8266

    0
    rajmohan060
    rajmohan060

    Reply 1 year ago

    open the arduino ide...without connecting the esp8266 go to tools-ports...note the ports available there...then connect your esp8266 repeat the same procedure...u should see a new port appearing in the ports section...select that port and upload the code.

    0
    patilmayur716
    patilmayur716

    Question 2 years ago on Step 3

    Sir, I am getting this error

    esptool.py v2.6
    2.6
    esptool.py v2.6
    Serial port COM8
    Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
    File "C:\Users\lax63\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
    File "C:/Users/lax63/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
    esp.connect(args.before)
    File "C:/Users/lax63/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    _
    please help me.

    0
    rajmohan060
    rajmohan060

    Answer 1 year ago

    before uploading the code to the esp8266...connect it with the computer...select the appropriate COM port and open the serial monitor set the serial monitor's baud rate to 74800..And hold the Flash button on your esp8266 holding the flash button press the reset button on the esp8266 itself...u should see some lines ending with(1,6) or something similar to this when u press reset button holding the flash button...aftr this step immediately upload your code...it will be uploaded...

    0
    MohamedS595
    MohamedS595

    Answer 1 year ago

    you have a problem in esp8266 it's not connect to pc try to check the port