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.

You may also like...

  • trim

    Hello,
    do you perform tests regarding the lengths of cable as well as number of sensor .
    Because in me it appears that beyond 1 m with 2 probes (the first to 50cm and the other at 1 m).This no longer works and the FT detects more than a probe.

    I am therefore switch to 5v (as mounting arduino) and it works war better.
    I well love confront our tests because I can't find any site that deals with lengths of cable as possible and the number max that we can put on a PI raspberry.

    Thanks in advance

    • Hello,
      No test in this sense. I have a probe and I use the default cable with an extension of 20cm for a total of 140cm. I get well temperature.

  • Arnaud

    Hello,
    Thank you for this tutorial because we see many article that uses the RasberryPi but a couple “USB DS9490R 1-Wire controller”.
    If it can happen for another module to the temperature reading, It is rather interesting!!!
    You have the options we itemize your wiring diagram?
    Can we put in parallel several probe?

    • Oops I forgot to update the schema. This is corrected in the article with an image more

    • twixer

      Yes you can put several probes in parallel.
      There will be several directories in/sys/bus/w1/devices / with beginning by names 28-*, one for each sensor.

  • Hello,
    Here is the same type of mounting with a comparison with an analogue sensor and analog-to-digital converter on Raspberry Pi : http://www.magdiblog.fr/gpio/gpio-capteurs-de-temperature/

  • NBO

    Hello,
    For my part, I set up a network 1wire with a large number of devices (~ 20 or 30 to start) in my house. After doing a little tour of what I found on the web, and my own experiences :
    * I tried to connect several 18B 20 sensors in parallel on the Pi GPIO. I go up to 10 probes to the maximum. Beyond, some probes disappear alternately. This is more than enough robust, in 3v3 and 5v.
    * I made it work with a little less than 3 m cable : It's OK. I tried with a spool of 100 m RJ45 Cat5e cable : It no longer works.
    * From what I understand from my readings, especially on manufacturer's website (highly technical, a lot of precautions to be taken, Unfortunately no proposal of Assembly drawing “that works”), I imagine that the Pi GPIO “fact” the 1wire, but not worth a true bus master 1Wire.
    * One can apparently put dozens of components for a bus master, with a few tens of meters of cable total, provided you keep a topology with a single bus and “stubs” too long steps (<3m) on this bus. No Star. No parasitic mode.
    * Use a network cable-pair UTP Cat5e or better for the bus, cable according to a scheme proposed on http://owfs.org/index.php?page=wiring-standards
    * To achieve a more comprehensive network, Star, and let me put a large number of devices without much care network, I bought the card http://www.sheepwalkelectronics.co.uk/RPI3.shtml : 8 bus master on an i2c controller. Immediately compatible with Pi, with OWFS. All my probes of different networks appear together and I access each interchangeably. Bus masters are much better than the direct connection to the Pi. I did the test with 21 components on the same bus : It works. I hope to do more soon.
    * Question line impedance, CEM, etc, I am planning to take the following precautions, for a bus of a few tens of meters, coming out of the House, in contact with the ground (Lightning) : CAPAS decoupling on the sons of alim, close to the remote probes (typically 100nF + 10 to 100µF). "A little more zener diode" 5V in contrast between 5v and the mass to protect any differential surge. One near the controller, and out of the House, for example. Two diodes in contrast between the mass and the signal, and between the signal and the 5v, close to the controller, to protect in case of overvoltage on a son. Resistors in series on the entered "Signal" each probe, equal to the impedance of the line impedance (Typ. 100ohms), to mitigate the echo on the line.
    I am going to wire everything, I hope having taken all precautions for best results.

  • twixer

    hello,
    I followed the Fritzing diagram and my sensor was abnormally.
    Following the directions on http://www.magdiblog.fr/gpio/gpio-capteurs-de-temperature/ It was going better (Here is a picture : http://www.magdiblog.fr/wp-content/uploads/2013/12/raspberry_pi_ds18b20.png).
    Apart from these connections, everything else works fine.
    In any case, Thanks for the article !

    • Hello,
      Good new if it works. Je t’avoue ne pas voir la différence entre les deux schémas mais si ca fonctionne c’est l’essentiel 😉

    • Rinty35

      If the probe heater it is a problem of connection. Inversion between the ground and 3, 3v (or 5v)

  • Rinty35

    Attention if the colors are good on the above proposed Assembly diagram above, It does not correspond to the legs of the DS18B20 sensor.
    Watch the doc technique, http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
    When you look at the sensor at the bottom we have from left to right :
    The mass – The data (to connect to the GPIO input) – Food (on 3, 3v)

    What I don't know is if when it feeds it in 5v connected GPIO output voltage is 5v.
    I guess that Yes in this case it is necessary to put two additional heaters

  • Tom

    Hello,

    very good article. I just got my probe and I intend to complete my installation to drive my boiler. On the other hand, My sensor has three thread with the following colour : Red, White and transparent. I infer that white is the thread of data and the Red of the mass. I have all good?

    Thank you

    • Weird like colors but if the probe heats up after having been connected, is that the connection is not good. I had the case the first time and it still works
      Is that for data that is white or transparent, je ne sais pas 🙁

  • Tom

    Solved : Transparent = ground wire and white = data.
    I have two resistors in series 4.6 k and 200 4.8 k. It works nikel.
    The following small script gives me the temperature with a probe :


    t=`cat /sys/bus/w1/devices/28*/w1_slave|grep "t="|awk -F"t=" '{print $2/1000}'`
    if [ $? -ne 0 ]
    then
    exit 1
    else
    if [ "$1" = "-c" ]
    then
    echo "$t°C"
    else
    echo $t
    fi
    exit 0
    fi

    Thank you and enjoy you with the Zhao

  • Tom

    My past questions :

    -the probe needs 3, 3V. Map relay that I use to control the boiler needs 5v. Can I use the same connector GROUND without risk to toast the probe or the rasp?
    -why the GPIO command takes as a parameter 0 to write on the GPIO 4 and not 4. for example if I want to write 1 on the gpio 4 need the command : GPIO write 0 1????
    Thank you

  • piRstone

    Hello,

    everything works well for me finally almost.
    I'd like to display the temperature value in a web page in php.
    So I decided to make the find command in an exec() and retrieve the value of the return (which is an array() ) except that this table is empty (a print-r() Returns me “Array()”)
    How to retrieve the temperature in a variable at the time ?
    Thanks in advance.

  • LordK1

    Hello,

    If I read well the technical instructions for the sensor, the present scheme is false.
    Seen from the top, and the curved part of the DS18B20 down, from left to right, We are DRG/DATA/VDC

    See the following address : http://www.datasheetdir.com/DS18B20+Temperature-Sensors

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop