Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA simple watering project often floods the pot because soil takes time to feel the water. This one pumps for four seconds, rests for two minutes, checks the soil again and stops after five bursts in a row so a dry tank cannot run the pump forever.
Keep to low-voltage loads unless a qualified electrician wires the mains side in an earthed, closed enclosure.
Tick anything you already have and the total updates.
Capacitive probe that measures soil moisture without exposed metal, so it does not corrode like resistive probes.
An electrically isolated switch that lets a 3.3/5 V pin turn a 12 V (or mains) load on and off.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico self-watering planter: gives short pump bursts and then rests so the water can soak in (MicroPython)
from machine import Pin, ADC
import time
soil = ADC(26)
pump = Pin(15, Pin.OUT)
PUMP_ON = 1 # set to 0 for a relay board that switches on with a LOW signal
pump.value(1 - PUMP_ON)
DRY_ABOVE = 40000 # the reading rises as the soil dries (capacitive sensors read lower when wet)
BURST_S = 4 # pump for 4 seconds
REST_S = 120 # then wait 2 minutes for the water to spread before checking again
MAX_BURSTS = 5 # safety: stop after 5 bursts in a row and wait for a person
bursts = 0
while True:
value = soil.read_u16()
print("soil", value)
if value > DRY_ABOVE:
if bursts >= MAX_BURSTS:
print("Still dry after", MAX_BURSTS, "bursts: check the tank and the tube")
time.sleep(600)
bursts = 0
continue
pump.value(PUMP_ON); time.sleep(BURST_S); pump.value(1 - PUMP_ON)
bursts += 1
time.sleep(REST_S)
else:
bursts = 0
time.sleep(30)
Calibrate: note the raw reading in dry air and in water, and put them in SOIL_DRY and SOIL_WET.
Load must be on COM and NO, with its own supply in series.
Your module may be active-HIGH. Set RELAY_ACTIVE_LOW to false.
Some 5 V relay boards do not fully switch off with 3.3 V logic. Remove the JD-VCC jumper, feed JD-VCC from 5 V and VCC from 3.3 V, or use a relay board made for 3.3 V input.
The relay is rated for mains, but mains wiring is dangerous. Keep this build on low-voltage loads (12 V pumps, fans, LED strips), or have a qualified electrician fit the relay inside an earthed, closed enclosure.
5 parts: Capacitive Soil Moisture Sensor – 3.3V/5V Analog Output, 5V Relay Module with Optocoupler (1 channel), 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 4 steps.
No. This page has the complete, tested code (main.py).
About ₹594 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.
Calibrating an analog sensor with map(); Isolation, relays and switching higher-power loads.
Ideas that reuse this build: Pico soil moisture OLED and Auto plant watering. 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.