Login

Send data to a Realtime Database using Google Firebase and Raspberry Pi

Objectives

  • Create a Realtime Database using Google Firebase
  • Send data to the Realtime Database using a Python code on Raspberry Pi

Things

  1. Raspberry Pi 3B
  2. USB Power Adapter and cable
  3. DHT11 sensor
  4. Jumper wires
  5. Google Account

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 Raspberry Pi to send data to a Realtime Database.

Firebase Realtime Database

Raspberry Pi Pinout

Interfacing DHT11 sensor with Raspberry Pi

 

Interfacing DHT11 sensor with Raspberry Pi

 

Installing required libraries on Raspberry Pi

Run the following command in a terminal to install the Python package for Google Firebase

sudo pip install requests python-firebase

Final code

cd ~/Documents/Codebase
nano firebase_dht.py

Edit the following line (line 9 in the below code) and add your Firebase URL

https://YOUR_FIREBASE_URL.firebaseio.com/

To run the code

python firebase_dht.py

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.

If DHT11 sensor library has not been installed on your Raspberry Pi, run the following commands

git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get install build-essential python-dev python-openssl
sudo python setup.py install

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