Objectives
- Set up a realtime database using Google Firebase
- Send DHT11 sensor data to the realtime database using NodeMCU
Things
- NodeMCU board (quantity: 1 no.)
- Micro USB cable A to B (quantity: 1 no.)
- Breadboard (quantity: 1 no.)
- DHT11 sensor (quantity: 1 no.)
- 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 1: Download the FirebaseArduino library as a ZIP file. Or DOWNLOAD ZIP
Step 2: Open Arduino IDE. Navigate to Sketch->Include library->Add .ZIP library.
Step 3: Select the downloaded zip file
Step 4: Navigate to Sketch->Include library->Manage libraries
Step 5: Search 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.