Project 1.11.2
IoT Plant Status Monitor
Overview
Build a plant-status dashboard that combines soil moisture, temperature, humidity, and light readings in one project.
This project demonstrates combining I2C and ADC sensors in a single monitor.
The final result should show plant-related status information on both an OLED display and a local web dashboard.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() Soil moisture sensor |
![]() BME280 module |
![]() LDR (light dependent resistor) |
![]() SH1106 OLED display |
![]() Breadboard |
![]() Jumper wires |
Small plant or pot of soil |
| 2.4 GHz Wi-Fi network | Phone or computer browser |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| BME280 VCC | 3.3V | Physical pin 36 | |
| BME280 GND | GND | Physical pin 38 | |
| BME280 SDA | GPIO 8 | GPIO 8 / physical pin 11 | I2C0 SDA |
| BME280 SCL | GPIO 9 | GPIO 9 / physical pin 12 | I2C0 SCL |
| OLED VCC | 3.3V | Physical pin 36 | |
| OLED GND | GND | Physical pin 38 | |
| OLED SDA | GPIO 8 | GPIO 8 / physical pin 11 | Shared I2C data line |
| OLED SCL | GPIO 9 | GPIO 9 / physical pin 12 | Shared I2C clock line |
| Soil sensor VCC | 3.3V | Physical pin 36 | |
| Soil sensor GND | GND | Physical pin 38 | |
| Soil sensor AOUT | GPIO 26 | GPIO 26 / physical pin 31 | ADC input |
| LDR leg 1 | 3.3V | Physical pin 36 | Top side of voltage divider |
| LDR leg 2 | GPIO 27 | GPIO 27 / physical pin 32 | |
| LDR leg 2 | GND | Physical pin 38 | Bottom side of voltage divider |
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: Place the BME280, OLED, Soil Sensor, and LDR
Place the BME280 module and SH1106 OLED display module on the breadboard.
Place the soil moisture sensor module on the breadboard, or position it so the probe can enter soil.
Place the LDR and 10kΩ resistor on the breadboard.
Check the printed pin labels on each module before wiring.

Step 3: Connect the BME280
Connect BME280 VCC to 3.3V.
Connect BME280 GND to GND.
Connect BME280 SDA to GPIO 8.
Connect BME280 SCL to GPIO 9.

Step 4: Connect the OLED
Connect OLED VCC to 3.3V.
Connect OLED GND to GND.
Connect OLED SDA to GPIO 8.
Connect OLED SCL to GPIO 9.

Step 5: Connect the Soil Moisture Sensor
Connect soil sensor VCC to 3.3V.
Connect soil sensor GND to GND.
Connect soil sensor AOUT to GPIO 26.

Step 6: Connect the LDR to 3.3V
Connect LDR VCC to 3.3V.
Connect LDR A0 to GPIO 27.
Connect the LDR GND to GND.

Wiring Check
Pico 2W is placed correctly across the breadboard center gap
BME280 VCC connects to 3.3V
BME280 GND connects to GND
BME280 SDA connects to GPIO 8
BME280 SCL connects to GPIO 9
OLED VCC connects to 3.3V
OLED GND connects to GND
OLED SDA connects to GPIO 8
OLED SCL connects to GPIO 9
Soil moisture sensor VCC connects to 3.3V
Soil moisture sensor GND connects to GND
Soil moisture sensor AOUT connects to GPIO 26
One LDR leg connects to 3.3V
Other LDR leg connects to GPIO 27
Other LDR leg connects to GND
No loose jumper wires
Beginner Note
The BME280 and OLED share I2C pins, while the soil sensor and LDR use separate ADC pins.
Safety Note
Do not pour water onto the Pico or breadboard. Insert the soil probe carefully and avoid damaging roots.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
I2C scanner test
Check that the BME280 and OLED both appear on the I2C bus.
from machine import I2C, Pin
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
print([hex(addr) for addr in i2c.scan()])
Expected test result: You should usually see the BME280 address 0x76 or 0x77 and the OLED address 0x3c.
BME280 test
Check that temperature and humidity values can be read.
from machine import I2C, Pin
import BME280
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
try:
bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
bme = BME280.BME280(i2c=i2c, address=0x77)
print('Temperature:', bme.temperature)
print('Humidity:', bme.humidity)
Expected test result: The Shell should print temperature and humidity values.
Soil sensor ADC test
Check that the soil moisture sensor reading changes between dry and wet conditions.
from machine import ADC, Pin
import time
adc = ADC(Pin(26))
while True:
print(adc.read_u16())
time.sleep(0.5)
Expected test result: The raw ADC value should change between dry and wet conditions.
LDR ADC test
Check that the LDR light reading changes when the light level changes.
from machine import ADC, Pin
import time
adc = ADC(Pin(27))
while True:
print(adc.read_u16())
time.sleep(0.5)
Expected test result: The raw ADC value should change when you cover the LDR or shine more light on it.
OLED text test
Check that the OLED driver works.
from machine import I2C, Pin
import sh1106
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
oled = sh1106.SH1106_I2C(128, 64, i2c)
oled.fill(0)
oled.text('Plant Status', 12, 28, 1)
oled.show()
Expected test result: The OLED should show Plant Status.
Wi-Fi connection test
Check that the Pico connects to Wi-Fi and prints its IP address.
import network
import time
SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
for _ in range(15):
if wlan.isconnected():
break
print('Connecting...')
time.sleep(1)
print('Connected:', wlan.isconnected())
if wlan.isconnected():
print('IP address:', wlan.ifconfig()[0])
Expected test result: The Shell should show Connected: True and print an IP address.
Full Project Code
Upload and run this code after the individual tests work correctly.
import network
import socket
import time
from machine import ADC, I2C, Pin
import sh1106
import BME280
SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
oled = sh1106.SH1106_I2C(128, 64, i2c)
try:
bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
bme = BME280.BME280(i2c=i2c, address=0x77)
soil_adc = ADC(Pin(26))
light_adc = ADC(Pin(27))
SOIL_DRY = 58000
SOIL_WET = 20000
def soil_percent():
raw = soil_adc.read_u16()
if raw >= SOIL_DRY:
return 0
if raw <= SOIL_WET:
return 100
return int((SOIL_DRY - raw) / (SOIL_DRY - SOIL_WET) * 100)
def light_percent():
raw = light_adc.read_u16()
return int((raw / 65535) * 100)
def plant_status(soil, light):
if soil < 25:
return 'Needs Water'
if light < 20:
return 'Needs Light'
return 'Plant OK'
def web_page(soil, temp, hum, light, status):
return '''<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta http-equiv='refresh' content='5'>
<title>IoT Plant Status</title>
</head>
<body style='font-family:Arial;text-align:center;padding:30px'>
<h1>IoT Plant Status</h1>
<p>Soil Moisture: {}%</p>
<p>Temperature: {}</p>
<p>Humidity: {}</p>
<p>Light: {}%</p>
<h3>{}</h3>
</body>
</html>'''.format(soil, temp, hum, light, status)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
print('Connecting to Wi-Fi...')
for _ in range(15):
if wlan.isconnected():
break
time.sleep(1)
if not wlan.isconnected():
raise RuntimeError('Wi-Fi connection failed')
ip_address = wlan.ifconfig()[0]
print('Connected. Open http://{} in your browser'.format(ip_address))
address = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
server = socket.socket()
server.bind(address)
server.listen(1)
server.settimeout(0.2)
while True:
soil = soil_percent()
light = light_percent()
temp = str(bme.temperature)
hum = str(bme.humidity)
status = plant_status(soil, light)
oled.fill(0)
oled.text('Plant Status', 12, 0, 1)
oled.text('Soil:{}%'.format(soil), 0, 18, 1)
oled.text('Light:{}%'.format(light), 0, 32, 1)
oled.text(status[:16], 0, 50, 1)
oled.show()
try:
client, client_address = server.accept()
except OSError:
continue
client.recv(1024)
response = web_page(soil, temp, hum, light, status)
client.send('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n'.encode())
client.sendall(response.encode())
client.close()
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
| Mixed sensor setup | Uses one I2C bus for BME280 and OLED plus two ADC inputs for soil and light | This project brings several beginner sensor ideas together |
| soil_percent() | Converts the moisture sensor reading into a percentage | The plant dashboard needs a simple moisture value |
| light_percent() | Converts the LDR reading into a light percentage | This lets the project describe the room light level simply |
| plant_status() | Creates a simple overall plant message | The dashboard becomes easier to understand than showing only raw numbers |
Expected Result
After entering your Wi-Fi details and running the code, the OLED and browser page should show soil moisture, temperature, humidity, light level, and a simple overall plant status such as Needs Water, Needs Light, or Plant OK.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Soil reading looks wrong | Moisture calibration values do not match your sensor | Print raw ADC values and adjust SOIL_DRY and SOIL_WET |
| Light reading never changes | LDR voltage divider is wired incorrectly | Check the 3.3V -> LDR -> GPIO 27 junction -> 10kΩ -> GND path |
| No BME280 values | Wrong I2C wiring or wrong address | Run the I2C scanner and try 0x76 or 0x77 |
| OLED shows nothing | Wrong pins or missing sh1106.py | Check GPIO 8/9 and confirm the library file is on the Pico |






