Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe ultrasonic sensor in the tank lid measures the gap to the water. The Pico takes five readings, uses the middle one to ignore stray echoes, and turns the gap into a percentage between your empty and full marks. Check the tank from the kitchen instead of climbing to the roof.
Keep the Pico and OLED indoors; run a 4-wire cable up to the sensor and seal it in the lid away from splashes.
Tick anything you already have and the total updates.
Sends a 40 kHz ultrasonic ping and times the echo to measure distance from 2 cm to about 4 m.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico water tank level in percent on an OLED (MicroPython)
from machine import Pin, I2C, time_pulse_us
import ssd1306, time
trig = Pin(2, Pin.OUT)
echo = Pin(3, Pin.IN) # through a 1 kOhm + 2 kOhm divider: echo is 5 V
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
EMPTY_CM = 120 # sensor to the bottom of the tank
FULL_CM = 20 # sensor to the water when full
def distance_cm():
trig.value(0); time.sleep_us(2)
trig.value(1); time.sleep_us(10); trig.value(0)
t = time_pulse_us(echo, 1, 30000)
return -1 if t < 0 else t * 0.0343 / 2
while True:
readings = sorted(d for d in (distance_cm() for _ in range(5)) if d > 0)
oled.fill(0)
if readings:
d = readings[len(readings) // 2] # median of five ignores odd echoes
pct = max(0, min(100, int((EMPTY_CM - d) * 100 / (EMPTY_CM - FULL_CM))))
oled.text("Tank level", 0, 0)
oled.text("{} %".format(pct), 40, 20)
oled.rect(0, 40, 128, 16, 1)
oled.fill_rect(2, 42, int(124 * pct / 100), 12, 1)
print(d, "cm", pct, "%")
else:
oled.text("No echo", 0, 0)
oled.show()
time.sleep(2)
TRIG and ECHO are swapped, or the sensor has no 5 V. Swap the two signal wires and check VCC.
Average several readings and keep wires short. Two HC-SR04s pinging at once will confuse each other.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
6 parts: HC-SR04 Ultrasonic Range Finder Sensor Module, 0.96" OLED Display 128x64 (I2C), Raspberry Pi Pico, Resistor Assortment Kit (30 Values), 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 1–2 hours. The build on this page has 5 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.
Drawing text on an I²C display; Time-of-flight measurement with sound.
Keep the Pico and OLED indoors; run a 4-wire cable up to the sensor and seal it in the lid away from splashes.
Ideas that reuse this build: Pico distance meter and Tank level 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.