Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at

hpr2353 :: RoboThermometer

A surprisingly short geeky episode about connecting a temperature sensor to a Raspberry Pi

<< First, < Previous, , Latest >>

Thumbnail of Epicanis
Hosted by Epicanis on 2017-08-09 is flagged as Clean and is released under a CC-BY-SA license.
Raspberry Pi, Shell, Zabbix, Monitoring, Temperature, DS18B20, Sensors, Linux. 3.
The show is available on the Internet Archive at:

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:12:36


Sorry this is such a short episode. I don't know what came over me, I was just listening to Mr.X talking about doing something with Python in Hacker Public Radio episode 2340, and for some reason I just felt a compulsion to record some kind of episode myself. It was so strange. I'm way behind on my Hacker Public Radio contribution duties anyway, so here's a quick, geeky tutorial about a thing I did with a Raspberry Pi just to try it.

The temperature sensor I'm using is one of the many "1-wire" protocol devices supported by established kernel drivers, hence the reference to loading the modules for it:

sudo modprobe w1-gpio
sudo modprobe w1-therm

The part about adding "dtoverlay=w1-gpio" to /boot/config.txt and then rebooting is also necessary, otherwise the modules load but no devices show up in /sys/bus/w1/devices/ .

Part of the fun was coming up with a way of extracting the temperature reading in useful form without having to write a bunch of unnecessary python code. Not that there's anything wrong with python, but I get the impression that some people think everything "RaspberryPi" has to be written in python. An example of this that amused me is the piFM project, which cleverly abuses the first-generation Raspberry Pi spread-spectrum circuitry to turn it into a surprisingly powerful FM radio transmitter. This project had two ways to run it - the actual compiled C program that takes input audio and makes FM radio come out...and a python "module" that was literally just a system call that...ran the C program that takes the audio and makes FM radio come out.

Examples of reading the temperature data that I ran into tended to also be short python scripts, so I took it as a challenge to do without, resulting in the fun-to-recite command in the episode, which on my system is:

echo "scale=3; (`grep -o "[[:digit:]]\{5\}" /sys/bus/w1/devices/28-05167380f6ff/w1_slave`/(5000/9))+32" | bc

As an example of what you get with a correctly connected and configured DS18B20 module on a Raspberry Pi, in my case the device shows up as:


Your device's number after the "28-" will be different, so just replace my example with your own device's number.

If you read the "w1_slave" virtual-file in that directory, you get something that looks similar to this:

67 01 4b 46 7f ff 0c 10 c4 : crc=c4 YES
67 01 4b 46 7f ff 0c 10 c4 t=22437

To be completely proper, one probably should validate that output to make sure the CRC matches so you know for sure that the read of the temperature data was correct, but I've had Zabbix checking my living-room temperature once every minute for a couple of days now and seen no odd readings or failures, so I'm not going to bother making anything more complicated than my hypnotic one-liner, unless I ever try to use the same kind of setup to monitor something more important, like a tank of expensive fish or a bioreactor full of beer.

If you want some more detailed connection instructions for the DS18B20 temperature sensor and the Raspberry Pi, here is one of the many online pages with the whole process:


Subscribe to the comments RSS feed.

Comment #1 posted on 2017-08-11 03:02:01 by b--yeezi

On my to-do list

Thanks for this entertaining and informative episode. I've been meaning to test out temperature monitoring on a Raspberry pi for some time. Do you know if the process you described will work for one-wire temperature probes like the one shown here

Comment #2 posted on 2017-08-11 12:03:49 by ClaudioM

Another Great Episode

Even with all those dry "robotic" commands and regex, you always find a way to make such things interesting and entertaining to listen to. Thanks again for another great episode and welcome back!

Comment #3 posted on 2017-08-12 16:54:39 by Ivan "Epicanis" Privaci (pseud.)

Glad to be back!

@b--yeezi That looks like exactly the sort of submersible temperature sensor that should work! It's exactly the same core component as far as the RaspberryPi is concerned, they've just stuck it to a heat-conducting piece of stainless steel and sealed it up so that it can be submerged into whatever liquid (or potentially-wet weather, etc) you might want to monitor. From what I read, you'll need a 4.7kOhm resistor between two of those leads (the "module" I'm using[1] has that built onto the board already) but otherwise you should be able to plug it right in and use it exactly as described.

@ClaudioM thanks for the encouraging feedback! I swear I really am trying to produce _much_ more often than I have been. Probably more short episodes coming Real Soon Now!...


Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?