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 to .
- Code:Issues I’m facing:
- I get an error, and it seems is empty (no folder).
- Running 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!
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-gpioCode:
/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)- I get an
Code:
IndexError: list index out of rangeCode:
/sys/bus/w1/devices/Code:
28*- Running
Code:
ls /sys/bus/w1/devices/- 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