Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe Pi has a built-in driver for the DS18B20 one-wire probe, so no library is needed: the probe shows up as a file that Python reads. The program adds a line with the time and temperature each minute, and you can open the file in a spreadsheet to draw a graph.
Tick anything you already have and the total updates.
Waterproof stainless-steel probe that reads liquid or soil temperature from −55 to +125 °C (±0.5 °C).
Follow the colours: red is power, dark grey is ground, blue is a signal.
temperature_log.py# Pi temperature logger: DS18B20 probe to a CSV file every minute
import glob, time, csv, os
from datetime import datetime
base = glob.glob("/sys/bus/w1/devices/28-*")[0] # the probe appears as a folder starting 28-
LOGFILE = os.path.expanduser("~/temperature_log.csv")
def read_c():
with open(base + "/w1_slave") as f:
lines = f.read().splitlines()
if not lines[0].endswith("YES"):
return None # bad read, try again next minute
return int(lines[1].split("t=")[1]) / 1000
if not os.path.exists(LOGFILE):
with open(LOGFILE, "w", newline="") as f:
csv.writer(f).writerow(["time", "celsius"])
while True:
t = read_c()
if t is not None:
with open(LOGFILE, "a", newline="") as f:
csv.writer(f).writerow([datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "%.2f" % t])
print("%.2f C" % t)
time.sleep(60)
The 4.7 kΩ pull-up is missing or DATA is on the wrong pin. Check the yellow wire.
6 parts: DS18B20 Waterproof Temperature Probe – 1m Cable, Resistor Assortment Kit (30 Values), Raspberry Pi Zero 2 W, Raspberry Pi Micro USB 5.1V 2.5A Power Supply, Official Raspberry Pi 32GB A2 Class Micro SD Card and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1–2 hours. The build on this page has 5 steps.
No. This page has the complete, tested code (temperature_log.py). Install this library first: gpiozero (pre-installed).
About ₹3,919 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
1-Wire bus and pull-up resistors.
Ideas that reuse this build: Pico W thermometer web page and Car fridge 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.