Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe DS18B20 uses the Pi's built-in 1-Wire support, which exposes the probe as a file. A short Python script reads that file every minute and sends a Telegram message if the temperature stays above the limit for ten minutes, then another when it recovers. The delay avoids alerts when the door is briefly open. The Telegram token and chat ID live in a private file, not in the script.
Tick anything you already have and the total updates.
microSD card for the operating system
Waterproof DS18B20 probe
Follow the colours: red is power, dark grey is ground, blue is a signal.
Official Pi 4 power supply.
fridge_alert.pyimport glob, os, time
import requests
with open(os.path.expanduser("~/.tgcfg")) as f:
TOKEN, CHAT_ID = [l.strip() for l in f.readlines()[:2]]
LIMIT_C = 8.0
LIMIT_SECONDS = 600
device = glob.glob("/sys/bus/w1/devices/28-*/w1_slave")[0]
warm_since = None
alerted = False
def read_c():
with open(device) as f:
lines = f.read().splitlines()
if not lines[0].endswith("YES"):
return None
return int(lines[1].split("t=")[1]) / 1000.0
def send(text):
try:
requests.post("https://api.telegram.org/bot%s/sendMessage" % TOKEN,
data={"chat_id": CHAT_ID, "text": text}, timeout=10)
except requests.RequestException as e:
print("Telegram failed:", e)
while True:
t = read_c()
if t is not None:
now = time.time()
if t > LIMIT_C:
warm_since = warm_since or now
if not alerted and now - warm_since > LIMIT_SECONDS:
alerted = True
send("Fridge is warm: %.1f C" % t)
else:
if alerted:
send("Fridge is back to %.1f C" % t)
warm_since, alerted = None, False
time.sleep(60)
1-Wire is not enabled or the pull-up is missing; check wiring and reboot.
The probe was not found. Check the wiring.
Press Start in your bot chat and check ~/.tgcfg.
Generally below 5 C, and under 8 C at the very most.
Yes. See the Pi DS18B20 logger project.
Yes, with the same wiring.
7 parts: Raspberry Pi 4 Model B 2GB RAM Single Board Computer, Official Raspberry Pi 4 USB-C Power Supply – 15.3W, Official Raspberry Pi 32GB A2 Class Micro SD Card, DS18B20 Waterproof Temperature Probe – 1m Cable, Stainless Steel, Resistor Assortment Kit (30 Values), Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1.5 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (fridge_alert.py).
About ₹8,547 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Enabling the Pi's 1-Wire interface; Reading a DS18B20 from /sys; Alerting after a delay.
Ideas that reuse this build: Pi DS18B20 temperature logger. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.