The Gardener's New Best Friend
Every gardener knows the feeling: you’re on vacation, the tomatoes are ripening, and a heatwave is rolling in. Your plants are silently screaming for water, and you’re 500 miles away. Traditional timers help, but they can’t adapt to sudden rain, soil moisture changes, or a sensor that’s gone haywire. What if your garden could call for help — and an AI agent could respond instantly?
In this guide, we’ll take a $6 microcontroller — the Raspberry Pi Pico W — wire it up with a soil moisture sensor, a DHT22 temperature/humidity sensor, and a relay-driven water pump, then connect the whole rig to the ASI Biont AI agent. The result? A fully autonomous smart-garden system that waters only when needed, sends you a Telegram alert when the soil dries out, and logs climate data — all without you writing a single line of boilerplate code.
Why Raspberry Pi Pico W?
The Raspberry Pi Pico W is the perfect IoT edge node. It’s cheap, ultra-low-power, and has built-in Wi-Fi (CYW43439) for about $6. With 264 KB of SRAM and 2 MB of flash, it can run MicroPython and handle MQTT communication with ease. It’s not a Linux box — it’s a real-time microcontroller — which makes it ideal for sensor polling and relay switching without the overhead of an OS.
The Connection Strategy: MQTT + execute_python
ASI Biont connects to the Pico W via MQTT, the de facto messaging protocol for IoT. The Pico W publishes sensor data (soil moisture, temperature, humidity) to a topic like garden/sensors. The AI agent, running in the ASI Biont cloud, subscribes to that topic using a Python script executed via execute_python with the paho-mqtt library. When the AI receives a reading that crosses a threshold (e.g., moisture < 30%), it publishes a command to garden/actuators to turn on the pump relay.
Why not SSH or COM port? The Pico W runs MicroPython, not a full Linux OS, so SSH is out. COM port would require a tethered computer running the Hardware Bridge, which defeats the wireless advantage. MQTT lets the Pico W sleep between readings and only wake to send a few bytes — perfect for battery-powered or low-power setups.
Wiring Diagram
Here’s a simple breadboard layout:
| Pico W Pin | Component | Notes |
|---|---|---|
| 3V3(OUT) | DHT22 VCC | Power the sensor |
| GND | DHT22 GND | Common ground |
| GP15 | DHT22 DATA | 10kΩ pull-up to 3.3V |
| 3V3(OUT) | Soil Moisture VCC | Resistive sensor |
| GND | Soil Moisture GND | |
| GP26 (ADC0) | Soil Moisture OUT | Analog voltage 0–3.3V |
| 3V3(OUT) | Relay VCC | 5V relay via transistor or module |
| GND | Relay GND | |
| GP16 | Relay IN | Active HIGH to close pump circuit |
| — | Pump | Connected to relay COM/NO terminals |
Note: Use a separate 5V supply for the pump and relay module; the Pico’s 3.3V rail can’t drive a pump. A simple transistor (2N2222) or a ready-made relay module works fine.
MicroPython Code for the Pico W
Flash your Pico W with the latest MicroPython firmware (from raspberrypi.com), then upload this main.py:
import network
import time
import utime
from machine import Pin, ADC
import dht
from umqtt.simple import MQTTClient
# Configuration
WIFI_SSID = "YourSSID"
WIFI_PASS = "YourPassword"
MQTT_BROKER = "test.mosquitto.org" # or your own broker
CLIENT_ID = "pico_garden_01"
TOPIC_SENSORS = b"garden/sensors"
TOPIC_ACTUATORS = b"garden/actuators"
# Hardware pins
dht_pin = Pin(15, Pin.IN, Pin.PULL_UP)
sensor = dht.DHT22(dht_pin)
soil_adc = ADC(Pin(26))
relay = Pin(16, Pin.OUT)
relay.value(0) # pump off
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print("Connecting to Wi-Fi...")
wlan.connect(WIFI_SSID, WIFI_PASS)
while not wlan.isconnected():
time.sleep(1)
print("Connected:", wlan.ifconfig())
def mqtt_callback(topic, msg):
print("Received:", topic, msg)
if topic == TOPIC_ACTUATORS:
if msg == b"PUMP_ON":
relay.value(1)
print("Pump ON")
elif msg == b"PUMP_OFF":
relay.value(0)
print("Pump OFF")
def publish_sensors():
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
moisture = soil_adc.read_u16() # 0–65535
# Convert to percentage (0 = wet, 65535 = dry). Adjust for your sensor.
moisture_pct = 100 - (moisture / 65535 * 100)
payload = f"{{\"temp\":{temp},\"hum\":{hum},\"moisture\":{moisture_pct:.1f}}}"
client.publish(TOPIC_SENSORS, payload)
print("Published:", payload)
except Exception as e:
print("Sensor error:", e)
# Main
connect_wifi()
client = MQTTClient(CLIENT_ID, MQTT_BROKER)
client.set_callback(mqtt_callback)
client.connect()
client.subscribe(TOPIC_ACTUATORS)
print("MQTT connected, subscribed to actuators")
while True:
publish_sensors()
client.check_msg() # non-blocking check for commands
time.sleep(60) # publish every minute
Upload this via Thonny or rshell. The Pico W will publish sensor JSON to garden/sensors every 60 seconds and listen for commands on garden/actuators.
The AI Agent: Your Gardening Brain
Now, the magic. Open a chat with ASI Biont and describe your setup:
“I have a Pico W publishing sensor data to MQTT topic garden/sensors as JSON with temp, hum, and moisture. It listens on garden/actuators for PUMP_ON / PUMP_OFF. Create a script that: if moisture < 30%, send PUMP_ON, wait 10 seconds, then send PUMP_OFF. Also send me a Telegram alert when the pump runs. Log all readings to a CSV file.”
ASI Biont will generate and execute this Python script in its execute_python sandbox:
import paho.mqtt.client as mqtt
import time
import json
import csv
from datetime import datetime
# Configuration
BROKER = "test.mosquitto.org"
TOPIC_SENSORS = "garden/sensors"
TOPIC_ACTUATORS = "garden/actuators"
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID = "YOUR_CHAT_ID"
CSV_FILE = "garden_log.csv"
# Global state
last_moisture = 100
pump_running = False
def send_telegram(message):
import requests
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
requests.post(url, json={"chat_id": TELEGRAM_CHAT_ID, "text": message})
def log_to_csv(temp, hum, moisture, pump_status):
with open(CSV_FILE, "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([datetime.now(), temp, hum, moisture, pump_status])
def on_message(client, userdata, msg):
global last_moisture
try:
data = json.loads(msg.payload)
last_moisture = data["moisture"]
temp = data["temp"]
hum = data["hum"]
print(f"Received: temp={temp}°C, hum={hum}%, moisture={last_moisture}%")
log_to_csv(temp, hum, last_moisture, pump_running)
except Exception as e:
print("Parse error:", e)
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, 1883, 60)
client.subscribe(TOPIC_SENSORS)
client.loop_start()
# Main control loop (runs for 30 seconds — sandbox limit)
for _ in range(3):
time.sleep(10)
if last_moisture < 30 and not pump_running:
client.publish(TOPIC_ACTUATORS, "PUMP_ON")
pump_running = True
send_telegram("🚨 Soil too dry! Pump activated.")
print("Pump ON")
time.sleep(10)
client.publish(TOPIC_ACTUATORS, "PUMP_OFF")
pump_running = False
send_telegram("✅ Pump stopped after 10 seconds.")
print("Pump OFF")
elif last_moisture >= 30 and pump_running:
client.publish(TOPIC_ACTUATORS, "PUMP_OFF")
pump_running = False
print("Moisture OK, pump off")
client.loop_stop()
client.disconnect()
The AI runs this script in its sandbox (30-second timeout). For continuous monitoring, you ask the AI to schedule the script as a recurring task — it will run every 5 minutes, check the latest sensor reading, and actuate the pump as needed.
Real-World Scenario: The Home Greenhouse
Problem: Sarah, an urban gardener in Berlin, has a small greenhouse on her balcony. She travels every other week and has lost two tomato harvests to underwatering during heatwaves.
Solution: She builds the Pico W garden node for €20 in parts. She configures the MQTT broker (she uses the free test.mosquitto.org for testing, then switches to a local Mosquitto on her home server for production). She asks ASI Biont to set up the integration — the AI generates the execute_python script, schedules it, and creates a Telegram bot that alerts her.
Results:
- Water usage drops 40% because the pump only runs when the soil is actually dry.
- Sarah receives a Telegram alert every time the pump activates — she can see the log on her phone.
- The CSV log reveals that her greenhouse temperature spikes to 38°C at 3 PM; she later adds a shade cloth.
- Total setup time: 2 hours for wiring + 10 minutes for the AI chat.
Why This Matters: No-Code Industrial IoT
You didn’t write a single line of the integration script. You described your hardware and what you wanted, and ASI Biont’s AI wrote the MQTT subscriber, the threshold logic, the Telegram notifier, and the CSV logger in seconds. The same approach works for any device — an ESP32 with a CO₂ sensor, a Modbus PLC in a factory, or a GPS tracker on a delivery van.
ASI Biont connects to any device through execute_python — the AI writes the integration code on the fly. No waiting for a developer to add “support” for your sensor. No dashboard widgets. Just a conversation: you describe your setup, and the AI builds the bridge.
Ready to Automate Your Garden?
Grab a Raspberry Pi Pico W, a handful of sensors, and head over to asibiont.com. Start a chat with the AI agent, describe your hardware and your goal, and watch it write the code for you. Your plants — and your free time — will thank you.
Comments