Skip to content

Project 2.6.23: Smart Nursery Monitoring System

Intermediate Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython


Overview

This project monitors a nursery environment for young plants by checking both soil moisture and local climate together.

Students will use a soil sensor and a BME280 to watch moisture, temperature, and humidity together, then flag when the nursery moves outside the preferred range.

The final system should report whether the nursery is healthy, too dry, too wet, too hot, too cold, or outside its preferred humidity range.

Required Components

Soil moisture sensor
Soil moisture sensor
Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
BME280 sensor module
BME280 sensor module
Green LED and 220 Ω resistor
Green LED and 220 Ω resistor
Red LED and 220 Ω resistor
Red LED and 220 Ω resistor

Circuit Connections

Component terminal Connect to Pico physical pin Notes
Soil sensor AOUT GPIO 26 / physical pin 31 ADC moisture input
BME280 sensor module Requires bme280.py on the Pico
Green LED anode GPIO 16 through 220 Ω resistor GPIO 16 / physical pin 21 Safe-state indicator
Red LED anode GPIO 17 through 220 Ω resistor GPIO 17 / physical pin 22 Alert indicator
Both LED cathodes GND Any GND pin Common return
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

Circuit Diagram

  Raspberry Pi Pico 2 W
  ┌─────────────────────┐
  │                     │
  │  GPIO 2  ───────────┤──── BME280 SDA
  │  GPIO 3  ───────────┤──── BME280 SCL
  │                     │
  │  GPIO 26 ───────────┤──── Soil Sensor AOUT
  │                     │
  │  GPIO 16 ────220Ω───┤──── Green LED (+)
  │  GPIO 17 ────220Ω───┤──── Red LED (+)
  │                     │
  │  3.3V    ───────────┤──── Soil Sensor VCC
  │  3.3V    ───────────┤──── BME280 VCC
  │                     │
  │  GND     ───────────┤──── Soil Sensor GND
  │  GND     ───────────┤──── BME280 GND
  │  GND     ───────────┤──── Green LED (-)
  │  GND     ───────────┤──── Red LED (-)
  │                     │
  └─────────────────────┘

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 nursery 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: 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. If you are using a bare BME280 sensor, use the module pins labeled VCC, GND, SDA, and SCL.

Step 5: Place and Connect the Green LED

Place the green LED on the breadboard. Identify the long leg as the anode (+) and the short leg as the cathode (-). Connect the green LED long leg through a 220Ω resistor to GPIO 16. Connect the green LED short leg to GND.

Step 6: Place and Connect the Red LED

Place the red LED on the breadboard. Identify the long leg as the anode (+) and the short leg as the cathode (-). Connect the red LED long leg through a 220Ω resistor to GPIO 17. 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] BME280 SDA connects to GPIO 2 and SCL connects to GPIO 3
  • [x] Green LED long leg connects through a 220Ω resistor to GPIO 16
  • [x] Red LED long leg connects through a 220Ω resistor to GPIO 17
  • [x] Both LED short legs connect to GND
  • [x] No loose jumper wires

Intermediate Note Test one variable at a time so you know whether soil, temperature, or humidity is causing the nursery alert. The BME280 needs 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 soil, BME280, and LED wiring before any full-system test
  • Keep the nursery sample and the board physically separated to reduce accidental spills

Test the Input Sensors

  • Calibrate the soil sensor and confirm that BME280 temperature and humidity values look realistic
  • Test one variable at a time so you know which reading changes the final state

Test the Output Devices

  • Test the green and red LEDs separately
  • Confirm that only one overall nursery state is shown at a time

Run the Full System

  • Create a dry-soil or warm-air test and observe how the system reports the nursery problem
  • Then restore the values to a healthy range and confirm that the green LED returns

Save the Project

  • Save the final code and record the nursery thresholds that worked in your environment
  • Write down which variable was hardest to keep stable during the test

Additional Testing and Calibration Checks

Calibration and tuning notes

  • Nursery thresholds should be tuned carefully because young plants respond quickly to watering and climate mistakes
  • Test one condition at a time first, then try combined issues such as dry and hot conditions together
  • If the system alerts too often, check the calibration and real climate before widening the limits
  • Use live readings, not assumptions, when deciding whether the nursery state is correct

Quick testing checklist

  • [ ] Soil, temperature, and humidity values appear correctly
  • [ ] Green LED shows the safe state
  • [ ] Red LED shows the alert state
  • [ ] The Shell lists the actual nursery problem
  • [ ] Returning the environment to normal restores the safe state

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)
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)


green_led = Pin(16, Pin.OUT)
red_led = Pin(17, Pin.OUT)

soil_dry = 52000
soil_wet = 22000
moisture_min = 60
moisture_max = 80
temp_min = 20
temp_max = 28
humidity_min = 50
humidity_max = 85


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
    if span == 0:
        return 0
    percent = int(((soil_dry - raw) * 100) / span)
    return clamp(percent, 0, 100)


def nursery_state(moisture, temp_c, humidity_pct):
    issues = []
    if moisture < moisture_min:
        issues.append("soil too dry")
    if moisture > moisture_max:
        issues.append("soil too wet")
    if temp_c < temp_min:
        issues.append("too cold")
    if temp_c > temp_max:
        issues.append("too hot")
    if humidity_pct < humidity_min:
        issues.append("humidity too low")
    if humidity_pct > humidity_max:
        issues.append("humidity too high")
    return issues


print("Smart nursery monitoring system ready")
time.sleep(2)

while True:
    try:
        moisture = soil_percent()
        temp_c, humidity_pct, pressure_hpa = read_bme280()
    except Exception as error:
        print("Sensor error:", error)
        time.sleep(2)
        continue

    issues = nursery_state(moisture, temp_c, humidity_pct)

    if issues:
        green_led.off()
        red_led.on()
        print("Nursery alert:", ", ".join(issues))
    else:
        green_led.on()
        red_led.off()
        print("Nursery OK | Soil:{}% Temp:{}C Hum:{}%".format(moisture, temp_c, humidity_pct))

    time.sleep(5)

How the Code Works

Code Section 1 Why It Matters
Nursery thresholds 1 Young plants need narrower tolerances than mature plants
nursery_state() 1 A good nursery monitor should explain what is wrong
Green and red LEDs Show whether the nursery is OK or in an alert state Visual feedback helps quick checks near the bench
Combined reporting 1 Students can compare the numbers with the summary decision

Expected Result

When moisture, temperature, and humidity all stay within the preferred nursery range, the green LED should stay on and the Shell should report an OK state. If one or more variables move outside the target range, the red LED should turn on and the Shell should explain the problem.


Troubleshooting

Problem 1 Solution
The nursery is always in alert 1 Compare the live values with the thresholds and recalibrate if needed
Humidity never changes 1 Check the BME280 wiring and read timing
The red LED never turns off The problem condition never cleared or the LED logic is wrong Restore safe conditions and verify the issue list in the Shell
Soil percentage looks unrealistic 1 Capture fresh dry and wet references for the nursery medium