# How to use a DS18B20 temperature sensor in my Pi?

I have a few DS18B20 temperature sensors. These are normally used in Arduino projects, but I don't see why not to use them with a Pi. There is a software called DigiTemp that seems to drive the device and I have compiled and installed it on the Pi. The not so clear thing is, how do I connect them? Directly to the UART?

Adafruit has released a distro called occidentalis which has 1-wire support built in.

One wire is most commonly used for DS18B20 temp sensors. The Pi does not have 'hardware' 1-wire support but it can bitbang it with some success. Connect a DS18B20 with VCC to 3V, ground to ground and Data to GPIO #4. Then connect a 4.7K resistor from Data to VCC.

This will allow you to read the temperature with commands like

cat /sys/bus/w1/devices/28-*/w1_slave


I don't know if digitemp can be made to work with those, but it should be fairly straightforward to write a munin plugin if you just want to get the temperature graphs

• Is there any way to use the 1-wire driver in Arch Linux? – Tomas Aug 14 '12 at 3:30
• @Tomas, I'm not using Arch Linux, but I expect they'll get the module in there eventually. In the meantime you'll have to patch the kernel yourself. – John La Rooy Aug 14 '12 at 3:38
• 1 wire on GPIO 4 is now supported by official kernel (update from Aug 23) so any distribution that is using it will have this supported. You have to update the kernel however (ensure it's based on kernel 3.2). Then insert wire and w1-therm modules. – Krzysztof Adamski Aug 24 '12 at 9:10

I think the secret sauce is the last line on this page

It links to DS9097U which does the UART to 1-wire conversion

I have previously use the "pic arbiter" with these devices. It works in a similar role getting the data from the 1-wire devices and making it suitable for consumption by the UART

It's also possible to connect I2C devices such as the MCP9804 directly to GPIO pins. The downside is that you need 4 wires

• Thanks. If it is possible, I'd want to use the sensor without adding yet another IC. I don't mind spending 3 GPIO pins. Is it easy to interface a 1-wire device using GPIO directly? – Tomas Jul 26 '12 at 21:52