This repository contains all the necessary code, files, and instructions to build a soil moisture sensor station. The station can host up to four capacitive soil moisture sensors and send their data to an MQTT broker.
To build the soil moisture sensor station, you will need the following components:
- Raspberry Pi Pico W
- ADS1115 ADS Module
- Capacitive Soil Moisture Sensor(s) (CSM)
- Some wires
Connect the components as follows:
-
Raspberry Pi Pico W:
- Pin 38 (GND) to ground
- Pin 36 (3V3) to power
- Pin 19 (SDA) to SDA on ADS1115
- Pin 20 (SCL) to SCL on ADS1115
-
ADS1115 ADS Module:
- Connect the sensor data pin (A) to one of the ADS1115 AIN pins (0 to 3)
The code is organized into several files, each serving a specific purpose:
calibrate_sensor.py
: Calibrates the soil moisture sensors.connection.py
: Contains functions for connecting to the MQTT broker.flash.py
: Provides functions for controlling the onboard LED.min_max_values.py
: Handles files from calibration.read_ads115.py
: Contains functions to read values from the ADS1115.run.py
: Main file for executing the sensor station.umqttsimple.py
: MQTT module.config.py
: Stores MQTT settings.config_secrets.py
: Stores required secrets.
Before using the sensors, run calibrate_sensor.py
to collect data in both dry and wet states. This sets the min and max values for accurate readings.
Set the following variables:
CLIENT_ID
TOPIC_PUB
Set the following variables:
SSID
PASSWORD
MQTT_USR
MQTT_PW
BROKER_IP
BROKER_PORT
Rename run.py
to main.py
if you want it to run automatically after restart. Otherwise, start the script manually after each restart. Upon execution, the script performs the following steps:
- Connects to Wi-Fi
- Connects to the MQTT broker
- Starts a loop to collect measurements and send messages to the broker
The case design is an early prototype available on Onshape. It requires further optimization. The measurements of the components are correct, but the holes for the M2 screws and threaded inserts are oversized to accommodate printer tolerances.
Feel free to use and modify the case design according to your needs.
- Secret Handling
- Config Handling
- Revisit Case
- Battery implementation