
Ever wished your plants could tell you when something’s wrong? With a Raspberry Pi, a camera, and a bit of machine learning magic, they practically can. In this guide, you’ll build an AI Plant Doctor — a smart system that snaps photos of your plants, analyzes their leaves for signs of disease, and sends alerts with care tips straight to your phone.
Perfect for hobby gardeners, balcony growers, and anyone who’s ever killed a basil plant and wondered why.
What You’ll Need
Before we dig in, gather the following equipment:
- Raspberry Pi 4 (4GB or 8GB) — the 8GB model is ideal for smoother ML inference
- Raspberry Pi Camera Module 3 (or a USB webcam)
- MicroSD card (32GB+) with Raspberry Pi OS (64-bit) installed
- Official Raspberry Pi power supply
- Camera mount or tripod to position the camera over your plants
- Weatherproof case (if placing outdoors)
- Wi-Fi connection
- (Optional) A light ring or LED strip for consistent lighting
- (Optional) A soil moisture sensor for extra plant data
You’ll also need a Telegram account (free) for receiving alerts on your phone.
Step 1: Set Up Your Raspberry Pi
Flash Raspberry Pi OS (64-bit) onto your microSD card using Raspberry Pi Imager. Boot up, connect to Wi-Fi, and run the usual updates:
sudo apt update && sudo apt full-upgrade -y
Enable the camera interface via sudo raspi-config → Interface Options → Camera.
Step 2: Install the Required Libraries
We’ll use TensorFlow Lite for lightweight, on-device inference — perfect for the Pi.
sudo apt install python3-pip python3-opencv -y
pip3 install tflite-runtime pillow numpy requests
Test your camera with:
libcamera-still -o test.jpg
If you see a crisp image of your plant, you’re good to go.
Step 3: Get a Plant Disease Detection Model
You have two great options:
- Use a pre-trained model — The PlantVillage dataset has trained models available on TensorFlow Hub and GitHub that can detect 30+ common diseases across tomatoes, potatoes, grapes, apples, and more.
- Train your own — Use Google Teachable Machine for a no-code approach, then export as a TFLite model.
Download your .tflite model and its label file (labels.txt) into a project folder like ~/plant-doctor/.
Step 4: Write the Detection Script
Create a Python script (plant_doctor.py) that:
- Captures an image from the camera every hour
- Preprocesses it (resize to 224×224, normalize)
- Runs inference with TensorFlow Lite
- If a disease is detected with high confidence, triggers an alert
Here’s the core logic:
import tflite_runtime.interpreter as tflite
import numpy as np
from PIL import Image
import subprocess, requests, time
interpreter = tflite.Interpreter(model_path="plant_model.tflite")
interpreter.allocate_tensors()
labels = open("labels.txt").read().splitlines()
def capture():
subprocess.run(["libcamera-still", "-o", "plant.jpg", "-n"])
return Image.open("plant.jpg").resize((224,224))
def predict(img):
input_data = np.expand_dims(np.array(img, dtype=np.float32)/255.0, axis=0)
interpreter.set_tensor(interpreter.get_input_details()[0]['index'], input_data)
interpreter.invoke()
output = interpreter.get_tensor(interpreter.get_output_details()[0]['index'])[0]
return labels[np.argmax(output)], max(output)
Step 5: Send Alerts to Your Phone via Telegram
Create a Telegram bot with @BotFather, grab your bot token and chat ID, then add this function:
def send_alert(disease, confidence):
msg = f"🌱 Plant Alert!\nDetected: {disease}\nConfidence: {confidence:.0%}"
requests.post(
f"https://api.telegram.org/bot<TOKEN>/sendMessage",
data={"chat_id": "<CHAT_ID>", "text": msg}
)
You can even attach the captured image and include care tips from a simple dictionary keyed to each disease (e.g., “Early blight → Remove affected leaves, apply copper fungicide, avoid overhead watering”).
Step 6: Automate It
Use cron to run the script every hour:
crontab -e
# Add:
0 * * * * /usr/bin/python3 /home/pi/plant-doctor/plant_doctor.py
Tips for Better Accuracy
- Consistent lighting matters enormously — consider a small LED ring
- Position the camera 20–30 cm from the leaves
- Retrain the model with photos of your specific plants for best results
- Clean the lens regularly if outdoors
Wrapping Up
That’s it — you now have a 24/7 AI plant doctor watching over your garden. With some tweaking, you can expand it to multiple cameras, log data to a dashboard, or integrate it with Home Assistant for automated watering.
Happy growing! 🌿
Liked this project? Follow @raspitips on Instagram for more Raspberry Pi ideas, tips, and tutorials.



