4.1.5 Smart Agriculture Research Lab Demo
Overview
Build and prototype a smart agriculture research lab demo 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
![]() Raspberry Pi Pico 2 W |
![]() Soil moisture sensor |
![]() Temperature sensor |
Irrigation status sensor |
![]() Breadboard |
![]() Jumper wires |
Components Gallery
| Component | Image |
|---|---|
| Raspberry Pi Pico 2 W | |
| Soil Moisture Sensor | |
| Temperature Sensor | |
| Irrigation Status Sensor | |
| Breadboard | |
| Jumper Wires |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| Soil Moisture | ADC0 (Pin 26) | See source design notes | Verify pin compatibility and voltage level |
| Temperature | ADC1 (Pin 27) | See source design notes | Verify pin compatibility and voltage level |
| Irrigation Status | GPIO14 | See source design notes | Verify pin compatibility and voltage level |
Step-by-Step Assembly
Hardware Setup
Step 1: Connect the Soil Moisture Sensor
Connect the soil moisture sensor output pin to ADC0 (Pin 26) on the Raspberry Pi Pico 2 W.
Step 2: Connect the Temperature Sensor
Connect the temperature sensor output pin to ADC1 (Pin 27) on the Raspberry Pi Pico 2 W.
Step 3: Connect the Irrigation Status Sensor
Connect the irrigation status sensor signal pin to GPIO14.
Step 4: Verify the Circuit
Confirm that:
- Soil moisture sensor is connected to ADC0 (Pin 26)
- Temperature sensor is connected to ADC1 (Pin 27)
- Irrigation status sensor is connected to GPIO14
- All power and ground connections are secure
Testing Individual Components
Before running the full project, test each subsystem separately. This makes it easier to find wiring, code, or logic problems.
- 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 this code into a new file or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.
Starter Code
# Smart Agriculture Research Lab - Project 356
# Research-Grade Multi-Parameter Monitoring
from machine import Pin, ADC
import time
import math
soil_sensor = ADC(Pin(26))
temp_sensor = ADC(Pin(27))
irrigation = Pin(14, Pin.IN)
# Layer 1: Farm Research Node
def read_research_data():
soil_raw = soil_sensor.read_u16()
temp_raw = temp_sensor.read_u16()
soil_moisture = int((soil_raw / 65535) * 100)
voltage = (temp_raw / 65535) * 3.3
resistance = (33000 / voltage) - 10000
temperature = 1 / (
math.log(resistance / 10000) / 3950 + 1 / 298.15
) - 273.15
irrigation_status = (
"ACTIVE" if irrigation.value() else "INACTIVE"
)
return {
"soil": soil_moisture,
"temperature": round(temperature, 1),
"irrigation": irrigation_status
}
# Layer 2: National Agriculture Index
def calculate_agri_index(data):
soil = data["soil"]
temp = data["temperature"]
soil_score = soil
temp_score = max(0, 100 - abs(temp - 25) * 5)
index = (soil_score * 0.6) + (temp_score * 0.4)
if index >= 80:
return "EXCELLENT", index
elif index >= 60:
return "GOOD", index
elif index >= 40:
return "FAIR", index
else:
return "POOR", index
# Layer 3: Intelligence Dashboard
def generate_intelligence(index, score):
recommendations = {
"EXCELLENT": [
"Maintain optimal conditions",
"Document best practices"
],
"GOOD": [
"Continue monitoring",
"Minor adjustments"
],
"FAIR": [
"Optimize irrigation",
"Review crop health"
],
"POOR": [
"Immediate intervention needed",
"Review system"
]
}
return recommendations.get(index, [])
def run_demo():
scenarios = [
(60, 24),
(30, 30),
(80, 25),
(20, 35)
]
for soil, temp in scenarios:
data = {
"soil": soil,
"temperature": temp,
"irrigation": "ACTIVE"
}
status, score = calculate_agri_index(data)
recs = generate_intelligence(status, score)
print(f"\nSoil: {soil}%, Temp: {temp}°C")
print(f"Index: {score:.1f} - {status}")
for r in recs:
print(f" - {r}")
run_demo()
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| Starter Code | Implements one layer or subsystem of the prototype | Separating the project into parts makes expert systems easier to test and improve |
Expected Result
The system should collect data, process it, control the required outputs, and show clear evidence that the prototype solves the intended problem.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No readings appear in Thonny | Incorrect wiring, wrong pins, or missing library | Recheck the circuit, confirm pin numbers, and test each module separately |
| Import error appears | Library file is missing or saved in the wrong location | Check the Pico file structure and save libraries exactly as instructed |
| Actuator does not respond | Relay/driver wiring or external power issue | Verify driver input, external power, and shared ground where required |
| Results are unstable | Sensor noise, loose wiring, or poor calibration | Secure the wiring and add calibration or averaging in code |
| Prototype works only sometimes | System is too complex to test all at once | Return to subsystem testing and integrate one part at a time |




