Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsAn analogue input can only read up to 3.3 V, so a 100 kΩ and 10 kΩ divider scales a 12 V battery down by 11. The Pico averages 16 readings, multiplies back up and shows the voltage with a bar between 11.8 and 12.6 V. Good for a car, inverter or solar battery.
Fuse the battery lead at 500 mA close to the battery. Keep to batteries up to 24 V.
Tick anything you already have and the total updates.
Two resistors scale the battery voltage down by 11 so an analog pin can measure up to about 50 V safely.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico battery voltage monitor for 12 V batteries on an OLED (MicroPython)
from machine import Pin, I2C, ADC
import ssd1306, time
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
adc = ADC(26) # divider middle point on GP26
RATIO = 11.0 # 100 kOhm + 10 kOhm divider
LOW, FULL = 11.8, 12.6 # lead-acid: low and full resting voltage
def read_v():
total = 0
for _ in range(16): # average to smooth out noise
total += adc.read_u16()
time.sleep_ms(2)
return total / 16 / 65535 * 3.3 * RATIO
while True:
v = read_v()
pct = max(0, min(100, int((v - LOW) * 100 / (FULL - LOW))))
oled.fill(0)
oled.text("Battery", 0, 0)
oled.text("{:.2f} V".format(v), 36, 20)
oled.rect(0, 40, 128, 14, 1)
oled.fill_rect(2, 42, int(124 * pct / 100), 10, 1)
oled.text("LOW" if v < LOW else "OK", 0, 56)
oled.show()
print(round(v, 2), "V")
time.sleep(1)
Measure the real resistor values and change 11.0 to (R1 + R2) / R2.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
5 parts: Resistor Assortment Kit (30 Values), 0.96" OLED Display 128x64 (I2C), 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 5 steps.
No. This page has the complete, tested code (main.py). Install this library first: ssd1306 (micropython-lib).
About ₹666 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; Voltage dividers and ADC scaling.
Fuse the battery lead at 500 mA close to the battery. Keep to batteries up to 24 V.
Ideas that reuse this build: Battery voltage tester and Pico 12 V gauge on Arduino. 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.