Login

Send data to a Realtime Database using Google Firebase and NodeMCU

Objectives

  • Set up a realtime database using Google Firebase
  • Send DHT11 sensor data to the realtime database using NodeMCU

Things

  1. NodeMCU board (quantity: 1 no.)
  2. Micro USB cable A to B (quantity: 1 no.)
  3. Breadboard (quantity: 1 no.)
  4. DHT11 sensor (quantity: 1 no.)
  5. Jumper cables (quantity: 3 no.)

Let’s begin!

Google Firebase is a cloud platform owned by Google. It allows you to set up Realtime Databases and much more. Let’s use the DHT11 Digital Humidity and Temperature sensor connected to a NodeMCU to send data to a Realtime Database.

Firebase Realtime Database

Interfacing DHT11 sensor with NodeMCU

Interfacing DHT11 sensor with NodeMCU

 

Installing required libraries on Arduino IDE

Step 1Download the FirebaseArduino library as a ZIP file. Or DOWNLOAD ZIP

Step 2Open Arduino IDE. Navigate to Sketch->Include library->Add .ZIP library.

Step 3Select the downloaded zip file

Step 4Navigate to Sketch->Include library->Manage libraries

Step 5Search for ArduinoJson. Select version as 5.13.1 or lower and install it.

Final Code

Edit the following line and add your Firebase URL

#define FIREBASE_HOST "xxxxxxxxxx.firebaseio.com"

Edit the following line and add your Firebase Database Secret

#define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Edit the following line and add your WiFi credentials

#define WIFI_SSID "xxxxxxxxxx"
#define WIFI_PASSWORD "xxxxxxxxxx"

 

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

Uploading the code

Step 1: Enter the final code in the Arduino IDE window.

  • When you click on New to open a new blank code in the Arduino IDE, you will get a new window with two functions: void setup() and void loop()
  • You can either type commands as shown in the final code under void setup() and void loop() functions or
  • Delete the contents of this window. Then copy and paste the final code in the Arduino IDE window.

Step 2: Compile/ verify the code by clicking on the verify button.

  • Make sure the board is connected to your computer
  • Check if the correct board and port is selected.

Step 3: Upload the code by clicking on the upload button, which is right next to the verify button.

  • The Arduino IDE provides a progress bar when it’s uploading.
  • After it is done, you will see “Done uploading” on the bottom left of your IDE.
  • If you encounter any errors, you need to go back to the code and fix the errors.

 

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X