Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsCooling a router box, 3D-printer enclosure or battery cupboard works best when the fan runs slowly and quietly until it has to work hard. The Pico reads a waterproof DS18B20 and gives a 12 V fan a PWM duty that rises from 30 per cent at 30 °C to 100 per cent at 50 °C.
Use a 12 V DC fan only. Never switch mains power with a MOSFET module.
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).
Logic-level MOSFET used as a fast electronic switch, so a PWM pin can control a motor's speed.
4.7 kΩ pull-up between DATA and VCC; 10 kΩ gate pull-down
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico temperature-controlled fan: DS18B20 probe and a PWM fan curve (MicroPython)
from machine import Pin, PWM
import onewire, ds18x20, time
ow = ds18x20.DS18X20(onewire.OneWire(Pin(15)))
probes = ow.scan()
fan = PWM(Pin(14))
fan.freq(25000) # above hearing, fans stay quiet
LOW_C, HIGH_C = 30, 50 # fan starts at 30 C and runs flat out at 50 C
MIN_DUTY = 0.30 # fans stall below about 30 percent
def set_fan(temp):
if temp < LOW_C:
duty = 0
elif temp >= HIGH_C:
duty = 1
else:
duty = MIN_DUTY + (1 - MIN_DUTY) * (temp - LOW_C) / (HIGH_C - LOW_C)
fan.duty_u16(int(duty * 65535))
return duty
while True:
ow.convert_temp()
time.sleep_ms(750)
t = ow.read_temp(probes[0])
d = set_fan(t)
print("%.1f C fan %d %%" % (t, d * 100))
time.sleep(2)
The 4.7 kΩ pull-up is missing or DATA is on the wrong pin. Check the yellow wire.
Gate and drain swapped, or the 10 kΩ gate pull-down is missing.
8 parts: DS18B20 Waterproof Temperature Probe – 1m Cable, Power MOSFET (TO-220, IRLZ44N), Hobby DC Motor (130 size), Resistor Assortment Kit (30 Values), Diodes (Pack of 10, 1N4007), Raspberry Pi Pico, Solderless Breadboard (830 points) 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 intermediate project and takes about 45 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (main.py).
About ₹649 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; MOSFET switching and flyback diodes.
Use a 12 V DC fan only. Never switch mains power with a MOSFET module.
Ideas that reuse this build: Temperature fan controller and PWM fan speed knob. 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.