Raspberry Pi Pico W + ASI Biont AI Agent: Build a Smart Plant Watering System with MQTT in Minutes
Imagine telling your AI assistant: “Water the plants if the soil is dry and it’s morning” — and it just works. No manual wiring, no custom web dashboard, no endless debugging of cloud integrations. That’s what happens when you connect a $6 Raspberry Pi Pico W to the ASI Biont AI agent.
In this article, we’ll show you exactly how to turn a Pico W, a soil moisture sensor, and a relay into an intelligent watering system — all controlled through a chat conversation with an AI that writes the integration code itself.
Why Connect a Microcontroller to an AI Agent?
Raspberry Pi Pico W is a tiny, low-cost board with built-in Wi-Fi. It runs MicroPython and can read sensors, switch relays, and talk to the internet via MQTT or HTTP. But writing the glue code — the logic that decides when to water, how to handle sensor drift, or how to alert you — still takes time.
ASI Biont changes that. Instead of writing a Python script that polls MQTT topics and implements decision logic yourself, you describe your goal in natural language. The AI generates the control script, connects to your broker, and manages the Pico W’s data stream. All you do is tell it what you want.
Which Connection Method Does ASI Biont Use with Pico W?
The Pico W supports several protocols, but for this case we’ll use MQTT — it’s lightweight, reliable, and works perfectly with battery-powered IoT devices. ASI Biont connects to any MQTT broker (Mosquitto, HiveMQ, Adafruit IO) using the paho-mqtt library. The AI runs a Python script inside its sandboxed execute_python environment that subscribes to sensor topics and publishes commands to the Pico W’s actuator topic.
If you prefer direct serial communication (e.g., when the Pico W is connected via USB), ASI Biont also supports Hardware Bridge — a small Python application that runs on your PC and relays commands from the cloud to a COM port. But for Wi-Fi-enabled devices like the Pico W, MQTT is the cleanest path.
Real-Use Case: AI-Powered Plant Watering System
| Component | Purpose |
|---|---|
| Raspberry Pi Pico W | Wi-Fi microcontroller, runs MicroPython |
| Capacitive soil moisture sensor | Reads moisture level (0–65535 raw) |
| 5V relay module | Controls a water pump or solenoid valve |
| MQTT broker (e.g., Mosquitto) | Message transport between Pico W and ASI Biont |
| ASI Biont AI agent | Central logic: decides when to water, sends alerts |
The system works as follows:
1. Pico W reads the soil moisture sensor every 10 seconds.
2. It publishes the value to MQTT topic pico/sensor/moisture.
3. ASI Biont subscribes to that topic via a Python script running in its sandbox.
4. When moisture drops below a threshold (user-defined in chat), the AI checks the time of day, then publishes "ON" to pico/actuator/pump.
5. Pico W receives the command and switches the relay on for 5 seconds.
6. After watering, the AI sends a Telegram message: “Plants watered at 07:15 AM.”
Step 1: MicroPython Firmware on Pico W
Below is the code that runs on the Pico W. It connects to Wi-Fi, initializes the MQTT client, and subscribes to the actuator topic.
# Raspberry Pi Pico W firmware (MicroPython)
import network
import time
from machine import Pin, ADC
from umqtt.simple import MQTTClient
# Configuration
WIFI_SSID = "YourSSID"
WIFI_PASS = "YourPassword"
MQTT_BROKER = "192.168.1.100" # Your broker IP or cloud broker
MQTT_TOPIC_SENSOR = b"pico/sensor/moisture"
MQTT_TOPIC_ACTUATOR = b"pico/actuator/pump"
CLIENT_ID = "pico_waterer"
# Pins
moisture_sensor = ADC(26) # GP26
relay = Pin(15, Pin.OUT)
relay.value(0)
# Wi-Fi connection
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASS)
while not wlan.isconnected():
time.sleep(0.5)
print("Wi-Fi connected")
# MQTT callback
def mqtt_callback(topic, msg):
if topic == MQTT_TOPIC_ACTUATOR:
if msg == b"ON":
relay.value(1)
time.sleep(5)
relay.value(0)
print("Pump activated for 5 seconds")
# Main loop
def main():
connect_wifi()
client = MQTTClient(CLIENT_ID, MQTT_BROKER)
client.set_callback(mqtt_callback)
client.connect()
client.subscribe(MQTT_TOPIC_ACTUATOR)
print("Connected to MQTT broker, waiting...")
while True:
# Read sensor
moisture = moisture_sensor.read_u16()
client.publish(MQTT_TOPIC_SENSOR, str(moisture))
print("Published moisture:", moisture)
# Non-blocking check for incoming commands
client.check_msg()
time.sleep(10)
if __name__ == "__main__":
main()
Upload this to the Pico W using Thonny or ampy. Ensure the board is powered and connected to Wi-Fi.
Step 2: ASI Biont AI Agent Configuration (via Chat)
Open a chat with ASI Biont. Describe your setup:
“Connect to MQTT broker at 192.168.1.100:1883. Subscribe to pico/sensor/moisture. When moisture value drops below 20000 and the current hour is between 6 and 9, publish ‘ON’ to pico/actuator/pump. Also send me a Telegram notification.”
The AI immediately writes and executes this Python script in its sandbox:
import paho.mqtt.client as mqtt
import time
from datetime import datetime
import requests # for Telegram notification
# Configuration
BROKER = "192.168.1.100"
PORT = 1883
TOPIC_SENSOR = "pico/sensor/moisture"
TOPIC_ACTUATOR = "pico/actuator/pump"
MOISTURE_THRESHOLD = 20000
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID = "YOUR_CHAT_ID"
def on_message(client, userdata, msg):
try:
moisture = int(msg.payload.decode())
print(f"Received moisture: {moisture}")
hour = datetime.now().hour
if moisture < MOISTURE_THRESHOLD and 6 <= hour <= 9:
client.publish(TOPIC_ACTUATOR, "ON")
print("Published ON to pump")
# Send Telegram
requests.post(
f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage",
json={"chat_id": TELEGRAM_CHAT_ID, "text": f"Watered at {hour}:00"}
)
except Exception as e:
print(f"Error: {e}")
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe(TOPIC_SENSOR)
print("Listening...")
client.loop_forever()
The script runs continuously while the AI session is active. If you need it to persist, you can deploy it on a VPS or a Raspberry Pi — but for prototyping, the sandbox is sufficient.
Why This Approach Beats Traditional IoT Dashboards
| Traditional Method | ASI Biont Method |
|---|---|
| Write both Pico firmware and a separate backend | AI writes the backend in seconds |
| Build a web dashboard or mobile app | Chat interface replaces dashboards |
| Programming decision logic manually | Describe logic in natural language |
| Debug MQTT payloads and timeouts | AI handles error handling and retries |
With ASI Biont, you never leave the chat. No Node-RED flows, no AWS Lambda, no custom REST API. You just talk to the AI, and it does the integration.
Expanding the System
Once the basic watering system works, you can extend it with:
- Temperature sensor: Add a DHT11 to prevent watering during freezing conditions.
- Voice control: Use ASI Biont’s chat interface to say “Water for 10 seconds” — the AI publishes the command immediately.
- Data logging: The AI can log moisture history into a Google Sheet or PostgreSQL database using available libraries (openpyxl, psycopg2).
- Multi-zone watering: Add more Pico W units, each on a different topic. The AI can manage them all simultaneously.
All of these require only a conversation update, no hardware changes.
What You Need to Get Started
- Hardware: Raspberry Pi Pico W, soil moisture sensor, relay, 5V power supply.
- Software: Install MicroPython on Pico W (official Raspberry Pi documentation).
- ASI Biont account: Sign up at asibiont.com.
- Bridge (optional): For serial connections, download
bridge.pyfrom the Devices page in your dashboard. For MQTT, no bridge is needed.
Conclusion: AI Meets Embedded Systems
The Raspberry Pi Pico W is an incredible platform for IoT projects. But raw sensor data is just noise until you give it context. ASI Biont provides that context — it understands your goals, speaks MQTT fluently, and writes the glue code instantly.
Instead of spending hours on backend logic, you can focus on what matters: building cool things with hardware. Whether it’s automated gardening, smart home controls, or industrial monitoring, the combination of Pico W and ASI Biont cuts development time from days to minutes.
Try it yourself. Go to asibiont.com, create an account, and tell the AI: “Connect my Pico W to a moisture sensor and water the plants when dry.” Watch as it writes the code, connects to your broker, and starts managing your garden — all in one conversation.
Comments