Build a Smart Garden Monitor with Pi 5

Introduction

Good ventilation is important, and while monitoring your garden is pretty useful for a bunch of stuff (knowing when to water, checking light levels, tracking temperature trends) having real-time data about your plants' environment helps you make better decisions about their care.

High-quality sensor data can be used to identify optimal growing conditions for different plants. An automated monitoring system also helps prevent overwatering and underwatering, two of the most common causes of plant death among hobbyists.

This quick guide will show you how to build a comprehensive garden monitoring system using the Raspberry Pi 5, which is powerful enough to handle multiple sensors and run a web dashboard simultaneously.

About the Sensors

We'll be using three main types of sensors in this project: soil moisture sensors, temperature/humidity sensors, and light sensors. Each serves a specific purpose in monitoring plant health.

Soil Moisture Sensors measure the water content in your soil using capacitive sensing technology. Unlike resistive sensors, capacitive sensors don't corrode over time, making them ideal for long-term garden monitoring.

DHT22 Temperature/Humidity Sensors provide accurate readings of ambient conditions. The DHT22 is preferred over the DHT11 for its better accuracy (±0.5°C vs ±2°C) and wider measurement range.

BH1750 Light Sensors measure light intensity in lux, helping you understand if your plants are getting adequate light throughout the day.

Setting Up Your Raspberry Pi 5

Before connecting any sensors, we need to prepare the Raspberry Pi 5. Start by installing the latest version of Raspberry Pi OS using the Raspberry Pi Imager.

Enable I2C and SPI interfaces through raspi-config, as these are required for communicating with our sensors. You can access this by running sudo raspi-config in the terminal.

Install the required Python libraries using pip. We'll need libraries for GPIO access, I2C communication, and the specific sensor drivers.

Wiring the Sensors

Connect the soil moisture sensor to GPIO pin 17 for the digital output and to an ADC (like the MCP3008) for analog readings. The VCC goes to 3.3V and GND to ground.

The DHT22 requires just one data pin (GPIO 4), plus VCC (3.3V) and GND. Add a 10K pull-up resistor between the data pin and VCC for stable readings.

For the BH1750 light sensor, connect SDA to GPIO 2 and SCL to GPIO 3. This sensor uses the I2C protocol, so make sure I2C is enabled on your Pi.

Writing the Monitoring Code

Create a new Python file called garden_monitor.py. We'll structure our code with separate functions for reading each sensor type.

The main loop will read all sensors every 5 minutes and store the data in a SQLite database. This gives us historical data for trend analysis.

We'll also implement threshold alerts that can notify you via email or push notification when conditions fall outside optimal ranges.

Building the Web Dashboard

Using Flask, we'll create a simple web interface to display current readings and historical charts. The dashboard updates in real-time using WebSocket connections.

Chart.js provides beautiful visualizations of your sensor data over time. We'll create line charts for temperature and humidity, and gauge charts for current soil moisture levels.

Next Steps

Once your basic monitoring system is running, consider adding automated watering with solenoid valves, expanding to monitor multiple garden zones, or integrating with home automation systems like Home Assistant.