DS18B20 with Raspberry Pi Pico

DS18B20 with Raspberry Pi Pico


Are you looking to learn about DS18B20? Check out this informative blog that covers everything from its applications and interfacing it with Raspberry pi pico to the materials required, circuit diagram, code, and library troubleshooting. Whether you're a beginner or an experienced electronics enthusiast, this blog is sure to provide valuable insights into this powerful temperature sensor. So why wait? Dive in today and start exploring the world of DS18B20!


What is DS18B20?

The DS18B20 is a 1-wire programmable temperature sensor from Maxim integrated that requires only one data line for communication with a central microprocessor. Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area.



  1. Thermostatic Controls
  2. Industrial Systems
  3. Consumer Products
  4. Thermometers
  5. Thermally Sensitive Systems


Material Required is as follows:

1.Raspberry Pi Pico




Circuit Diagram

  1. Connect the sensor's ground to one of the ground pins on the Pico.
  2. Connect the sensor's VCC pin to the Pico's 3.3V(out) pin.
  3. Connect the Sensor's data pin to the Pico's GPIO22




 Code and Library

 Setup library

  1. For DS18B20 we need OneWire and DS18X20 libraries. Download from the link below     https://github.com/micropython/micropython/tree/master/drivers/onewire  
  2. Visit the link for the respective library.
  3. Click on the file present inside the downloaded folder and then copy the contents of the entire file .
  4. Click on the “New” button on the Thonny IDE to open a blank script and paste the copied code.
  5. Click on the save button and when prompted to choose
  6. When asked for save location, choose Raspberry Pi Pico.4
  7. Once the dialog box opens to choose the save location on the Pico, double click on the “lib” folder present already to save the file inside it. If the lib folder does not exist, create it and then save the file inside it.
  8. Enter the same name for the file as on the GitHub repo and press the Ok button. To add the downloaded library, open Thonny and navigate to the following directory in the Pico.

Thonny > File > Open > Raspberry Pi Pico > lib

  1. Copy the library code and save the file with .py extension.



         import machine, onewire, ds18x20, time

ds_pin = machine.Pin(22)

ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))

roms = ds_sensor.scan()

print('Found DS devices: ', roms)

while True:



  for rom in roms:






Copy the above code into thonny ide and run the code.

You can see output into Thonny Shell




After executing the program and error still occurs, like the one below.



Solution: Check your connections, make sure the connections are correct and not loose. Also, check-in the code if the pin number is correct.





DS18B20 is a versatile temperature sensor that can be easily interfaced with the Raspberry Pi Pico. With its simple circuit design and easy-to-use libraries, measuring temperature has never been easier. Whether you're monitoring the temperature of your homebrewed beer or controlling the temperature of your greenhouse, DS18B20 has a wide range of applications. By following the steps outlined in this guide, you can confidently interface DS18B20 with your Raspberry Pi Pico and start measuring temperature in no time. And with troubleshooting tips and tricks, you can ensure a smooth and seamless experience. So what are you waiting for? Get started on your next project with DS18B20 today!


If you appreciate our work don't forget to share this post and leave your opinion in the comment box.


Please do check out other blog posts about Popular Electronics


Make sure you check out our wide range of products and collections (we offer some exciting deals!) 

You may also like to read

Frequently Asked Questions

1. What is the difference between LM35 and DS18B20?

Both LM35 and DS18B20 temperature sensors are compatible with microcontrollers such as Arduino. The main difference between them is that LM35 is an analog temperature sensor that needs an analog-to-digital converter to interface with a microcontroller. DS18B20 is a digital temperature sensor that uses a one-wire interface for communication. Moreover, LM35 has a broader operating voltage range compared to DS18B20.

2. Is DS18B20 water resistant?

The DS temperature sensor is resistant to water and can operate in wet conditions. It is even available in a waterproof variant.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.

You may also like to read