MultiSoilMoistureSensor_bb.png | ||
MultiSoilMoistureSensor.fzz | ||
MultiSoilMoistureSensor.ino | ||
README.md |
Multiple Soil Moisture Sensors with ESP32
Parts
- ESP32 or similar low-power WiFi-enabled board. I used this: https://www.sparkfun.com/products/23386
- Simple soil moisture sensors that are readable with either analog voltage or digital (1/0) output. There are others that use i.e. RS-485 but this guide doesn't cover that. I used these: https://www.amazon.com/dp/B0C6XGRKS5
- Optional: Qwiic OLED screen to view moisture without another device. I used this: https://www.sparkfun.com/products/22495 however in the future I'll likely go without in order to save battery power.
Code
See the .ino file in this repo.
Installation
- Edit the .ino file to modify the WiFi and MQTT settings to fit your environment.
- Set the IDE to use the "ESP32 Dev Module" board, or whatever fits your hardware.
- Upload the code to the board. You may need to hold a button after resetting to enter into flashing mode (see the hardware instructions).
- Plug in your moisture sensors according to this Fritzing wiring diagram (the 3-pin connectors represent the sensors; adjust accordingly to match the pins on your actual sensors. The ESP32 also may not match your ESP32; check the correct pinout for Analog Inputs):
- Plug the ESP32 into power if not already. Test the sensors with a piece of metal or a damp finger. The measurements should output via serial, OLED screen, and MQTT. By default it will refresh every 10 seconds, however in the future I'll likely greatly reduce this or even put the hardware into a long low-power sleep to save battery.
- Add the following to your Home Assistant configuration (presuming you have the MQTT integration configured and running properly; use MQTT Explorer to test):
mqtt:
sensor:
- name: "Plant 1 Water"
unique_id: esp_plant1
state_topic: "esp/plants/1"
qos: 2
unit_of_measurement: "%"
device_class: moisture
state_class: measurement
value_template: "{{ value }}"
- name: "Plant 2 Water"
unique_id: esp_plant2
state_topic: "esp/plants/2"
qos: 2
unit_of_measurement: "%"
device_class: moisture
state_class: measurement
value_template: "{{ value }}"
- name: "Plant 3 Water"
unique_id: esp_plant3
state_topic: "esp/plants/3"
qos: 2
unit_of_measurement: "%"
device_class: moisture
state_class: measurement
value_template: "{{ value }}"
- name: "Plant 4 Water"
unique_id: esp_plant4
state_topic: "esp/plants/4"
qos: 2
unit_of_measurement: "%"
device_class: moisture
state_class: measurement
value_template: "{{ value }}"
- Restart Home Assistant.
- Create a HA graph Card:
chart_type: line
period: 5minute
type: statistics-graph
entities:
- sensor.plant_1_water
- sensor.plant_2_water
- sensor.plant_3_water
- sensor.plant_4_water
stat_types:
- mean
days_to_show: 1
PRs, suggestions, and project photos welcome!