Pico W fridge temperature watch
Build it step by step
0 of 7 doneWire the probe
Red to 3V3(OUT), black to GND, yellow to GP15.
Add the resistor
4.7 kilo-ohms between the yellow wire and 3V3(OUT).
Edit the program
Put your Wi-Fi name and password in the placeholders.
Run it
The shell prints an address like http://192.168.1.50.
Open the address
On a phone or computer on the same network.
Put the probe in a glass of ice water
It reads close to 0 degrees.
Place it in the fridge
Feed the thin cable through the door seal, without pinching it.
How do you build a pico W fridge temperature watch?
A Pico W reads a DS18B20 probe and serves the current, lowest and highest temperature on a local page, with a warning line if it stays above 8 degrees for an hour. You need Raspberry Pi Pico W, DS18B20 waterproof probe, Resistor 4.7 kΩ and Breadboard 830 Tie Points. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 4
Parts list
- Development BoardsBuy
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DS18B20 red wire (VDD) | Pico W 3V3(OUT) pin 36 | Power at 3.3 V |
| DS18B20 black wire (GND) | Pico W GND pin 38 | Common ground |
| DS18B20 yellow wire (DATA) | Pico W GP15 pin 20 | One-wire data |
| 4.7 kilo-ohm resistor | Between DS18B20 DATA and 3V3(OUT) | Pull-up for the data line |
Code
The DS18B20 is a digital temperature probe that sends its reading over a single data wire, called one-wire, using a small protocol that MicroPython handles in its onewire and ds18x20 modules. The 4.7 kilo-ohm resistor holds the data line high between messages. The stainless-steel probe on a thin cable can be fed through the door seal of a fridge without cutting anything. The program reads the temperature every ten seconds, remembers the lowest and highest values, and starts a timer when the reading goes above 8 degrees, which is the usual upper limit for a domestic fridge. If it stays above for an hour it shows a red warning on the page. Put the probe in a small glass of water on a shelf so that it follows the temperature of the food rather than the quick changes of the air when the door opens. The page is for your home network only. A hobby monitor, not a food-safety instrument: follow official food-safety guidance for anything that matters.
import time
import network
import socket
import onewire
import ds18x20
from machine import Pin
SSID = "YOUR_WIFI_NAME" # placeholders: use your own network
PASSWORD = "YOUR_WIFI_PASSWORD"
LIMIT = 8.0 # degrees C
WARN_AFTER_MS = 3600000 # one hour above the limit
ds = ds18x20.DS18X20(onewire.OneWire(Pin(15)))
roms = ds.scan()
if not roms:
raise RuntimeError("No DS18B20 found, check the wiring and the 4.7k resistor")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
for _ in range(30):
if wlan.isconnected():
break
time.sleep(0.5)
if not wlan.isconnected():
raise RuntimeError("Wi-Fi did not connect, check the name and password")
print("Open http://" + wlan.ifconfig()[0])
server = socket.socket()
server.bind(("0.0.0.0", 80))
server.listen(1)
server.settimeout(1)
current = None
lowest = None
highest = None
above_since = None
warning = False
last_read = time.ticks_add(time.ticks_ms(), -10000)
def update():
global current, lowest, highest, above_since, warning
ds.convert_temp()
time.sleep_ms(800)
current = ds.read_temp(roms[0])
lowest = current if lowest is None else min(lowest, current)
highest = current if highest is None else max(highest, current)
if current > LIMIT:
if above_since is None:
above_since = time.ticks_ms()
elif time.ticks_diff(time.ticks_ms(), above_since) >= WARN_AFTER_MS:
warning = True
else:
above_since = None
warning = False
while True:
if time.ticks_diff(time.ticks_ms(), last_read) >= 10000:
update()
last_read = time.ticks_ms()
try:
client, addr = server.accept()
except OSError:
continue # no visitor, go round again
client.recv(1024)
note = "<p style='color:red;font-size:1.5em'>Above " + str(LIMIT) + " C for over an hour</p>" if warning else "<p>Within the limit</p>"
page = ("<!DOCTYPE html><html><head><meta charset='utf-8'>"
"<meta name='viewport' content='width=device-width, initial-scale=1'>"
"<meta http-equiv='refresh' content='30'><title>Fridge</title></head>"
"<body style='font-family:sans-serif;text-align:center;margin-top:3em'>"
"<h1>Fridge</h1><p style='font-size:3em'>%.1f °C</p>"
"<p>Lowest %.1f °C, highest %.1f °C since start</p>%s</body></html>"
% (current, lowest, highest, note))
client.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
client.send(page)
client.close()Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Probe in room air | Near room temperature |
| Probe in ice water | Close to 0 degrees |
| Probe in a warm hand | Rises towards 30 degrees |
| Fridge shelf | Between 2 and 8 degrees |
| Lowest and highest | Keep the extremes since start |
If it does not work
No DS18B20 found
Check the 4.7 kilo-ohm resistor between data and 3V3 and the three wires.
Reads 85.0 or -127
Check the power wire and the pull-up resistor.
Page does not open
Check the address from the shell and that the phone is on the same Wi-Fi.
Wi-Fi does not connect
Check the name and password, and that the network is 2.4 GHz.
Door does not seal
Use a thin, flat part of the cable and check the seal after fitting.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico W fridge temperature watch?
Raspberry Pi Pico W, DS18B20 waterproof probe, Resistor 4.7 kΩ and Breadboard 830 Tie Points.
How long does the pico W fridge temperature watch take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the pico W fridge temperature watch works?
Probe in room air: Near room temperature. Probe in ice water: Close to 0 degrees. Probe in a warm hand: Rises towards 30 degrees.
No DS18B20 found: what should I check?
Check the 4.7 kilo-ohm resistor between data and 3V3 and the three wires.
Reads 85.0 or -127: what should I check?
Check the power wire and the pull-up resistor.
Page does not open: what should I check?
Check the address from the shell and that the phone is on the same Wi-Fi.
Wi-Fi does not connect: what should I check?
Check the name and password, and that the network is 2.4 GHz.
