Objectives
- Create a Realtime Database using Google Firebase
- Send data to the Realtime Database using a Python code on Raspberry Pi
Things
- Raspberry Pi 3B
- USB Power Adapter and cable
- DHT11 sensor
- Jumper wires
- 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