Multiple Ds18b20 Temp Sensors Interfacing With Raspberry Pi

Photo of vinayyn

Made by vinayyn

About the project

Interfacing Nine DS18B20 Temperature sensors with Raspberry Pi and Displaying sensor data Using Python

Project info

Difficulty: Moderate

Platforms: AdafruitRaspberry PiPython

Estimated time: 4 hours

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Through Hole Resistor, 3.3 kohm Through Hole Resistor, 3.3 kohm x 1
Raspberry Pi 4 Model B Raspberry Pi 4 Model B x 1
Adafruit Waterproof DS18B20 Digital temperature sensor Adafruit Waterproof DS18B20 Digital temperature sensor x 9

Software apps and online services

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Solder Wire, Lead Free Solder Wire, Lead Free
Raspberry Pi Raspbian Raspberry Pi Raspbian

Hand tools and fabrication machines

Soldering iron (generic) Soldering iron (generic) x 1

Story

I have gone through some tutorials for interfacing the DS18B20, In those, They have given the explanation of how to interface the DS18B20 using Arduino Platforms Only. The least countable people explained how to interface with DS18B20 With the Raspberry using Python, in that they have interfaced only One single DS18B20. Here in this project, I am Explaining How To Interface Nine(9) DS18B20 Temperature sensors with Raspberry pi 4 B.

For one of the projects, I needed to interface with 9 Waterproof Temperature sensors and Relay and Proximity sensors. Using python Programming to read the temperature From the DS18B20 was not easy initially. After a lot of Workout In the final, I read multiple DS18B20 temperatures Data. in this project I have used Raspberry Pi 4 B and Raspbian os Bullseye.

9 -DS18B20 is interfaced with Raspberry pi along with the relays,Opto-isolators,IR Proximity sensors

9 -DS18B20 is interfaced with Raspberry pi along with the relays,Opto-isolators,IR Proximity sensors

9 -DS18B20 is interfaced with Raspberry pi along with the relays,Opto-isolators,IR Proximity sensors

DS18B20

Pinout of DS18B20

Pinout of DS18B20

Pinout of DS18B20

DS18B20 Sensor Specifications

  • Programmable Digital Temperature Sensor
  • Communicates using the 1-Wire method
  • Operating voltage: 3V to 5V
  • Temperature Range: -55°C to +125°C
  • Accuracy: ±0.5°C
  • Output Resolution: 9-bit to 12-bit (programmable)

A unique 64-bit address enables multiplexing

  • Conversion time: 750ms at 12-bit
  • Programmable alarm options
  • Available as To-92, SOP, and even as a waterproof sensor

Where to use DS18B20 Sensor

The DS18B20 is a 1-wire programmable Temperature sensor from maxim integrated. It is widely used to measure temperature in hard environments like in chemical solutions, mines or soil, etc. The constriction of the sensor is rugged and also can be purchased with a waterproof option making the mounting process easy. It can measure a wide range of temperatures from -55°C to +125° with a decent accuracy of ±5°C. Each sensor has a unique address and requires only one pin of the MCU to transfer data so it is a very good choice for measuring the temperature at multiple points without compromising many of your digital pins on the microcontroller.

How to use the DS18B20 Sensor

The sensor works with the method of 1-Wire communication. It requires only the data pin connected to the microcontroller with a pull-up resistor and the other two pins are used for power as shown below.

The pull-up resistor is used to keep the line in a high state when the bus is not in use. The temperature value measured by the sensor will be stored in a 2-byte register inside the sensor. This data can be read using the 1- wire method by sending in a sequence of data. There are two types of commands that are to be sent to read the values, one is a ROM command and the other is a function command.

Configuring The Raspberry Pi to communicate with DS18B20 Using One- wire Communication

In the raspberry pi, We need to enable the Interfaces after the fresh installation of Raspbian OS.

To enable the one-wire interface use :

sudo raspi-config

Scroll to the interfacing option and click on it and then enable the One-wire Interface.

To add support for OneWire, we first need to open up the boot config file, and this can be done by running the following command. to do that I have used a nano text editor, you can use Terminal for that by entering the below command

sudo nano /boot/config.txt

Next At the bottom of this file enter the following.

dtoverlay=w1-gpio

Once done save and exit by pressing CTRL + X any enter Yes(Y).. Now reboot the Pi by running the following command.

sudo reboot

Once the Raspberry Pi has booted back up, we need to run modprobe so we can load the correct modules.

sudo modprobe w1-gpio

Then

sudo modprobe w1-therm

Now change into the devices directory and use the ls command to see the folders and files in the directory.

cd /sys/bus/w1/devices 
ls

List the file and a 28-xxxxxxxxxxxx device directory (e.g. here is 28-00000674869d) will be found. This is the ROM of DS18B20. If more than one DS18B20 is connected, you will find a certain directory of more than one.

cd 28-00000674869d

Now run the following cat command.

cat w1_slave

The above command should output data but as you will notice it is not very user-friendly.

The first line should have a YES or NO at the end of it. If it is YES, then a second line with the temperature should appear. This line will look similar to something like t=12323, and you will need to do a bit of math to make this a usable temperature that we can understand easily. For example, in Celsius, you simply divide by 1000.

Response from raspberry pi

Response from raspberry pi

Response from raspberry pi

The YES in the first line indicates CRC check success (Data Valid ). The number following t= is the temperature, 28750 stands for 28.7 (C).

single DS18B20 Output

single DS18B20 Output

single DS18B20 Output

Graphical Representation of Interfacing of Multiple DS18B20 Temperature sensor with Raspberry Pi.

Connection Diagram

Connection Diagram

Connection Diagram

Schematic Diagram of DS18B20 With Raspberry PI

Schematic Diagram of DS18B20 With Raspberry PI

Schematic Diagram of DS18B20 With Raspberry PI

Schematic Diagram of DS18B20 With Raspberry PI

Schematic Diagram of DS18B20 With Raspberry PI

Schematic Diagram of DS18B20 With Raspberry PI

Output Of Nine DS18B20 Temperature Sensors

The output of the Project contains 9 DS18B20 Temperature Data in Celcius and Fahrenheit

output on Python Idle

output on Python Idle

output on Python Idle

Schematics, diagrams and documents

Schematics

Schematics

Schematics

Code

Project Code

Python 3 is used For Programming

Credits

Leave your feedback...