If you’ve ever worked with the DHT11 or DHT22 for temperature readings, you already know their biggest weakness — they’re slow, occasionally flaky, and not something you’d want to dunk in a fish tank or bury in soil. That’s exactly where the DS18B20 earns its reputation. It’s a fully digital, waterproof-capable temperature sensor that talks over a single data wire, gives you accurate readings down to 0.5°C, and can even run multiple sensors off the same pin at once.
In this project, we’ll interface the DS18B20 temperature sensor with a Raspberry Pi Pico using MicroPython, print the live readings to the serial monitor (REPL), and simultaneously show them on a 0.96″ SSD1306 OLED display. This is a great upgrade if you’re building a fridge monitor, a 3D printer enclosure logger, a brewing rig, or an outdoor weather station where a waterproof probe actually matters.
By the end of this tutorial, you’ll have a fully working setup that reads temperature over the OneWire protocol and displays it in two places at once — perfect for both debugging on your laptop and standalone field deployment.
Table of Contents
Requirements
Hardware Requirements:
| Product Name | Quantity | ||
|---|---|---|---|
| Raspberry Pi Pico | 1 | https://amzn.to/36gKUlu | https://amzn.to/3sTnD1Z |
| DS18B20 Temperature Sensor | 1 | https://link.amazon/B01awLhBc | https://amzn.to/3pUglJl |
| 4.7kΩ resistor (pull-up for the data line) | 1 | https://amzn.to/3hBlqlq | https://link.amazon/B0dMqP8eL |
| 0.96" SSD1306 OLED display (128×64) | 1 | https://amzn.to/34f0GNi | https://amzn.to/35HZK4E |
| USB-A to Micro-USB cable | 1 | Data-capable (not charge-only) | |
| Breadboard | 1 | https://amzn.to/3CcBR16 | https://amzn.to/3tH3k6X |
| Few Connecting Wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
Software Requirements:
- Thonny IDE (or any MicroPython-compatible IDE)
- MicroPython firmware flashed on the Pico
ssd1306.pydriver file
DS18B20 Sensor Details
What is it? The DS18B20 is a digital temperature sensor from Maxim Integrated that communicates using the 1-Wire (OneWire) protocol — meaning it needs just a single data line (plus power and ground) to talk to your microcontroller. Each sensor ships with a unique 64-bit serial number burned into it, which is what makes it possible to run several DS18B20 sensors on the exact same data pin without any conflicts.

How does it work? Unlike the DHT-series sensors that output a rough analog-style pulse train, the DS18B20 does the analog-to-digital conversion onboard and sends back a clean digital value. When your microcontroller sends a “convert temperature” command over the OneWire bus, the sensor takes the reading internally and holds it in a scratchpad register until it’s read out. This is what makes it noticeably more accurate and stable than the DHT11, especially at temperature extremes.
The sensor also supports a parasite power mode, where it can draw power directly from the data line instead of a separate VCC connection — handy for waterproof probes with only two exposed wires. In this tutorial, we’ll use the simpler and more reliable normal power mode with all three wires connected.
Technical Specifications:
- Operating voltage: 3.0V to 5.5V
- Temperature range: -55°C to +125°C
- Accuracy: ±0.5°C (from -10°C to +85°C)
- Resolution: 9 to 12-bit, user-configurable
- Communication: 1-Wire digital protocol
- Conversion time: ~750ms at 12-bit resolution
- Multiple sensors supported on a single data pin
SSD1306 OLED Display Overview
The SSD1306 is a monochrome OLED driver we’ve covered in detail in our SSD1306 OLED with Raspberry Pi Pico article. It communicates over I2C, needs just four wires, and is ideal for showing sensor data without needing a laptop connected. We’re reusing that same wiring and driver setup here, just feeding it temperature data instead.
DS18B20 with Pi Pico Circuit Diagram
Connect all the required components using the below circuit diagram:

DS18B20 to Raspberry Pi Pico:
| DS18B20 Pin | Raspberry Pi Pico Pin |
|---|---|
| VDD (Red) | 3V3 (Pin 36) |
| GND (Black) | GND (Pin 38) |
| DATA (Yellow) | GP15 (Pin 20) |
Place the 4.7kΩ pull-up resistor between the DATA line and 3V3. This resistor is not optional — without it, the OneWire bus will float and you’ll get unreliable or no readings at all.
SSD1306 OLED to Raspberry Pi Pico:
| SSD1306 Pin | Raspberry Pi Pico Pin |
|---|---|
| VCC | 3V3 (Pin 36) |
| GND | GND (Pin 38) |
| SCL | GP1 (Pin 2) |
| SDA | GP0 (Pin 1) |
Double-check your OLED module’s silkscreen — some clone boards swap SDA/SCL labeling, so it’s worth confirming with a multimeter or datasheet before powering it up.
Required MicroPython Libraries
MicroPython already ships with the onewire and ds18x20 modules built in, so there’s nothing extra to install for the sensor itself. You only need to copy one driver file onto the Pico for the display:
ssd1306.py— Download from the official MicroPython-SSD1306 repository and save it to the Pico’s root directory using Thonny.
Code to Upload
Open Thonny, connect to your Pico, and upload the following script as main.py. Make sure ssd1306.py is already saved on the board before you run this.
from machine import Pin, I2C
import onewire, ds18x20
import time
import ssd1306
# ----- OneWire / DS18B20 setup -----
ow_pin = Pin(11)
ow = onewire.OneWire(ow_pin)
ds_sensor = ds18x20.DS18X20(ow)
roms = ds_sensor.scan()
print("Found DS18B20 sensors:", roms)
if len(roms) == 0:
print("No DS18B20 sensor detected. Check wiring and pull-up resistor.")
# ----- I2C / SSD1306 setup -----
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
def show_on_oled(temp_c, temp_f):
oled.fill(0)
oled.text("DS18B20 Sensor", 0, 0)
oled.text("---------------", 0, 10)
oled.text("Temp: {:.2f} C".format(temp_c), 0, 25)
oled.text("Temp: {:.2f} F".format(temp_f), 0, 40)
oled.text("CircuitSchools", 0, 55)
oled.show()
while True:
if roms:
ds_sensor.convert_temp()
time.sleep_ms(750) # DS18B20 needs ~750ms to complete conversion
for rom in roms:
temp_c = ds_sensor.read_temp(rom)
temp_f = temp_c * 9 / 5 + 32
print("Temperature: {:.2f} C | {:.2f} F".format(temp_c, temp_f))
show_on_oled(temp_c, temp_f)
else:
print("Waiting for sensor...")
time.sleep(2)
time.sleep(1)
A few things worth noting about this code:
ds_sensor.scan()returns a list of ROM addresses for every DS18B20 detected on the bus — this is what lets you daisy-chain multiple sensors later if you want to.convert_temp()triggers the onboard analog-to-digital conversion, and we wait 750ms because that’s the datasheet-specified time needed at 12-bit resolution before the reading is ready to pull.- The same reading gets printed to the serial console via
print()and pushed to the OLED viashow_on_oled(), so both outputs stay in sync every cycle.
Working of DS18B20 with Raspberry Pi Pico
Once you run the script, open Thonny’s Shell (or any serial terminal at 115200 baud) to watch the live serial output. You should see something like this scrolling by every couple of seconds:

At the same time, the SSD1306 OLED will refresh with the current Celsius and Fahrenheit readings, labeled and updated on the same cycle as the serial output. Try holding the sensor between your fingers or breathing on it — you’ll see both the serial monitor and the OLED update within a couple of seconds, confirming the DS18B20’s fast, accurate response compared to the DHT11.

If you connect a waterproof probe version instead of the bare TO-92 sensor, you can drop it straight into a fish tank, a compost bin, or an outdoor enclosure, and the Pico will keep logging temperature over serial (great for datalogging over USB) while the OLED gives you an instant on-site readout.
Troubleshooting
Running into blank readings, a frozen OLED, or garbage values? Common culprits include a missing pull-up resistor, a loose data wire, or a wrong I2C address on the OLED.
FAQs
Can I connect multiple DS18B20 sensors to one Pico pin? Yes. Since each sensor has a unique ROM address, you can wire several DS18B20 units to the same GPIO pin (with a shared pull-up resistor) and loop through ds_sensor.scan() to read each one individually.
Why does my code show “No DS18B20 sensor detected”? This almost always means the 4.7kΩ pull-up resistor is missing between DATA and 3V3, or the data wire isn’t seated properly in the breadboard. Reseat the wiring and re-run the scan.
Is the DS18B20 better than the DHT11 for this kind of project? For temperature-only applications, yes — it’s more accurate, faster to respond, and available in a waterproof probe format. If you also need humidity, you’d still want a DHT11/DHT22 or a combined sensor like the BME280.
Can this same code work on an ESP32 instead of a Pico? Yes, with minor changes. The onewire and ds18x20 modules are part of standard MicroPython, so you’d just update the GPIO pin numbers to match your ESP32 board’s wiring.
Conclusion
The DS18B20 is one of those sensors that quietly outperforms more “popular” options once you actually need reliable, waterproof, multi-point temperature sensing. Pairing it with a Raspberry Pi Pico and an SSD1306 OLED gives you a compact, standalone temperature logger that’s equally useful for quick USB-tethered debugging and permanent field deployment. From here, you could extend this project with an SD card for offline logging, a buzzer for high-temperature alerts, or Wi-Fi push notifications if you move over to a Pico W.
