Connect Multiple Temperature Sensors with Raspberry Pi

Waterproof ds18b20 temperature sensor for Raspberry Pi

In our article DS18B20 Temperature Sensor with Raspberry Pi we detailed how the Raspberry Pi can be used to take temperature readings from a ds18b20 temperature sensor via the i2c protocol. Here we will expand that article to explain how multiple temperature sensors can be copnnected to the Raspberry Pi – particularly useful for example in solar water heating pump controllers and other differential temperature applications where two or more temperature sensors are required.

How to connect multiple ds18b20 temperature sensors via i2c protocol to GPIO pins on Raspberry Pi

The above schematic shows how three ds18b20 temperature sensors are connected to the GPIO pins of the Raspberry Pi. Note that although there are now multiple temperature sensors to be read, we still only have three connections to the Raspberry Pi: +3.3V and 0V connections to power the sensors, and the single data wire which returns the temperature readings from all the sensors.

Reading temperature readings from multiple sensors down one wire is possible because each ds18b20 sensor has a unique serial number coded into it at manufacture which the Raspberry Pi can be used to identify them by.

When using multiple sensors the first thing to do is get the serial number for each sensor and physically label them so that you know which is which when you come to install them in different locations around a system.

Follow the steps in the article on connecting a single sensor to get everything set up on your Raspberry Pi and use the ls -l sys/bus/w1/devices command to find the serial number for this first sensor. Then add the second sensor and identify it when you relist the connected devices noting its serial number. Repeat this process until you have connected and identified all of the sensors.

To confirm that everything is working as it should, take the temperature reading of each of the sensors in turn with the command:

cat /sys/bus/w1/devices/28-00000xxxxxxx/w1_slave

…replacing the xxxxxxx with the correct serial number for each sensor.

You are now ready to make use of your temperature sensors in your Raspberry Pi project – e.g.Raspberry Pi Temperature Datalogging.