Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA USB camera works on a Raspberry Pi with no drivers: it shows up as a video device and OpenCV can read frames from it. The script compares each frame with the one before and, if enough pixels changed, saves a time-stamped photo. That is enough for a desk, a door or a shelf, and the same camera works on any other Linux board.
Point it only at your own property and tell people it is there.
Photos of people are personal data: do not publish them.
Tick anything you already have and the total updates.
8 MP autofocus USB camera with a sharper picture
Follow the colours: red is power, dark grey is ground, blue is a signal.
Use the 27 W supply with a Pi 5. A weaker supply can make the camera drop out.
motion.pyimport cv2, time, os
MIN_AREA = 2500 # pixels that must change
os.makedirs("snapshots", exist_ok=True)
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
time.sleep(2) # let exposure settle
ok, frame = cam.read()
prev = cv2.GaussianBlur(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), (21, 21), 0)
last_save = 0
while True:
ok, frame = cam.read()
if not ok:
time.sleep(1); continue
gray = cv2.GaussianBlur(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), (21, 21), 0)
diff = cv2.threshold(cv2.absdiff(prev, gray), 25, 255, cv2.THRESH_BINARY)[1]
changed = cv2.countNonZero(diff)
prev = gray
if changed > MIN_AREA and time.time() - last_save > 3: # at most one photo every 3 s
name = time.strftime("snapshots/%Y%m%d-%H%M%S.jpg")
cv2.imwrite(name, frame)
last_save = time.time()
print("saved", name, changed)
Run `lsusb` to see the camera. Try another cable, and use the Pi's own supply: low power makes cameras disappear.
Auto exposure flicker. Raise MIN_AREA, or fix exposure with `v4l2-ctl`.
Wait two seconds after opening the camera for exposure, and add light.
Yes, with OpenCV's VideoWriter, but photos need far less storage.
Any camera that appears as /dev/video0 works.
Add a short script that posts the file to a chat bot or email service.
5 parts: Raspberry Pi 5 – 8GB RAM, Raspberry Pi 27W USB-C PD Power Supply – White (IN), microSD Memory Card (Class 10), Arducam UB0238 5MP Auto Focus Mini USB Camera Board and Arducam UB0240 IMX179 8MP Autofocus USB Camera Module. 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 2 hours. The build on this page has 7 steps.
No. This page has the complete, tested code (motion.py).
About ₹31,768 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading a USB camera with OpenCV; Motion detection by frame differencing; Running a script at boot with systemd.
Point it only at your own property and tell people it is there. Photos of people are personal data: do not publish them.
Ideas that reuse this build: Pi Camera Module time-lapse. 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.