DS18B20 Temperature Sensor with Raspberry Pi
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:
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…
Filed under: howto, Raspberry Pi | 6 Comments
Tags: 18B20, 1wire, DS18B20, kernel, modprobe, module, onewire, Raspberry Pi, Raspi, RPi, sensor, temperature, thermometer, w1-gpio, w1-therm