Table of Contents
ESP32 Firebase Project Description:
ESP32 Firebase- Before I am going to explain how to use the ESP32 with Firebase, first, I am going to talk about some of my previous projects based on the Google Firebase. In my last tutorial on the Google Firebase Database, I explained how to send a sensor value from the Nodemcu ESP8266 Wifi Module to the Google Firebase Database. If you want to use Nodemcu ESP8266 WiFi Module with the Google Firebase then read my article “Nodemcu Firebase Database Tutorial“, this is a beginners level project and explains the very basics like for example, how to setup your own Google Firebase account, How to connect an analog sensor with the Nodemcu ESP8266, and send the sensor data to the Firebase Database.
I also uploaded an advanced version based on the Nodemcu ESP8266 and Firebase Database. The advanced version is about the students’ attendance system using GSM sim900A module, RFID MFRC522, 16×2 LCD, and the Google’s Firebase Database. This is really an amazing project, you will learn a lot of new things like for example, how to use an RFID module, GSM Module, and how to send attendance data from the Arduino to the Google Firebase Database. But before you are going to make the advanced version first I recommend read my getting started tutorial on the Nodemcu Firebase Database.
In today’s tutorial, we will be using the ESP32 Wifi + Bluetooth Module by the Espressif Systems with the Google Firebase database. This is the same company that created the ESP8266 series of chips, modules, and development boards. Unlike the Nodemcu ESP8266 Wifi Module, the ESP32 Wifi + Bluetooth module is becoming very famous as it consist of more analog pins; while in Nodemcu ESP8266 there is only one Analog pin A0.
About the Sponsor “PCBWay”:
This ESP32 Power Supply PCB board is sponsored and manufactured by the PCBway Company, which is one of the most experienced PCB and PCB assembly manufacturer. They create high-quality PCBs at reasonable prices, Only 5 dollars for 10 PCBs and 30 dollars in total for 20 PCBs assembly; besides this the new members also get a 5 Dollars bonus. As you can see the quality is really great, the silkscreen is quite clear and the black solder mask looks amazing. I am 100% satisfied with their work.
As this is a getting started tutorial based on the ESP32 and Firebase, I will try to keep things simple so that you can easily follow this tutorial. I will be using a variable resistor or potentiometer as the Sensor. As you can easily arrange a variable resistor or potentiometer; later you can replace a variable resistor with any analog sensor you want.
In this tutorial, we will cover,
- About the Google Firebase
- Circuit Diagram Explanation
- ESP32 Firebase programming and finally
Without any further delay let’s get started!!!
The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:
Other Tools and Components:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
About the Google Firebase Database:
Google Firebase is a Google-backed application development software used for creating, managing, and modifying data generated from any android/IOS application, web services, IoT sensors & Hardware. To learn more about the Google Firebase Console, you can read the official Google Firebase Documentation from Google Firebase.
Some of the most commonly asked questions about the Google Firebase Database.
What is Google Firebase Database?
What type of Database is Firebase?
Firebase is a Backend As A Service or BAAS, meaning it is a NoSQL data store that is in the cloud that your clients can access directly in realtime. Now this means Firebase has it’s own Realtime Database, Cloud Storage, Authentication, Hosting and many other services.
Is Firebase better than SQL?
Unlike SQL there’s no schema for the database, no tables, no columns, it’s just a combination of key/value pairs. Firebase is based on a data structure used by the NoSQL database is vastly different from those used in a relational database. Some operations are faster in NoSQL than relational databases like MySQL.
Which is better Firebase or AWS?
If you’re a small team setting up, Firebase might serve you better than a heavy AWS setup. It also has a lower learning curve than AWS. On the flip side, Firebase makes it difficult to query larger datasets. Their database also doesn’t provide relational data, which could spell trouble for some newer companies.
Can I use Firebase for Free?
Yes, it’s free. You can use Analytics for advanced messaging – out of the box. Which products are paid? Firebase’s paid infrastructure products are the Realtime Database, Firebase Storage, Hosting, and Test Lab.
Is Firebase good for large database?
The real-time functions in Firebase are not only suited for, but designed for large data sets. The fact that records stream in real-time is perfect for this. Performance is, as with any large data app, only as good as your implementation.
Is Firebase a DBMS?
FireBase It’s a cloud service Also FireBase is a NoSQL database. In FireBase Data stored/processed in a cloud. FireBase is suitable for real time applications. MySQL is a relational database management system (RDBMS)
Which language is used in Firebase?
Can Firebase Handle million users?
This is possible since firebase is just a bucket of data that can be easily allocated for each user. Queries with limited sorting and filtering functionality can be performed with the firebase database. Cloud firestore assures automatic scaling and can handle 1 million concurrent connections and 10,000 writes/second.
Is Firebase secure?
1 Answer. The short answer is yes: by authenticating your users and writing security rules, you can fully restrict read / write access to your Firebase data. In a nutshell, Firebase security is enforced by server-side rules, that you author, and govern read or write access to given paths in your Firebase data tree.
Why Firebase is used in Android?
Firebase allows you to build apps which need authentication, database, file storage, analytics and server side functionality without having to own and manage infrastructure and software required for server side support. Using firebase, you can access google cloud store for storing images from your app.
How fast is Firebase real-time database?
Firebase uses a document storage (JSON Documents), similar to MongoDB, so there are documents with fields and sub documents, and nothing like rows or tables. Back to your question, yes Firebase is blazingly fast. I’ve used Firebase in building two apps of mine, and the response is amazing.
Is learning Firebase easy?
Yes it is really easy for beginners. Firebase has very good documentation. It is easy to connect you application to Firebase. If you are an android developer using Android Studio, you can connect your app to Firebase with just a few clicks using assistant, without using a single line of code.
Google Firebase Account Setup for the ESP32?
You can start by opening Google search engine and search for the Firebase Console.
After you click on the Firebase Console, this will take you to the Firebase Console main page.
To start a new project, you can click on the add project. This will open a new page.
In the first step, I entered my project name as the esp32andfirebase. You can select any project name as you want. After you enter the project name then you can click on the Continue button; this will open the step 2.
In step 2, you don’t have to do anything, as you can see the Enable Google Analytics for this project is already enabled, if not you can enable this. Now, Simply click on the Continue button. This will take you to the final step 3.
Click on the drop down menu and select my site.
Click on the Create project button, this will start loading, you can wait for a few seconds.
After your project is ready, now you can click on the button.
As you can see a project with the name esp32andfirebase has been created successfully. You can click on this project to continue with the setup.
On the left side under the Develop, you can see Authentication, Database, Storage, Hosting, Functions, and ML Kit. For now, you can click on the Database.
Scroll down and search for the Realtime Database, click on the Create database button. This will open the Security rules for Realtime Database.
Under the Security rules for Realtime Database you are provided with two options
- Start locked mode
- Start in test mode
Select the start in test mode and then click on the enable button. After some loading, a new page will open.
Click on the Plus icon to expand.
Enter the Name as data and value as 0 “Zero” and then click on the add button.
Under the project name esp32andfirebase you can see the default value of 0 stored in the variable data. As currently I am using only one sensor so that’s why I will go with only variable data. If you want you can add multiple variables for storing multiple sensors data. At this point we are done with the Firebase database setup. Now to link this firebase database account with the ESP32, copy the link as you can see in the picture below.
On the left side you can see the Project Overview, next to it is the settings button, click on this button.
On the left side you can see the Project Overview, next to it is the settings button, click on this button.
As you can see, under the Settings we have different menus General, Cloud Messaging, Integrations, Service accounts, Data privacy, and Users and permissions. For now you will have to click on the Service accounts.
Copy the link under the Firebase service account and paste it in notepad file. We will not use this on the ESP32 side, but may be you will need this for some other project, if you want to use the same account. On the left side you can see the Database secrets, click on this.
Copy the Database Secret and paste it in the notepad with the other two links.
For now we will only use the first one and the third one in the ESP32 programming. Don’t share this information with anyone. I am sharing this information with you guys, as I will never use this id and account again.
Anyhow, our Firebase Database settings are completed. Now you can click on the Database button under the Develop as you see on the left side.
This is ready. Now all we need is to program the ESP32 and use the links that we copied. But before we start the programming, first let me explain the circuit diagram.
ESP32 Firebase, Analog Sensor with ESP32 Circuit Diagram:
Let’s first start with the regulated 5v power supply based on the LM7805 voltage regulator. This is the same 5v regulated power supply I have been using for the Nodemcu ESP8266 Wifi module.
J1 is the female power jack and this is where we connect a 12v adaptor, battery or a solar panel. Two 470uf capacitors are connected at the input and output sides of the voltage regulator. A 330 ohm resistor is connected in series with a 2.5v led. This is a current limiting resistor. The output of the voltage regulator is connected with the 5v pin of the ESP32 module and the ground of the power supply is connected with the ground of ESP32 module.
About the ESP32 Power Supply PCB Board:
This is the ESP32 power supply board Manufactured by the PCBWay Company. I have already explained the designing and making of this board.
Finally, I connected a Potentiometer with the Analog pin A0 of the ESP32 Wifi + Bluetooth Module as per the circuit diagram already explained, and connected the ESP32 with the laptop to upload the code given below.
Before, you start the programming; first of all, make sure that you download all the necessary libraries.
Firebase ESP32 Programming:
* Firebase ESP32
#define FIREBASE_HOST "https://esp32andfirebase.firebaseio.com/"
#define FIREBASE_AUTH "gga1JXWY5rgyBHk56RSXLn3FPpajWfcq6itIM3nI"
#define WIFI_SSID "AndroidAP7DF8"
#define WIFI_PASSWORD "electroniclinic"
//Define FirebaseESP32 data object
int Vresistor = A0;
int Vrdata = 0;
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
Serial.print("Connected with IP: ");
//Set database read timeout to 1 minute (max 15 minutes)
Firebase.setReadTimeout(firebaseData, 1000 * 60);
//tiny, small, medium, large and unlimited.
//Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s).
This option allows get and delete functions (PUT and DELETE HTTP requests) works for device connected behind the
Firewall that allows only GET and POST requests.
//String path = "/data";
Vrdata = analogRead(Vresistor);
int Sdata = map(Vrdata,0,4095,0,1000);
After uploading the above program, go back to your Google Firebase account, make sure you connect the ESP32 with the internet through Wifi and you will be able to see the potentiometer value on the screen.
I was able to monitor the potentiometer in real-time. For the practical demonstration and step by step explanation watch video given below.
Watch Video Tutorial: