Skip to content

Project 1.12.9

Bluetooth Soil Dryness Monitor

Project 1.12.9: Bluetooth Soil Dryness Monitor

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

Overview

Build a Bluetooth soil dryness monitor that reports moisture level to your phone.

This project demonstrates how an analog sensor reading can be turned into a simple percentage.

The final result should let a phone request the current soil moisture percentage and see whether the soil is dry or okay.

Required Components

Pico 2 W
Raspberry Pi Pico 2 W
Soil moisture sensor
Soil moisture sensor
Breadboard
Breadboard
Jumper Wires
Jumper wires
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 Use 3.3V for ADC-safe testing
Soil sensor GND GND Physical pin 38 Common ground
Soil sensor AOUT GPIO 26 GPIO 26 / physical pin 31 ADC input

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2 W

Place the Raspberry Pi Pico 2 W 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.

Pico Placement


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.

Sensor Placement


Step 3: Connect the Soil Sensor Power

Connect soil sensor VCC to 3.3V.

Connect soil sensor GND to GND.

Soil Sensor Power


Step 4: Connect the Soil Sensor Signal Pin

Connect soil sensor AOUT to GPIO 26.

GPIO 26 is the ADC input used by this project.

Soil Sensor Signal Wiring


Wiring Check

    • Pico 2 W 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 ADC reading changes between dry and wet conditions.

from machine import ADC, Pin
import time

soil = ADC(Pin(26))
while True:
    print('Raw soil value:', soil.read_u16())
    time.sleep(0.5)

Expected test result: The printed value should change when the sensor moves between drier and wetter soil.


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-Soil')
print('Scan for Pico-Soil in your BLE app')
while True:
    time.sleep(1)

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


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-Soil')


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


def moisture_status(percent):
    if percent < 30:
        return 'DRY'
    return 'OK'


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

    moisture = get_moisture_percent()
    status = moisture_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)

last_status = moisture_status(get_moisture_percent())
print('Bluetooth soil monitor ready')
print('Connect with a BLE app and send: read, status, moisture, or help')

while True:
    moisture = get_moisture_percent()
    current_status = moisture_status(moisture)
    if current_status != last_status:
        uart.write(('Status changed: {} ({}%)\n'.format(current_status, moisture)).encode())
        print('Status changed:', current_status, moisture)
        last_status = current_status
    time.sleep(1)

How the Code Works

Code Section What It Does Why It Matters
get_moisture_percent() Converts the raw ADC value into a percentage A percentage is easier for beginners to understand
moisture_status() Labels the reading as DRY or OK This gives a quick decision from the sensor data
on_rx() callback Sends the current reading to the phone when asked Students can request live moisture data at any time
Status change check Sends a Bluetooth message when the dry or okay state changes This turns the project into an automatic alert

Expected Result

After running the code, your phone BLE app should find Pico-Soil. Sending read, status, or moisture should return the current moisture percentage and a status such as DRY or OK. If the soil changes enough to cross the threshold, the Pico should also send an update message.


Troubleshooting

Problem Possible Cause Solution
Moisture value never changes Sensor wiring is wrong or the probe is not changing conditions Check AOUT on GPIO 26 and compare dry and wet readings
Phone cannot find Pico-Soil BLE helper files are missing or Bluetooth is not active Check that ble_uart.py and ble_advertising.py are saved on the Pico and rerun the advertising test
Percentage seems inaccurate Different soil sensors need calibration Treat the number as an estimate and adjust the dry threshold after testing your own sensor