Skip to content

BraunRudolf/moisture_sensor

Repository files navigation

Soil Moisture Sensor Station

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.

Table of Contents

  1. Integration
    1. Part List
    2. Wiring
  2. Code
    1. Overview
    2. Calibration
    3. Configuration
    4. Execution
  3. Case
  4. To-Dos

Integration

Part List

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

Wiring

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)

Breadboard View

Code

Overview

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.

Calibration

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.

Configuration

config.py

Set the following variables:

  • CLIENT_ID
  • TOPIC_PUB

config_secrets.py

Set the following variables:

  • SSID
  • PASSWORD
  • MQTT_USR
  • MQTT_PW
  • BROKER_IP
  • BROKER_PORT

Execution

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:

  1. Connects to Wi-Fi
  2. Connects to the MQTT broker
  3. Starts a loop to collect measurements and send messages to the broker

Case

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.

To-Dos

  • Secret Handling
  • Config Handling
  • Revisit Case
  • Battery implementation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages