Quantcast
Channel: Chris Swan's Weblog » thermometer
Viewing all articles
Browse latest Browse all 3

DS18B20 Temperature Sensor with Raspberry Pi

0
0

After bringing my Nanode based temperature sensor back to life I thought about some other projects that I might do. One was simply to add an external sensor to the Nanode project, and another was to turn my slow cooker into a sous vide water bath (along the lines of ‘Sous Vader‘). Those projects would need a temperature sensor that could withstand weather/immersion, and the waterproof DS18B20 fits the bill (such as this on eBay).

The two sensors that I ordered arrived today, and since I’ve got a Raspberry Pi on my desk I thought I’d try them out with that first. I quick hunt for DS18B20, onewire and 1wire in the forums suggested that things would be very easy (e.g. too trivial for anybody to explain) or very hard (e.g. requiring ninja kernel hacking skills). As I didn’t come across any code samples I was starting to fear the latter, but luckily it turned out to be the former. A bit more digging around led me to this tutorial by Matthew Kirk on the University of Cambridge site. Things have clearly moved on since he wrote it though, and I didn’t need to patch my (reasonably up to date) Raspbian to get w1-gpio and w1-therm support. It was simply a question of connecting the three wires black-GND red-3.3v and white-GPIO4 and I was all set (I didn’t use a pull up resistor).

With the appropriate modules installed (sudo modprobe w1-gpio && sudo modprobe w1-therm) the temperature can be read with:

cat /sys/bus/w1/devices/serial_number/w1_slave

The serial_number is something like 28-000003ea00b4 and the one on my desk is presently reading something like this:

48 01 4b 46 7f ff 08 10 ad : crc=ad YES
48 01 4b 46 7f ff 08 10 ad t=20500

So anything that can read from a file can read the temperature, and the crucial part in all of that is t=20500, which is 20.5 Celcius.

I’m off to solder some header pins onto the wires so that they don’t fall out of my breadboard so easily…



Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images