Pi 4 shows 52 degrees, which is the CPU. How do I read the room temperature and send it up?
Total newbie with the Pi side of things. I want my Raspberry Pi 4 to measure the temperature in my basement workshop and send it to Hermetry every minute. I followed a tutorial that used vcgencmd measure_temp and got the sending part working with paho, the number shows on my dashboard. But it says 52 degrees and my basement is definitely not 52.
So I bought a DS18B20 (the waterproof one with the cable). Wired red to 5V, black to GND, yellow to GPIO4. Nothing shows up in /sys/bus/w1/devices/, only w1_bus_master1 or sometimes not even that. I’ve seen people mention a resistor but the kit didn’t have one.
Doesn’t the Pi have its own temperature sensor already? That’s what vcgencmd reads I thought.
It does but it’s the CPU chip temperature, that’s why 52. It’ll never be room temperature inside the case.
Did you enable 1-Wire in raspi-config? And the resistor is not optional, 4.7k between data and power.
Also don’t feed it 5V. The data line gets pulled up to whatever you power it from, and the Pi’s GPIO pins are 3.3V only.
Did the same thing in first year, the probe was fine afterwards but I was lucky. Full checklist:
Wiring: red to 3V3 (pin 1), black to GND (pin 6), yellow to GPIO4 (pin 7), and a 4.7k resistor from yellow to 3V3. Add dtoverlay=w1-gpio to /boot/firmware/config.txt (or /boot/config.txt on older images) and reboot. You should see a 28-xxxxxxxxxxxx folder.
Then the script, on the same paho code you have:
import glob, json, time
import paho.mqtt.client as mqtt
dev = glob.glob('/sys/bus/w1/devices/28-*/w1_slave')[0]
def read_c():
lines = open(dev).read().splitlines()
if not lines[0].endswith('YES'):
return None # CRC failed, skip this one
return int(lines[1].split('t=')[1]) / 1000.0
c = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="basement-pi")
c.username_pw_set("YOUR_ACCESS_TOKEN") # token as username, no password
c.tls_set()
c.connect("YOUR_BROKER_HOST", 8883, keepalive=60)
c.loop_start()
while True:
t = read_c()
if t is not None:
c.publish("v1/telemetry", json.dumps({"temp_c": round(t, 2)}), qos=1)
time.sleep(60)
Use a new key name like temp_c so the CPU readings don’t mix into the same chart. Broker host is on the device’s Connection details card.
Got a resistor from a friend, moved red to 3V3, enabled the overlay and the 28- folder appeared. Probe survived the 5V. Basement is 17.8, which sounds right. Kept the CPU one as a separate key, might be handy.
If you ever run the cable longer than a few metres and readings get flaky, drop the resistor to 2.2k.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

