How to fetch data from Firebase to Nodemcu | Step by step instructions
How to fetch data from Firebase to Nodemcu
Hello guys, welcome back. In this tutorial, we are going to learn how to fetch data from Firebase to Nodemcu. Also, a LED ON and OFF example is used to explain this tutorial. This can be simply described as an IoT project. Because the Internet is required to turn this LED on and off. You may remember that we used the Blynk app for this in a previous lesson. Today we will use Firebase software instead. Click think for more details in the Nodemcu ESP8266. Click this link for more information about Nodemcu ESP8266.
What is the Firebase?
Firebase is simply software used to manage and modify android / IOS applications, web services, IoT sensors, and hardware. This is a service provided by Google. Also, that is an open-source web application software. Just having a google account is enough to work with this. Also, The following steps will show you how to set up the firebase.
OK, let’s learn this lesson step by step. So, the required components are given below.
Secondly, connect these components, For that, use the circuit diagram below.
Step 3
Thirdly, let’s set up the firebase and Arduino IDE Program. For that, follow the steps below.
Step 1
OK, first open your internet browser and search for “Firebase” here. Then, click on the second result on the page.
Step 2
Now, click the “Get Started” button. After, click the “New project” button.
Step 3
Next, enter your project name and click the “Continue” button. Click again the “Continue” button.
Step 4
OK, select your account now, then select “Default Account for Firebase”. Then click the “Create Project” button. After, you can see how your project is set up. It only takes a few seconds. Now, your project is ready. If all this is correct, click the “Continue” button.
Step 5
Now, click on the “Project Settings” button and then the “Service Account” button. After, click the “Database Secrets” button on this page.
Step 6
Well, now we will pause the Firebase setup and set up the Arduino IDE program. The code is as follows.
Secondly, define the variables that should be included in Firebase Details and WIFI Connection Details. We will include this information later.
#define FIREBASE_HOST ” ” // Firebase host
#define FIREBASE_AUTH ” ” //Firebase Auth code
#define WIFI_SSID ” ” //Enter your wifi Name
#define WIFI_PASSWORD ” ” // Enter your password
Thirdly, the LED-connected pin is configured as an OUTPUT pin. Later, the WIFI library and firebase library were begun in the void setup.
void setup() {
Serial.begin(9600);
pinMode(D1, OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“Connecting”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
delay(500);
}
Serial.println();
Serial.println(“Connected.”);
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.set(“LED_STATUS”, 0);
}
Lastly, in the invalid loop, the values received through the Firebase are entered into a variable called “fireStatus”. Then if that value is 1 the LED will turn ON. If 0, the LED turns off.
void loop() {
fireStatus = Firebase.getInt(“LED_STATUS”);
if (fireStatus == 1) {
Serial.println(“Led Turned ON”);
digitalWrite(D1, HIGH);
}
else if (fireStatus == 0) {
Serial.println(“Led Turned OFF”);
digitalWrite(D1, LOW);
}
else {
Serial.println(“Command Error! Please send 0/1”);
}
}
Step 7
Okay, now let’s go back to the Firebase side. Then copy and paste this code on the Arduino IDE program.
Step 8
Afterward, click the “Realtime Database” button on the left side. Next, click the “Create Database” button. Then select the Database location and click the “Next” button. Next step select the “Start in test mode” after, clicks the “Enable” button.
Step 9
Now, copy and paste this Firebase host link into the program.
Step 10
Then, click the “+” icon and enter “LED_STATUS” for the name and “0” for the value. Next, click the “Add” button. OK, now set up the Firebase software is enough.
Step 11
Now, fill in the program’s WIFI connection information. For that. Enter the WIFI name and WIFI password.
Step 12
Now, let us download and install the JSON 5.13.5 library which is an essential library to work with firebase. For that, use the pictures below.
Step 13
Lastly, select the correct board and port, After, upload this program to the Nodemcu board. OK, now we can ON and OFF the LED using Firebase. For that, open the Firebase again and update the values to 1 and 0.
Below is the full video guide. We will meet in the next tutorial.
Hello guys, Welcome back to my channel. Today we are going to talk about motor control. Motor control is a very important topic in learning Arduino. In this article, we…
MQ3 alcohol sensor Arduino code Hello guys, welcome back to another tutorial from the SriTu Hobby. In this tutorial, we will learn how to work the MQ3…
Hello, welcome back. In this tutorial, we will learn how to control a lot of servo motors using one Arduino board. Also, we use a 16 channel PWM servo motor…
Hello friends, Welcome back to my blog. We described the LED bulb display in a previous post. It is very difficult to show what we want with this LED display….
Process of this Digital Rular When activated in this project, the ultrasonic sensor calculates the distance to the barrier in front of it. This distance is then taken by the…
Hello and welcome back. In this project, we will learn how to make a DIY simple Bluetooth control car using the Arduino. Especially, we can control this car using three…
4 Comments
I am Brijesh Dungrani. I am facing problem in the project of NODE MCU with Firebase. I need your support.
I am Brijesh Dungrani. I am facing problem in the project of NODE MCU with Firebase. I need your support.
what is your issue?
i do all settings as per your instructions but still my LED is not blinking.
Please double-check the program.