Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8023

Automation, sensing and robotics • Raspberry Pi 4 with DS18B20Z+ Temperature Sensor - No Data Detected, Help!

$
0
0
Hi everyone! I’m new to Raspberry Pi and recently got a DS18B20Z+ temperature sensor (SOIC-8 package, soldered onto a breakout board) to use with my Raspberry Pi 4 (4GB, latest Raspberry Pi OS). I’m trying to build a simple temperature monitoring project, but I can’t get any data from the sensor! For reference, here’s the DS18B20Z+ Datasheet.

Here’s my setup and code:
- Hardware Setup:
- DS18B20Z+ VCC to Pi Pin 1 (3.3V).
- GND to Pin 6 (GND).
- DATA to GPIO 4 (Pin 7), with a 4.7kΩ pull-up resistor between DATA and 3.3V.
- Using a breakout board with soldered DS18B20Z+, connected via DuPont wires to the Pi.

- System Config: Added

Code:

dtoverlay=w1-gpio
to

Code:

/boot/config.txt
.

- Code:

Code:

import osimport globimport timeos.system('modprobe w1-gpio')os.system('modprobe w1-therm')base_dir = '/sys/bus/w1/devices/'device_folder = glob.glob(base_dir + '28*')[0]device_file = device_folder + '/w1_slave'def read_temp_raw():    with open(device_file, 'r') as f:        return f.readlines()while True:    lines = read_temp_raw()    if lines[0].strip()[-3:] == 'YES':        temp_line = lines[1].find('t=')        if temp_line != -1:            temp_c = float(lines[1][temp_line+2:]) / 1000.0            print(f"Temperature: {temp_c:.1f}°C")    else:        print("Read failed")    time.sleep(1)
Issues I’m facing:
- I get an

Code:

IndexError: list index out of range
error, and it seems

Code:

/sys/bus/w1/devices/
is empty (no

Code:

28*
folder).
- Running

Code:

ls /sys/bus/w1/devices/
shows nothing.
- The sensor is brand new, soldering looks fine, and I confirmed 3.3V power is stable.

Questions:
1. Why isn’t my Raspberry Pi detecting the DS18B20Z+?
2. Is there anything special about the SOIC-8 DS18B20Z+ compared to the common TO-92 package?
3. Any simpler code or debugging tips?

Thanks for any help!

Statistics: Posted by nenefly — Wed Jul 23, 2025 7:16 am



Viewing all articles
Browse latest Browse all 8023

Trending Articles