Project 2.6.25: Smart Plant Health Monitor
Intermediate Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
This project combines multiple sensors to create a simple plant-health scoring system instead of relying on only one reading.
Students will build a multi-sensor node using soil, light, and BME280 temperature, humidity, and pressure measurements, then convert those readings into a health score and LED status.
The final system should report sensor values, classify plant condition as HEALTHY, WARNING, or CRITICAL, and explain which conditions need attention.
Required Components
![]() Soil moisture sensor |
![]() Yellow LED and 220 Ω resistor |
![]() Raspberry Pi Pico 2 W |
![]() LDR and 10 kΩ resistor |
![]() BME280 sensor module |
![]() Green LED and 220 Ω resistor |
![]() Red LED and 220 Ω resistor |
![]() Breadboard and jumper wires |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| Soil sensor AOUT | GPIO 26 | GPIO 26 / physical pin 31 | ADC moisture input |
| LDR divider node | GPIO 27 | GPIO 27 / physical pin 32 | ADC light input |
| Green LED anode | GPIO 16 through 220 Ω resistor | GPIO 16 / physical pin 21 | Healthy indicator |
| Yellow LED anode | GPIO 17 through 220 Ω resistor | GPIO 17 / physical pin 22 | Warning indicator |
| Red LED anode | GPIO 18 through 220 Ω resistor | GPIO 18 / physical pin 24 | Critical indicator |
| All LED cathodes | GND | Any GND pin | Common return path |
| BME280 VCC | 3.3V | Physical pin 36 | Sensor power |
| BME280 GND | GND | Any GND pin | Common ground |
| BME280 SDA | GPIO 2 | GPIO 2 / physical pin 4 | I2C data |
| BME280 SCL | GPIO 3 | GPIO 3 / physical pin 5 | I2C clock |
Wiring Diagram

Raspberry Pi Pico 2 W
┌─────────────────────┐
│ │
│ GPIO 26 ───────────┤──── Soil Sensor AOUT
│ GPIO 27 ───────────┤──── LDR divider node
│ │
│ GPIO 2 ───────────┤──── BME280 SDA
│ GPIO 3 ───────────┤──── BME280 SCL
│ │
│ GPIO 16 ────220Ω───┤──── Green LED (+)
│ GPIO 17 ────220Ω───┤──── Yellow LED (+)
│ GPIO 18 ────220Ω───┤──── Red LED (+)
│ │
│ 3.3V ───────────┤──── Soil Sensor VCC
│ 3.3V ───────────┤──── BME280 VCC
│ 3.3V ───────────┤──── LDR one leg
│ GND ───────────┤──── All LED cathodes (-)
│ GND ───────────┤──── BME280 GND
│ GND ───────────┤──── Soil Sensor GND
│ GND ───────────┤──── 10kΩ resistor to LDR
│ │
└─────────────────────┘
LDR Circuit
┌───────────────────┐
│ LDR leg 1 ───────┤──── 3.3V
│ LDR leg 2 ───────┤──── GPIO 27
│ │ │
│ │ 10kΩ resistor
│ │ │
│ │ GND
└───────────────────┘
Step-by-Step Assembly
Step 1: Place the Raspberry Pi Pico 2W
Place the Raspberry Pi Pico 2W on the breadboard so it sits across the center gap. Keep the USB port facing outward so you can easily connect it to your computer.
Step 2: Position the Soil Moisture Sensor
Place the soil moisture probe so the sensing end can enter the soil sample. Identify VCC, GND, and AOUT / AO / Signal before wiring.
Step 3: Connect the Soil Sensor
Connect soil sensor VCC to 3.3V. Connect soil sensor GND to GND. Connect soil sensor AOUT, AO, or Signal to GPIO 26 (ADC0).
Step 4: Build the LDR Divider
Place the LDR and 10kΩ resistor on the breadboard. Connect one LDR leg to 3.3V. Connect the other LDR leg to GPIO 27. Connect one end of the 10kΩ resistor to GPIO 27. Connect the other end of the 10kΩ resistor to GND.
Step 5: Place the BME280 Sensor Module
Identify BME280 VCC, GND, SDA, and SCL before wiring. Connect BME280 VCC to 3.3V. Connect BME280 GND to GND. Connect BME280 SDA to GPIO 2 and BME280 SCL to GPIO 3.
Step 6: Place the Three LEDs
Place the green, yellow, and red LEDs on the breadboard. For each LED, identify the long leg as the anode (+) and the short leg as the cathode (-).
Step 7: Connect the Green LED
Connect the green LED long leg through a 220Ω resistor to GPIO 16. Connect the green LED short leg to GND.
Step 8: Connect the Yellow LED
Connect the yellow LED long leg through a 220Ω resistor to GPIO 17. Connect the yellow LED short leg to GND.
Step 9: Connect the Red LED
Connect the red LED long leg through a 220Ω resistor to GPIO 18. Connect the red LED short leg to GND.
Wiring Check
- [x] Pico 2W is placed correctly across the breadboard center gap
- [x] Soil sensor AOUT / AO / Signal connects to GPIO 26
- [x] LDR divider node connects to GPIO 27
- [x] 10kΩ resistor connects from GPIO 27 to GND
- [x] BME280 SDA connects to GPIO 2
- [x] BME280 SCL connects to GPIO 3
- [x] Green LED long leg connects through a 220Ω resistor to GPIO 16
- [x] Yellow LED long leg connects through a 220Ω resistor to GPIO 17
- [x] Red LED long leg connects through a 220Ω resistor to GPIO 18
- [x] All LED short legs connect to GND
- [x] No loose jumper wires
Intermediate Note Test dry soil, wet soil, bright light, and shade before judging plant health states. BME280 sensors also need a short delay between readings.
Safety Note Do not pour water onto the Pico, breadboard, USB cable, or jumper wires. Add water to the soil sample away from the electronics.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring, library, or code problems.
Hardware Setup
- Build the analog sensor wiring first so the soil and light channels can be checked carefully
- Keep the LDR resistor node firmly connected because a loose divider creates unstable readings
Test the Input Sensors
- Test the soil sensor and record dry and wet values
- Test the LDR divider by covering and uncovering the sensor while watching ADC changes
- Run a short BME280 test and confirm that temperature and humidity values appear
Test the Output Devices
- Run a short LED test to confirm the three indicators can be controlled independently
- Confirm that only one state LED is active at a time during normal operation
Run the Full System
- Upload the final code and compare the live sensor readings with the plant environment around the desk or window
- Change one condition at a time, such as shade or soil moisture, and observe how the score and state respond
Save the Project
- Save the final code and note the calibration values used for soil and light
- Record which sensor had the biggest effect on the health score during your test
Additional Testing and Calibration Checks
Calibration and tuning notes
- Calibrate the soil and light sensors before adjusting any score thresholds
- Cover the LDR to create a low-light test and compare the reported light percentage with the LED state
- If the score seems harsh or too generous, adjust the threshold bands rather than guessing from raw values
- Test one stress factor at a time so you understand which rule changed the result
Quick testing checklist
- [ ] Soil percentage changes between dry and wet conditions
- [ ] Light percentage changes between bright and shaded conditions
- [ ] BME280 returns temperature and humidity values
- [ ] Only one status LED is active at a time
- [ ] The score and issue list match the test conditions
Full Project Code
After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.
from machine import ADC, I2C, Pin
import bme280
import time
soil = ADC(26)
light = ADC(27)
i2c_bme = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
bme = bme280.BME280(i2c=i2c_bme)
def number_from_bme(text_value):
cleaned = "".join(ch for ch in str(text_value) if ch.isdigit() or ch in ".-")
return float(cleaned)
def read_bme280():
temp_text, pressure_text, humidity_text = bme.values
return number_from_bme(temp_text), number_from_bme(humidity_text), number_from_bme(pressure_text)
led_green = Pin(16, Pin.OUT)
led_yellow = Pin(17, Pin.OUT)
led_red = Pin(18, Pin.OUT)
soil_dry = 52000
soil_wet = 22000
light_dark = 8000
light_bright = 60000
def clamp(value, low, high):
if value < low:
return low
if value > high:
return high
return value
def soil_percent():
raw = soil.read_u16()
span = soil_dry - soil_wet
percent = int(((soil_dry - raw) * 100) / span)
return clamp(percent, 0, 100)
def light_percent():
raw = light.read_u16()
span = light_bright - light_dark
percent = int(((raw - light_dark) * 100) / span)
return clamp(percent, 0, 100)
def environment_values():
temp_c, humidity, pressure_hpa = read_bme280()
return temp_c, humidity
def health_report(moisture, light_level, temp_c, humidity_pct):
score = 0
issues = []
if moisture >= 45:
score += 40
elif moisture >= 30:
score += 20
issues.append("soil getting dry")
else:
issues.append("soil too dry")
if light_level >= 35:
score += 30
elif light_level >= 20:
score += 15
issues.append("light is low")
else:
issues.append("light is too low")
if 18 <= temp_c <= 30 and 35 <= humidity_pct <= 80:
score += 30
else:
issues.append("climate outside preferred range")
if score >= 75:
state = "HEALTHY"
elif score >= 45:
state = "WARNING"
else:
state = "CRITICAL"
return score, state, issues
def set_leds(state):
led_green.value(1 if state == "HEALTHY" else 0)
led_yellow.value(1 if state == "WARNING" else 0)
led_red.value(1 if state == "CRITICAL" else 0)
print("Smart plant health monitor ready")
time.sleep(2)
while True:
try:
moisture = soil_percent()
light_level = light_percent()
temp_c, humidity_pct = environment_values()
except Exception as error:
print("Sensor error:", error)
time.sleep(2)
continue
score, state, issues = health_report(moisture, light_level, temp_c, humidity_pct)
set_leds(state)
print("Moisture:{}% Light:{}% Temp:{}C Hum:{}%".format(
moisture,
light_level,
temp_c,
humidity_pct,
))
print("Health score:{} State:{} Issues:{}".format(
score,
state,
", ".join(issues) if issues else "none",
))
time.sleep(3)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
soil_percent() and light_percent() |
Convert raw ADC readings into calibrated percentages | Raw values are hard to compare without calibration |
environment_values() |
Reads temperature and humidity from the BME280 | Plant health is influenced by more than soil and light |
health_report() |
Scores the plant condition and lists issues | The student can see not just the result, but why the system chose it |
set_leds() |
Maps state names to the indicator LEDs | The display of system condition becomes easy to read from a distance |
Expected Result
The system should print moisture, light, temperature, humidity, and a health score. The green LED should indicate healthy conditions, the yellow LED should indicate warning conditions, and the red LED should indicate critical conditions when multiple factors are poor.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| The light percentage does not change | LDR divider is wired incorrectly | Check that the LDR and 10 kΩ resistor form a proper divider into GPIO 27 |
| The health score is always low | Calibration values do not match the environment | Capture fresh calibration data and tune the score bands |
| More than one LED seems active | The LED test wiring or the state logic is wrong | Recheck LED pin assignments and ensure only one state is selected |
| The BME280 sensor gives read errors | Wiring or timing issue | Keep the read interval slow and confirm the SDA and SCL wires connection |





