Skip to content

Project 3.1.22: Portable Test Kit

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


Overview

The Pico collects gas, moisture, temperature, and humidity readings and presents them as a portable field-style test kit.

Field teams need quick multi-sensor checks when inspecting sanitation, agricultural, or environmental conditions away from a desk.

A Pico 2 W prototype with an MQ-5 liquefied petroleum/methane gas sensor, capacitive moisture sensor, BME280, and OLED display.

Multi-sensor integration, rotating display views, and practical discussion of portable measurement limits.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
BME280
BME280
Breadboard
Breadboard
Jumper wires
Jumper wires
OLED
OLED
Soil moisture sensor
Soil moisture sensor
Gas Sensor
Gas Sensor

Circuit Connections

Component terminal Connect to Pico physical pin Notes
MQ-5 AO GPIO 26 ADC0 GPIO 26 / physical pin 31 LPG/methane gas proxy input
Moisture sensor AO GPIO 27 ADC1 GPIO 27 / physical pin 32 Analog moisture reading
BME280 VCC 3.3V output Physical pin 36 Sensor power
BME280 GND GND Physical pin 38 Common ground
BME280 SDA GPIO 20 GPIO 20 / physical pin 26 I2C0 SDA shared with OLED
BME280 SCL GPIO 21 GPIO 21 / physical pin 27 I2C0 SCL shared with OLED
OLED VCC 3.3V output Physical pin 36 Display power
OLED GND GND Physical pin 38 Common ground
OLED SDA GPIO 20 GPIO 20 / physical pin 26 I2C0 SDA
OLED SCL GPIO 21 GPIO 21 / physical pin 27 I2C0 SCL

Wiring Diagram

Portable Test Kit wiring diagram

Raspberry Pi Pico 2 W
┌─────────────────────┐
│                     │
│ GPIO 26 / ADC0 ─────┼── MQ-5 AO
│ GPIO 27 / ADC1 ─────┼── Moisture sensor AO
│ GPIO 20 / SDA ──────┼── BME280 SDA + OLED SDA
│ GPIO 21 / SCL ──────┼── BME280 SCL + OLED SCL
│ 3V3 ────────────────┼── BME280 VCC + OLED VCC + safe sensor VCC
│ GND ────────────────┼── All module grounds
│                     │
└─────────────────────┘

Step-by-Step Assembly

  1. Connect the MQ-5 analog output to GPIO 26 and confirm the module is 3.3V-safe at the Pico input.
  2. Connect the moisture sensor analog output to GPIO 27.
  3. Connect the BME280 to Pico 3.3V, GND, GPIO 20 (SDA), and GPIO 21 (SCL).
  4. Connect the OLED to Pico 3.3V, GND, GPIO 20, and GPIO 21.
  5. Upload ssd1306.py and bme280.py if needed, then confirm the files appear in the Pico file list before full testing.
  6. Keep the kit wiring stable so movement between sites does not loosen the sensor connections.

Testing Individual Components

Before running the full project, test each subsystem separately. This makes it easier to find wiring, library, or logic problems before full integration.

  1. Hardware setup: Assemble the Pico, sensors, and display wiring exactly as shown in the connection table before applying power.
  2. Test the input sensors: Read each sensor separately in the serial monitor so you understand the baseline for air, moisture, temperature, and humidity.
  3. Test the output device: Run a short OLED test so the display path is validated before combining the full sensor kit.
  4. Test the decision logic: Check that the status labels update sensibly when you change one condition at a time.
  5. Run the full system: Carry the kit to at least two different locations and compare the readings and summary labels.
  6. Validate the prototype: Note which sensors drift or need the most recalibration after moving between sites.
  7. Save the project: Save the validated program on the Pico as main.py and keep a copy on the computer for future edits.

Full Project Code

After completing and checking the circuit connections, open Thonny IDE, copy and paste this code 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

try:
    from ssd1306 import SSD1306_I2C
    HAS_OLED = True
except ImportError:
    HAS_OLED = False

GAS_PIN = 26
MOISTURE_PIN = 27
BME_SDA_PIN = 20
BME_SCL_PIN = 21

gas = ADC(GAS_PIN)
moisture = ADC(MOISTURE_PIN)
i2c = I2C(0, sda=Pin(BME_SDA_PIN), scl=Pin(BME_SCL_PIN), freq=400000)
bme_sensor = bme280.BME280(i2c=i2c)

if HAS_OLED:
    oled = SSD1306_I2C(128, 64, i2c)


def moisture_label(value):
    if value < 18000:
        return "DRY"
    if value > 42000:
        return "WET"
    return "OK"


def gas_label(value):
    if value > 30000:
        return "AIR ALERT"
    if value > 18000:
        return "AIR WARN"
    return "AIR OK"


page = 0
print("Portable test kit ready")

while True:
    gas_value = gas.read_u16()
    moisture_value = moisture.read_u16()

    try:
        values = bme_sensor.values
        temperature = float(values[0].replace("C", ""))
        pressure = float(values[1].replace("hPa", ""))
        humidity = float(values[2].replace("%", ""))
    except Exception:
        temperature = 0
        pressure = 0
        humidity = 0

    print(
        "Gas:{} {} | Moisture:{} {} | Temp:{}C | Hum:{}% | Pressure:{}hPa".format(
            gas_value,
            gas_label(gas_value),
            moisture_value,
            moisture_label(moisture_value),
            temperature,
            humidity,
            pressure,
        )
    )

    if HAS_OLED:
        oled.fill(0)
        if page == 0:
            oled.text("Portable Kit", 0, 0)
            oled.text(gas_label(gas_value), 0, 20)
            oled.text("Gas:{}".format(gas_value), 0, 40)
        elif page == 1:
            oled.text("Portable Kit", 0, 0)
            oled.text(moisture_label(moisture_value), 0, 20)
            oled.text("M:{}".format(moisture_value), 0, 40)
        else:
            oled.text("Temp:{}C".format(temperature), 0, 10)
            oled.text("Hum:{}%".format(humidity), 0, 30)
            oled.text("P:{}hPa".format(pressure), 0, 50)
        oled.show()

    page = (page + 1) % 3
    time.sleep(2)

How the Code Works

Code Section What It Does Why It Matters What to Modify During Testing
Sensor setup Configures the gas, moisture, BME280, and OLED inputs and outputs The project becomes advanced by coordinating several sensor types in one portable device Check every sensor pin before changing any summary logic
Status helpers Turns raw gas and moisture values into simple local labels Field kits are easier to use when they show interpreted states as well as raw numbers Tune the label thresholds after comparing multiple real sites
Page rotation Cycles the OLED through air, moisture, and climate views One small display can still support multiple measurements with a simple screen strategy Change the page delay only after you confirm the display is readable in use
Main sampling loop Reads all sensors, prints the results, and updates the current page This creates a repeatable portable measurement workflow If one sensor is unstable, fix that hardware first instead of masking it in software

Expected Result

The serial monitor reports gas, moisture, temperature, humidity, and pressure readings clearly. The OLED rotates between air, moisture, and climate views so the kit can be used as a portable local dashboard.

Validation Checks

  • Normal condition test: Confirm the system stays in its safe or baseline state under normal room conditions.
  • Warning condition test: Move one input close to a chosen threshold and confirm the transition is sensible.
  • Critical condition test: Trigger the strongest label or alert state safely and confirm the output response is correct.
  • Calibration test: Compare the sensor readings against known dry/wet samples or a trusted room reference.
  • Limitation test: Deliberately create an awkward or noisy condition and note how the prototype behaves.

Deployment and Limitations

  • This prototype works well for classroom demonstrations and local monitoring pilots.
  • Before deployment, it needs calibration records, protective mounting, and regular validation checks.
  • Display-only systems still depend on correct sensor placement and trained users.

Troubleshooting

Problem Possible Cause Solution
One sensor always reads zero That sensor pin or power wiring is incorrect Test the failing sensor by itself before reconnecting it to the full kit
OLED stays blank I2C wiring or library file is wrong Use GPIO 20 and GPIO 21 and confirm that ssd1306.py is on the Pico
Gas readings drift a lot The gas sensor is not warmed up or the airflow keeps changing Allow more warm-up time and compare only after the reading stabilizes
Moisture labels make no sense Thresholds do not match your sample material Measure real dry and wet reference values and tune the moisture ranges
BME280 values are missing Driver file, address, or I2C wiring is wrong Confirm bme280.py, scan I2C, and recheck SDA/SCL connections