Serverless IoTs with Firebase Realtime Database and ESP32

Part2 — ESP32 Setup

Raster
3 min readApr 3, 2019

From Part1 of Serverless IoTs with Firebase RTDB, we setup the Firebase RTDB already with project name “ESP32 Firebase Project” and project ID “esp32-firebase-project”.

This part of story we will wiring the circuits, install Firebase Arduino Library for ESP32 in Arduino IDE, connect ESP32 to Firebase RTDB and test for store and read data from database.

Hardware

All ESP32 boards are supported by the Firebase RTDB library we used.

Here is the circuit for 2 nodes (ESP32 module).

Each node consists of one push button and LED and two resistors (200 and 4.7 k ohms).

We will turn the LED1 (GPIO19) on Node 1 (U1), ON and OFF by push the button S2 (GPIO18) on Node2 (U2) and also LED2 (GPIO19) on Node 2 (U2) will be controlled by push button S1 (GPIO18) on Node1 (U1).

Installing the ESP32 Add-on on Arduino IDE (Core SDK)

If you never installed ESP32 Arduino Core SDK for Arduino IDE or don’t know about this, please check this demo.

https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/

Firebase Arduino Library installation

We will use the Firebase Arduino Library for ESP32 from here https://github.com/mobizt/Firebase-ESP32

For Arduino IDE and Platformio, this library is available from Library Manager.

This story we will show you how to program in Arduino IDE.

From Arduino IDE, open Library Manager Window by go to menu Sketch > Include Library > Manage Libraries…

Search “firebase” in Library Manager, select Firebase ESP32 Client by Mobizt, choose the latest version, 3.1.2 in this example and click Install button and close this window.

Arduino Sketch for Node1 (U1)

Arduino Sketch for Node2 (U2)

The result

When you turn on/off button or switch 1 on Node 1, the LED2 on Node 2 will be ON/OFF and on other hand, when you turn on/off button or switch 2 on Node1, the LED1 on Node1 will be ON/OFF.

Here is the data in your Firebase RTDB looks like.

--

--