By the end you should have:
From page 5 of the official brief:
| Required | Your Hardware |
|---|---|
| Main board | e.g., micro:bit v2 / Raspberry Pi Pico / Raspberry Pi |
| At least 1 digital input | e.g., rain sensor, smoke detector, PIR motion |
| At least 1 analogue input | e.g., soil moisture, temperature (DHT22), light sensor |
| At least 1 output | e.g., buzzer, LED, servo, OLED screen |
| Storage method | e.g., microSD card, internal flash, USB drive |
from machine import Pin, ADC, Timer
import time, os
rain_sensor = Pin(15, Pin.IN)
soil = ADC(Pin(26))
led = Pin(16, Pin.OUT)
buzzer = Pin(17, Pin.OUT)
print("Press button to calibrate/start")
button.wait_for_press()
print("System starting in 3…2…1…")
rain_detected = rain_sensor.value()moisture = soil.read_u16()
temp = dht22.temperature()if temp > 30 and moisture < 30000:
risk = "HIGH"
else:
risk = "LOW"if risk == "HIGH":
led.value(1)
buzzer.value(1)
else:
led.value(0)with open("forest_data.csv", "a") as f:
f.write(f"{time.ticks_ms()},{temp},{moisture},{risk}\n")time.sleep(30) # 30-second gap between readings
This exact flow is what makes your system fully automatic after manual start, logs real environmental data, and simulates a forest process — ticking every single basic requirement on page 5 of the official brief.
Follow these stages:
Save your final code as main.py (or equivalent) in your Artefact folder.