Skip to content

Project 1.12.5

Bluetooth Plant Moisture Monitor

Overview

Build a Bluetooth soil-moisture monitor that sends plant status information to a phone app.

This project demonstrates combining an analog sensor with Bluetooth messages.

The final result should let the phone request the current moisture level and show whether the plant needs water.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
Soil moisture sensor
Soil moisture sensor
Breadboard
Breadboard
Jumper wires
Jumper wires
Phone with BLE app
Phone with BLE app

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
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

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 1

Step 2: Place the Soil Moisture Sensor

Place the soil moisture sensor module on the breadboard, or position it so the probe can be inserted into soil.

Identify VCC, GND, and AOUT before wiring.

Check the printed pin labels on your module because pin order can vary.

Step 2

Step 3: Connect the Soil Sensor VCC

Connect soil sensor VCC to 3.3V.

Step 3

Step 4: Connect the Soil Sensor GND

Connect soil sensor GND to GND.

Step 4

Step 5: Connect the Soil Sensor Signal Pin

Connect soil sensor AOUT to GPIO 26.

GPIO 26 is the ADC input used by this project.


Wiring Check

Pico 2W is placed correctly across the breadboard center gap

Soil moisture sensor VCC connects to 3.3V

Soil moisture sensor GND connects to GND

Soil moisture sensor AOUT connects to GPIO 26

No loose jumper wires


Beginner Note

Test the sensor in dry soil and wet soil before choosing moisture thresholds. Soil and sensor readings can vary.


Safety Note

Do not pour water onto the Pico or breadboard. Insert only the sensor probe into soil.


Testing Individual Components

Before running the full project, test each part separately. This makes it easier to find wiring or code problems.

Soil Moisture ADC Test

Check that the moisture 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.

BLE Advertising Test

Check that the Pico advertises as a BLE device your phone can see.

import bluetooth
import time
from ble_uart import BLEUART

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Plant')

print('Scan for Pico-Plant in your BLE app')

while True:
    time.sleep(1)

Expected test result: Your phone BLE app should find a device named Pico-Plant.


Full Project Code

Upload and run this code after the individual tests work correctly.

from machine import ADC, Pin
import bluetooth
import time
from ble_uart import BLEUART

soil = ADC(Pin(26))

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Plant')


def get_moisture_percent():
    raw = soil.read_u16()
    return 100 - int((raw / 65535) * 100)


def plant_status(percent):
    if percent < 30:
        return 'NEEDS WATER!'
    return 'OK'


def on_rx(data):
    command = data.decode('utf-8').strip().lower()
    print('Received command:', command)

    moisture = get_moisture_percent()
    status = plant_status(moisture)

    if command in ('read', 'status', 'moisture'):
        uart.write(('Moisture: {}%\n'.format(moisture)).encode())
        uart.write(('Status: {}\n'.format(status)).encode())
    elif command == 'help':
        uart.write(b'Commands: read, status, moisture, help\n')
    else:
        uart.write(b'Unknown command. Send help.\n')


uart.on_rx(on_rx)

print('Bluetooth plant moisture monitor ready')
print('Connect with a BLE app and send read, status, moisture, or help')

while True:
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
ADC moisture read Reads the soil sensor and converts it into a percentage The BLE app needs a simple moisture value instead of a raw ADC number
plant_status() Turns the moisture percentage into a beginner-friendly message This helps students interpret the reading quickly
BLEUART service Creates the Bluetooth text link to the phone This is how the sensor data is requested
on_rx() callback Sends the moisture and status reply when the phone asks for it The app gets live plant information on demand

Expected Result

After running the code, your phone BLE app should find Pico-Plant. Sending read, status, or moisture should return the current soil moisture percentage and a simple plant status such as OK or NEEDS WATER!


Troubleshooting

Problem Possible Cause Solution
Moisture never changes Sensor is not connected correctly or not in different conditions Check AOUT on GPIO 26 and test dry and wet conditions
Phone cannot find Pico-Plant BLE libraries are missing or Bluetooth is not active Check the library files and rerun the advertising test
Status seems wrong The threshold is not suitable for your sensor Adjust the 30% threshold after testing your own sensor readings