Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA fan that is always on is noisy, and a fan that is always off can let a Pi throttle. This program reads the chip temperature and gives a PWM fan a smooth curve: off under 50 °C, 30 per cent at 50 °C and full speed at 75 °C.
Tick anything you already have and the total updates.
Logic-level MOSFET used as a fast electronic switch, so a PWM pin can control a motor's speed.
Follow the colours: red is power, dark grey is ground, blue is a signal.
fan_control.py# Pi 5 quiet cooling fan: a PWM fan speed that follows the CPU temperature
from gpiozero import PWMOutputDevice
import subprocess, time
fan = PWMOutputDevice(18, frequency=25000) # 25 kHz is above hearing, so the fan stays quiet
LOW_C, HIGH_C = 50, 75 # fan starts at 50 C and runs flat out at 75 C
MIN_DUTY = 0.30
def cpu_temp():
out = subprocess.check_output(["vcgencmd", "measure_temp"]).decode()
return float(out.strip().replace("temp=", "").replace("'C", ""))
while True:
t = cpu_temp()
if t < LOW_C:
duty = 0
elif t >= HIGH_C:
duty = 1
else:
duty = MIN_DUTY + (1 - MIN_DUTY) * (t - LOW_C) / (HIGH_C - LOW_C)
fan.value = duty
print("%.1f C fan %d %%" % (t, duty * 100))
time.sleep(3)
Gate and drain swapped, or the 10 kΩ gate pull-down is missing.
8 parts: Power MOSFET (TO-220, IRLZ44N), Hobby DC Motor (130 size), Diodes (Pack of 10, 1N4007), Resistor Assortment Kit (30 Values), Raspberry Pi 5 · 4GB RAM, Official Raspberry Pi 4 USB-C Power Supply – 15.3W, 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 intermediate project and takes about 1–2 hours. The build on this page has 3 steps.
No. This page has the complete, tested code (fan_control.py). Install this library first: gpiozero (pre-installed).
About ₹15,889 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.
MOSFET switching and flyback diodes.
Ideas that reuse this build: Pico temperature fan curve and Temperature fan controller. 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.