Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe Pico's analog input reads the capacitive soil probe, the code turns it into a percentage using two calibration numbers, and the OLED draws a bar. Below 35 % the red LED comes on. The calibration step teaches how every analog sensor is mapped to real units.
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.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico soil moisture monitor with an OLED and a thirsty-plant LED (MicroPython)
from machine import Pin, ADC, I2C
import ssd1306, time
soil = ADC(26) # GP26 = ADC0
led = Pin(15, Pin.OUT)
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
DRY, WET = 50000, 22000 # raw readings in air and in water: calibrate yours
THIRSTY = 35 # percent
while True:
raw = sum(soil.read_u16() for _ in range(16)) // 16
pct = max(0, min(100, (DRY - raw) * 100 // (DRY - WET)))
led.value(1 if pct < THIRSTY else 0)
oled.fill(0)
oled.text("Soil moisture", 0, 0)
oled.hline(0, 10, 128, 1)
oled.text("{} %".format(pct), 0, 24)
oled.fill_rect(0, 44, pct * 128 // 100, 10, 1)
oled.text("Water me!" if pct < THIRSTY else "Happy plant", 0, 56)
oled.show()
print("raw", raw, "moisture", pct, "%")
time.sleep(2)
Calibrate: note the raw reading in dry air and in water, and put them in SOIL_DRY and SOIL_WET.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
LED is reversed; flip it. Check the 220 Ω resistor is in series.
7 parts: Capacitive Soil Moisture Sensor – 3.3V/5V Analog Output, 0.96" OLED Display 128x64 (I2C), Through-Hole LED Pack (Pack of 10), Resistor Assortment Kit (30 Values), 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 beginner project and takes about 45 minutes. The build on this page has 4 steps.
No. This page has the complete, tested code (main.py). Install this library first: ssd1306 (micropython-lib).
About ₹735 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(); Current-limiting resistors for LEDs; Drawing text on an I²C display.
Ideas that reuse this build: Arduino automatic watering and Plant mood ring. 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.