# Problem reading temp with ds18b20

**URL:** <https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981>\
**Category:** General\
**Created:** [September 9, 2026, 10:19am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981 "2026-09-09T10:19:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![george22](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@george22](https://forum.sunfounder.com/u/george22)\
**Post date:** [September 9, 2026, 10:19am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/1 "2026-09-09T10:19:59Z")

</div>

Hi

First time poster.

I am running pico 2 w and have a ds18b20 connected. I am using Thonny. This is the code i am using:

```auto
import time
import machine
import onewire, ds18x20

# the device is on GPIO12
dat = machine.Pin(22)

# create the onewire object
ds = ds18x20.DS18X20(onewire.OneWire(dat))
print('ds: ', ds)

# scan for devices on the bus
roms = ds.scan()
print('found devices:', roms)

# loop 10 times and print all temperatures
for i in range(10):
    print('temperatures:', end=' ')
    ds.convert_temp()
    time.sleep_ms(1500)
    for rom in roms:
        print(ds.read_temp(rom), end=' ')
    print()

```

And this is what i am getting:

```auto
MPY: soft reboot
ds: <DS18X20 object at 20012630>
found devices: []
temperatures: Traceback (most recent call last):
  File "<stdin>", line 19, in <module>
  File "ds18x20.py", line 1, in convert_temp
  File "onewire.py", line 1, in reset
OneWireError: 

```

I have a 4.7k connected between data and VCC.

As you can see the ‘object’ is detected, so where am i going wrong?

Any help much appreciated!

---

<div class="post-metadata">

**Author:** ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)\
**Post date:** [September 10, 2026, 8:14am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/2 "2026-09-10T08:14:35Z")

</div>

Your comment and your actual GPIO disagree

You say:

# the device is on GPIO12

dat = machine.Pin(22)

Your code is actually using GPIO22, not GPIO12.

If the DS18B20 data wire is physically connected to GPIO12, change it to:

dat = machine.Pin(12)

---

<div class="post-metadata">

**Author:** ![george22](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@george22](https://forum.sunfounder.com/u/george22)\
**Post date:** [September 10, 2026, 8:43am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/3 "2026-09-10T08:43:09Z")

</div>

So sorry! My bad. It is on pin 22, I just forgot to change the comment as I copied and pasted the code from somewhere else.

BTW: is there a way to test the probe without it being attached to anything?

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [September 10, 2026, 10:48am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/4 "2026-09-10T10:48:41Z")

</div>

To help us look into this further, could you please provide photos of your wiring and the sensor, along with your complete code and the full error message? We’ll see whether we can reproduce your issue.

---

<div class="post-metadata">

**Author:** ![george22](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@george22](https://forum.sunfounder.com/u/george22)\
**Post date:** [September 14, 2026, 2:24pm UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/5 "2026-09-14T14:24:39Z")

</div>

Hi

Sorry about the delay in replying. I tore my Achilles tendon!

Here are the images. My lcd display is working fine. Hope you can see all the wires for the temperature sensor

 ![IMG_20260914_145703](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/7/77f881b9b7b7e271e3c21abd9b8d6f0316c0c05c.jpeg)

 ![IMG_20260914_145722](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/9/9eecca654969a16b5d6580aac1c2e9cb6897d41f.jpeg)

 ![IMG_20260914_145752](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/c/c107d3001f24200441d2aa77f021df700c9a963c.jpeg)

Many thanks..

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [September 15, 2026, 8:06am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/6 "2026-09-15T08:06:21Z")

</div>

Sorry, from the photo you attached we can’t make out exactly how the DS18B20 probe is wired, so you may want to check with the DS18B20 seller whether this wiring is correct.

One more thing to note: your code has the DS18B20 connected to GP22, but from your photo, nothing is connected to GP22 on the Pico 2 W. Your DS18B20 probe runs to the 4.7K resistor board, and the 4.7K resistor board is then connected to GP0 and GP9 on the Pico 2 W — we’re not sure why it’s wired this way, but it isn’t connected to GP22 or GP12, so please double-check your wiring.

---

<div class="post-metadata">

**Author:** ![george22](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@george22](https://forum.sunfounder.com/u/george22)\
**Post date:** [September 16, 2026, 12:25pm UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/7 "2026-09-16T12:25:12Z")

</div>

Hi yes, sorry, not good pictures! Have removed the lcd wiring and the power cable to the pico and taken a new image.

 ![WIN_20260916_13_21_20_Pro](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/d/d56f76a60ec66a47c604ee0d6601c3ed918a716b.jpeg)

So, I have white to ground, red to power and yellow to gpio 22.

I think this is right.

Many thanks.

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [September 17, 2026, 9:59am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/8 "2026-09-17T09:59:56Z")

</div>

Thank you for following up, and for the photos.

I also have a Pico 2 W here, so I compared it against your photo. With the Pico 2 W in the same orientation, GP22 is on the opposite side — and the yellow wire in your photo is actually connected to GP9, not GP22 as the code specifies. That is most likely why scan() returns an empty list and throws OneWireError: the pin in the code does not match the actual wiring.

Please fix it in either of these two ways:

Move the yellow data wire from GP9 to GP22, keeping the code as machine.Pin(22); or  
Leave the wiring as it is and change the code to machine.Pin(9).  
Thanks again for your patience and cooperation!

 ![ScreenShot_2026-09-17_172427_511](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/5/55f711812edd6877974250ae1a22260bd83c6c34.png)

---

<div class="post-metadata">

**Author:** ![george22](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@george22](https://forum.sunfounder.com/u/george22)\
**Post date:** [September 17, 2026, 7:24pm UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/9 "2026-09-17T19:24:08Z")

</div>

AHHHHH !!!

There is the problem! The gpio pins on my pico have been soldered on the other side!

I was following the gpio pins from the picture below, expecting the pins to point up and not down.

I have a number of rpi A, B+ and Zero 2 w and have never had this problem.

Thank you for all your help and maybe this will help someone else!!

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/0/094494d40a86f0b57f43f5e42b61ffcc0a830035.png)

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [September 18, 2026, 9:22am UTC](https://forum.sunfounder.com/t/problem-reading-temp-with-ds18b20/4981/10 "2026-09-18T09:22:17Z")

</div>

Hi George,

Thank you very much for coming back and sharing the final cause — we’re really glad the problem is solved!

Your diagnosis is spot on: if the GPIO header on the Pico 2 W is soldered on the other side of the board (pins pointing down), then counting the pins from the usual picture (pins pointing up) gives the wrong numbering. The pin you actually wired to then doesn’t match machine.Pin(22) in your code, so scan() returns an empty list and throws OneWireError. That is exactly what happened in your case, and it has nothing to do with the DS18B20 probe itself.

You mentioned that this might help others — we couldn’t agree more. If you’re willing, feel free to add your troubleshooting process and a photo of the header orientation to the original thread; we’re sure it will help others who run into a similar situation.

Thanks again for your patience and cooperation, and we wish you a speedy recovery. If you have any further questions, just let us know.
