Skip to content

How to setup 1 Wire DS18B20 Sensor

LazeMSS edited this page Aug 31, 2021 · 5 revisions

To use a 1-Wire DS18B20 Sensor as temperature sensor you need to connect the sensor and configure a couple of things on your raspberry pi.

Besides this article this might also be a usefull read: https://github.com/LazeMSS/OctoPrint-TopTemp/issues/28#issuecomment-817287861

Sensor model

The sensor can either be bought as a pcb mounted sensor or "clean". I recommend buying a mounted one as it makes the wiring a lot easier. A mounted one can be found for less than a dollar on aliexpress : https://www.aliexpress.com/item/1834551892.html.
You don’t need a pullup resistor as the newer raspberry pi’s can do this themselves (https://blog.robertelder.org/ds18b20-raspberry-pi-setup-pullup/)

Wiring/attaching the sensor

First turn off the raspberry pi – use the power symbol and select "Shutdown system" in OctoPrint. Now connect the 3 wires like this:

➕ : connect to the 3v power on the rpi (physical pin 1 or physical pin 17, https://pinout.xyz/pinout/3v3_power)
➖ : connect to ground on the rpi (there are several ground pins, https://pinout.xyz/pinout/ground)
data : connect to any GPIO pin – in this guide we use GPIO pin 14 (https://pinout.xyz/pinout/wiringpi).

Notice the data pin might be named different things like signal, s, data, out. And ➖ can be named ground, gnd. ➕ can be labelled as Vdd. image

For pin layout in general look here: https://pinout.xyz/

Configuration of the raspberry pi

Warning: Make sure you are not printing anything!
In order to use the sensor on your raspberry pi there are a couple of things that needs to configured to make sure data can be read to OctoPrint.

Connect to the RPI

First connect to your RPI using SSH by putty/powershell or whatever you use to connect to your rpi (see https://www.raspberrypi.org/documentation/remote-access/ssh/ - chapter 4. Set up your client)

Normal guide

If you don’t have anything else connected to the pins then you can use this easy guide - it should work and if not then try the "Normal guide"

Run: sudo raspi-config

and goto the menu: "Advanced Option > 1-Wire" and select "Yes"

then save and exit, and reboot. If asked to reboot just say yes or run sudo reboot now

Expert guide

Run: sudo nano /boot/config.txt

scroll to the bottom and insert a new line with:

dtoverlay=w1-gpio-pullup,gpiopin=14

Remember to replace 14 with whatever GPIO pin you connected the "out" pin of the sensor to. So if you have connected the "out" pin to physical pin 12 of the RPI board then replace 14 in the above example with 18. It's important that you use the GPIO pin numbers and not the physical pin numbers. https://pinout.xyz/pinout/wiringpi

Save and exit by pressing Ctrl+X and select save

Now reboot by running: sudo reboot now

Check if configuration is okay

Run: lsmod | grep w1

it should list something like this:

1_therm               28672  0
w1_gpio               16384  0
wire                  36864  2 w1_gpio,w1_therm

If not then try running:

sudo modprobe w1_gpio

sudo modprobe w1_therm

OctoPrint setup / Top Temp

Open OctoPrint userinterface and select the power symbol and select "Restart OctoPrint"

image

When restarted go into Settings (wrench symbol) and select "Top Temp" under Plugins and select "Custom" dropdown and select "Add new".
To the right of "Command" input there should be a dropdown named "Predefined".
Click on it and look for one or more items starting with "DS18B20 sensor" - click one.
Press "Test" and confirm its working.

If there is no "DS18B20 sensor" in the predefined list check the above guide again

Sources/links:

Clone this wiki locally