Skip to content

Project 4.1.3: Smart Environmental Governance Platform

Overview

Build and prototype a Smart Environmental Governance Platform using the Raspberry Pi Pico 2 W and MicroPython.

This expert project is designed as an open-ended research and prototype challenge. Learners should use the concept, suggested components, and starter code as a guide, then conduct further research, improve the design, and build a working prototype.

The final result should demonstrate a working embedded system prototype with clear documentation, testing evidence, and a short presentation of design decisions.

Required Components

Pico 2 W
Raspberry Pi Pico 2 W
Gas Sensor
Air-quality sensor
Water Level Sensor
Water-quality sensor
Breadboard
Breadboard
Jumper Wires
Jumper wires

Components

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
Air Quality Sensor ADC0 GPIO 26 / Physical Pin 31 Verify voltage compatibility
Water Quality Sensor ADC1 GPIO 27 / Physical Pin 32 Verify voltage compatibility

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2 W

Insert the Raspberry Pi Pico 2 W onto the breadboard so that it sits across the center gap.

Make sure the USB connector faces outward for easy programming.


Step 2: Connect the Air Quality Sensor

Connect the air quality sensor output to ADC0 (GPIO 26).

Ensure the sensor power requirements match the Pico's voltage limits.


Step 3: Connect the Water Quality Sensor

Connect the water quality sensor output to ADC1 (GPIO 27).

Verify correct power and ground connections.


Step 4: Verify Sensor Connections

Double-check all signal, power, and ground wiring before applying power.


Wiring Check

Before running the code, confirm:

  • Air Quality Sensor connected to GPIO 26 (ADC0)
  • Water Quality Sensor connected to GPIO 27 (ADC1)
  • Sensors powered correctly
  • Ground connections secure
  • No loose jumper wires

Testing Individual Components

Before running the full project, test each subsystem separately.

This makes it easier to find wiring, code, or logic problems.

Sensor Testing Checklist

  • Test each sensor reading in the Thonny Shell.
  • Test each actuator using a safe low-power test.
  • Verify communication between system layers.
  • Record results and adjust the prototype before final integration.

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.


# Smart Environmental Governance Platform - Project 354

from machine import Pin, ADC
import time

air_sensor = ADC(Pin(26))
water_sensor = ADC(Pin(27))

# Regulatory thresholds (simplified WHO/EPA standards)
COMPLIANCE_THRESHOLDS = {
    "air_quality_min": 60,
    "water_quality_min": 70
}

def read_environmental_data():
    """Layer 1: Compliance Monitoring Node"""
    air_raw = air_sensor.read_u16()
    water_raw = water_sensor.read_u16()

    air_quality = int(((65535 - air_raw) / 65535) * 100)
    water_quality = int(((65535 - water_raw) / 65535) * 100)

    return {
        "air_quality": air_quality,
        "water_quality": water_quality,
        "timestamp": time.time()
    }

def determine_compliance(data):
    """Layer 2: Compliance Logic"""
    air = data["air_quality"]
    water = data["water_quality"]

    air_compliant = air >= COMPLIANCE_THRESHOLDS["air_quality_min"]
    water_compliant = water >= COMPLIANCE_THRESHOLDS["water_quality_min"]

    if air_compliant and water_compliant:
        return "COMPLIANT", "PASS"
    elif not air_compliant and not water_compliant:
        return "NON-COMPLIANT", "FAIL_BOTH"
    elif not air_compliant:
        return "NON-COMPLIANT", "FAIL_AIR"
    else:
        return "NON-COMPLIANT", "FAIL_WATER"

def generate_governance_report(site_id, data, compliance):
    """Layer 3: Governance Dashboard"""

    status, detail = compliance

    report = {
        "site_id": site_id,
        "status": status,
        "detail": detail,
        "air_quality": data["air_quality"],
        "water_quality": data["water_quality"],
        "thresholds": COMPLIANCE_THRESHOLDS,
        "audit_timestamp": time.time(),
        "required_actions": [] if status == "COMPLIANT" else [
            "Issue compliance notice" if "AIR" in detail else "",
            "Issue water quality warning" if "WATER" in detail else "",
            "Schedule inspection"
        ]
    }

    return report

def start_governance_system():
    site_id = "INDUSTRIAL_SITE_001"

    while True:
        data = read_environmental_data()
        compliance = determine_compliance(data)
        report = generate_governance_report(site_id, data, compliance)

        print(f"\n{'='*50}")
        print("ENVIRONMENTAL GOVERNANCE REPORT")
        print(f"{'='*50}")
        print(f"Site: {report['site_id']}")
        print(f"Status: {report['status']}")
        print(f"Detail: {report['detail']}")

        print("\nReadings:")
        print(f" Air Quality: {report['air_quality']}%")
        print(f" Water Quality: {report['water_quality']}%")

        print("\nRequired Actions:")
        for action in report['required_actions']:
            if action:
                print(f" - {action}")

        print(f"{'='*50}")

        time.sleep(20)

start_governance_system()

How the Code Works

Code Section What It Does Why It Matters
Starter Code Implements one layer or subsystem of the prototype Makes testing and improvements easier

Expected Result

The system should:

  • Collect environmental data.
  • Process compliance information.
  • Generate governance reports.
  • Display required actions when standards are not met.
  • Demonstrate a practical environmental monitoring solution.

Troubleshooting

Problem Possible Cause Solution
No readings appear in Thonny Incorrect wiring or wrong pins Verify all wiring and sensor connections
Import error appears Missing file or library Check file locations and library installation
Actuator does not respond Driver or power issue Verify external power and shared grounds
Results are unstable Sensor noise or poor calibration Improve calibration and average readings
Prototype works only sometimes System complexity Test and integrate one subsystem at a time