Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Measuring temperature is a popular microcontroller application. There are many applications in which motors, pumps, heaters and fans are switched depending on the temperature. In this tutorial we will learn to build Custom Android app with DS18B20 sensor and Raspberry Pi PICO W. It will also send alert notification with custom temperature threshold settings.

The DS18B20 is a digital temperature sensor with a comparatively large measuring range and fairly good accuracy. It also comes in different constructions. For example, to measure the temperature outdoors or in liquids. In comparison, the also popular DHT11 and DHT22 are the purest estimation clubs and only suitable for measuring indoors. In the following setup we will measure and display the temperature with a DS18B20 on a webserver. The DS18B20 is controlled via one-wire. Both One-Wire and DS18B20 are supported in MicroPython.

Materials Required

To connect the DS18B20 sensor to the Raspberry Pi PICO W, you will need:

  1. A 4.7K resistor
  2. Three female to female jumper wires
  3. A breadboard
  4. The DS18B20 temperature sensor

Working

The DS18B20 sensor is connected to the Raspberry Pi Pico W microcontroller, which collects temperature data. Using Firebase as the backend service, the Pico sends the temperature data to the cloud, where it is stored securely. The Android app retrieves the temperature data from Firebase and displays it in real-time on the user’s device. This integration provides users with the convenience of monitoring temperature remotely and accessing historical data, enabling them to stay informed and take necessary actions based on the temperature readings.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Connection Diagram

You can connect the temperature sensor with raspberry pi pico W as shown below.

Note on the pull-up resistor: It is recommended to connect a pull-up resistor with a value of 4.7 kΩ (4K7) between Data (3) and VCC (2). If you don’t have any resistance, you can also leave it out. But then make sure that the cable length is as short as possible. If you don’t have a 4.7K ohm resistor, then anything else between 1K ohms and 10K ohms will work. For trouble-free operation, the resistance should be present.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Raspberry Pi Pico W

DS18B20 Temperature Sensor

Pin 39

Vcc (Red Wire)

Pin 31 (GPIO 26)

Data (Yellow Wire)

Pin 38

Gnd (Black Wire)

  1. Connect one end of the 4.7K resistor to the 3V3 pin (PIN39)on the Raspberry Pi PICO W.
  2. Connect the other end of the resistor to the data pin (center pin) on the DS18B20.
  3. Connect the ground pin (GND) on the DS18B20 to a GND pin (PIN38) on the Raspberry Pi PICO W.
  4. Connect the data pin on the DS18B20 to PIN31 on the Raspberry Pi PICO W.

Configuring Firebase

First login to Firebase and create an account if you are logging in for first time. Provide a name for your project.

As per your requirement you can enable google analytics or disable it and click on Continue. This is optional and doesn’t make any impact if you don’t enable it.

Now your project will be created in sometime. Then click on Continue.

Now click on Realtime Database to proceed.

IoT Door Security with custom Android App using Firebase

Click on Create Database to build your Realtime Database.

Let the default location be there for your Realtime DB and click on Next.

By default the locked mode will be selected. click on enable.

After enabling, click on Rules and edit rules. Make the read and write as true. Also click on Publish to save changes.

Click on Data to get the the URL of your Realtime database. Copy this and keep it in a notepad. We need this in our micro python code.

Go to Project settings and collect the required information.

Click on Service accounts and click on Database secrets to get the secret key to connect with your database. Copy and paste it in notepad as we need it while creating the android app.

IoT Door Security with custom Android App using Firebase

Code

We are using micro python to run this entire project. You can download the code from below link and unzip it. You have to upload the code to Raspberry Pi Pico W and power it. The zip file contains 2 files and ufirebase.py is available for download from here. The credit goes to the creator of this python file. To upload the code you need Thonny IDE or you can use any other python IDE which supports Raspberry Pi PICO W.

Changes in the code

Enter the WiFi username and password in your python code

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Update the URL of your firebase real-time database here in micro python code before uploading it in Raspberry Pi Pico W.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Building Android App

For building this project easily we have provided the aia file below. You have to download and import it download and import it in MIT App Inventor.

Before you create an apk file you have to make changes in the firebase DB as shown below. Paste the DB secret key in Firebase Token box and real time database url in FirebaseURL which you have copied during the creation of firebase project.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Building and Testing

Finally after setting up the project and powering it on its time to test the temperature monitoring system. Once you power it on the sensor collects the temperature data and sends it to firebase on real-time using raspberry pi pico w. From firebase db the Android app collects the data and shows it.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Also the App has got temperature threshold configuration where it will send push notification when the temperature is below the minimum temperature and maximum temperature set. You can change these threshold settings and place custom values and save it.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

When the temperature is more than threshold temperature. You will receive a push notification.

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

If the temperature is below the minimum temperature then it will send a push notification

Custom Android app with DS18B20 sensor and Raspberry Pi PICO W

Summary

The Android app with DS18B20 temperature sensor, Firebase, and Raspberry Pi Pico W provides a comprehensive solution for monitoring temperature data remotely. By connecting the DS18B20 sensor to the Raspberry Pi Pico W, temperature readings are gathered and sent to Firebase, a cloud-based database. The Android app, developed using MIT App Inventor, retrieves the temperature data from Firebase and presents it to the user in real-time. This setup allows users to conveniently access temperature information from anywhere using their Android devices.

The integration of Firebase ensures data reliability and persistence, while the Raspberry Pi Pico W acts as the bridge between the sensor and the cloud. This combination of hardware, cloud, and mobile app technologies offers a seamless and efficient solution for temperature monitoring and tracking along with sending notification.

Suggested Projects:

2 thoughts on “Custom Android app with DS18B20 sensor and Raspberry Pi PICO W”

Leave a Comment