Temperature Sensor Setup - Digital-Waters/WaterMonitorDevice GitHub Wiki
DS18B20 Temperature Sensor Setup and Initialization
This page provides instructions for setting up a DS18B20 temperature sensor on a Raspberry Pi Zero 2 W to capture temperature data in your water monitoring project.
Tools Needed
- Wire cutters/strippers
- Electrical tape
Parts Needed
- DS18B20 Waterproof Temperature Sensor
- Jumper wires (female-to-female preferred)
- Raspberry Pi Zero 2 W
Instructions
1. Prepare the Sensor
Connect the DS18B20 temperature sensor to your Raspberry Pi using the following connections:
- VCC (red wire) to 3.3V on the Raspberry Pi.
- GND (black wire) to any ground pin.
- Data (yellow wire) to GPIO4 (Pin 7).
2. Secure the Wiring
Cut and strip the casing of the sensor wires to the appropriate length. Twist the wires to ensure a secure connection with the GPIO pins. Use electrical tape or heat shrink tubing to cover any exposed wires.
Software Setup
To run the temperature code on a Raspberry Pi Zero 2 W, which is designed to read temperature data from a DS18B20 sensor, you need to follow pre-requisite steps for both hardware and software setup:
Software Setup
-
Enable 1-Wire Interface:
- Open the Raspberry Pi configuration tool:
sudo raspi-config
- Navigate to
Interfacing Options
>1-Wire
and selectEnable
. - Reboot the Raspberry Pi to apply the changes:
sudo reboot
- Open the Raspberry Pi configuration tool:
-
Install Required Packages:
- Ensure you have the necessary packages installed:
sudo apt-get update sudo apt-get install python3 python3-pip
- Ensure you have the necessary packages installed:
-
Load 1-Wire Kernel Modules:
- Ensure the 1-Wire kernel modules are loaded. Add the following lines to
/boot/config.txt
:dtoverlay=w1-gpio
- You may also need to manually load the modules:
sudo modprobe w1-gpio sudo modprobe w1-therm
- Ensure the 1-Wire kernel modules are loaded. Add the following lines to
-
Check for the Sensor:
- Verify the sensor is detected. After rebooting, you should see a directory named
/sys/bus/w1/devices/
that contains directories with names starting with28-
(the DS18B20 sensor's family code). You can check it by:ls /sys/bus/w1/devices/
- Verify the sensor is detected. After rebooting, you should see a directory named