Raspberry Pi Home Server – Use a waterproof DS18B20 temperature sensor

Warning : This article has been automatically translated by Google Translate


Danger : This article has been automatically translated by Google Translate


Caveat : This article has been automatically translated by Google Translate


If you want to use the Raspberry to take the temperature of a liquid or outside, You can connect a waterproof probe based on a Sensor DS18B20.

Raspberry Pi Home Server - Utiliser une sonde de température étanche DS18B20

For those seeking this probe, I ordered it on eBay at e_goto for the sum of 2.49$ including shipping costs ! (Otherwise here on much faster than Amazon) Reception at home in a week with the rest of the components (surprise for next tutorials).

Here is image that you need to use it :

PicMonkey Collage

For the electronic part, need you the usual cables, the breadboard, Raspberry Pi and a resistor between 4.7KΩ and 10KΩ. If like me you have not immediately on hand a resistance with the correct value, You can combine two resistances so that their sum is the desired value. For information, I took 4.3KΩ and 1.3KΩ strength.

The Assembly was also is relatively simple. The probe I received had three sons : Red, black and white. Here's how I connected it to the Raspberry :

Raspberry Pi Home Server - Utiliser une sonde de température étanche DS18B20 Raspberry Pi Home Server - Utiliser une sonde de température étanche DS18B20

The Fritzing schema, the colours of the wires correspond to the colours of the wires from the probe :

DS18B20.fzz _-_-__ _ Fritzing Vue_de_la_platine_d_essai_

Now remains to configure the Raspberry to read the value of the temperature.

  1. Update the system
    apt-get update && apt-get upgrade -y
  2. Load the kernel modules to support the sensor. W1-gpio is the module for sensors with a single wire, W1-therm is for temperature sensors.
    modprobe w1-gpio modprobe w1-therm

    If you want to load them at every boot of the Raspberry, You must then modify the file /etc/modules adding the lines

    W1-gpio w1-therm
  3. The loading of modules created information in the directory /sys/bus/w1/devices. You must find your probe in the form of a directory whose name begins with 28-. In this directory you will have a file containing the measured temperature. It will be updated every time you go to read the contents of the file. Here is a complete example for the temperature :
    1._ssh-11Home, 21.5° C. The value is always in degrees Celsius.
  4. To retrieve the value, several techniques are possible :
    1. The command line :
      find/sys/bus/w1/devices /-name "28-*" -exec cat {}/w1_slave \; | grep "t =" | awk -F "t =" '{print $2/1000}'
    2. In Python, find again the sample of Adafruit on this page

You are now equipped to measure the temperature.

Like this article ? Bear with me on patreon!

You may also like...