WiFi Soil Moisture Sensors for Plants and Gardens - Home Assistant Enabled With ESPHome!

by Makers_Mashup in Living > Gardening

5555 Views, 58 Favorites, 0 Comments

WiFi Soil Moisture Sensors for Plants and Gardens - Home Assistant Enabled With ESPHome!

Soil Sensor.jpg

This is a very easy project for hobbyists and students. STEM teachers will find this a great tool for teaching along with horticulture classes. The Fusion 360 files are included in the project zip. The most recent updates for this project will be posed to Thangs.com (https://thangs.com/mythangs/file/844004).

There are only 3 points to solder, minimum parts and only need to 3D print 3 parts to build the sensor. They can be built for around $8 each buying products from Amazon.com. Much cheaper from places like Aliexpress, if you want to build these for the classroom plan ahead and build them for half the price.

You will need HomeAssistant setup to use these. It is insanely easy to get running. Check out https://www.home-assistant.io/ to get started. ESPHome is also required but once Home Assistant is running, the plugin is very easy to install from within Home Assistant. Don't let this be a barrier to using these awesome sensors. One of the great benefits to using Home Assistant is that it handles all of the heavy lifting for notifications, monitoring, etc. It would take you far longer to write all of this yourself to monitor them yourself.



The video for this instructable has complete details on the setup.


Supplies

Screenshot 2023-05-02 151333.jpg


Wemos D1 - https://amzn.to/41WHOL1

Capacitance Soil Sensor - https://amzn.to/41PWMmg

Be sure to get one with good reviews as these sensors are produced very cheaply.

M3x25mm Screws (x2) - https://amzn.to/3oGmOKc

Stainless will perform better given the damp plant environments.

USB Cable & 5V Power Supply - https://amzn.to/3AyrRik

3D Print the Parts

Screenshot 2023-05-02 153005.jpg
Sensor Internals.jpg
SoilSensorRenderingWithScrews.jpg
SensorFull.jpg
SoilSensorRendering.jpg

3 Parts to print. The top and cover, along with a small carriage that will hold the Wemos D1. All of them print without supports when oriented properly. Use a .14 layer height.

Solder the 3 Points From the Sensor

Screenshot 2023-05-02 151511.jpg
Screenshot 2023-05-02 151551.jpg

The soil sensor itself will come with a short cable. Cut that in half and then solder the following connections. Be sure to solder the connections as show in the photo above.


Sensor VCC solders to 5V on the Wemos

Sensor GND solders to GND on the Wemos

Signal solders to A0 on the Wemos

Assemble the Sensor

Screenshot 2023-05-02 152039.jpg

Place the Wemos into the carriage and position the soil sensor below it so the holes line up with the sensor retaining ridges.

Install the USB cable you'll use for the project (or power supply) and then place the cover onto the base.

Use the M3 Screws to hold the lid in place. There is a small ridge on the other side of the cover that will keep it from opening.

Provision the Device

Screenshot 2023-05-02 152109.jpg

Use the https://web.esphome.io/ webpage to connect to the device.

Then Provision it for first use.

You'll need to enter your wifi network and password when setting up the device.

If all goes well you'll be able to connect to your device by using "Visit Device".

Once the device is connected to your network. Adopt it inside Home Assistant from the ESP Home add-on.

Once adopted, you'll need to add the following code to your sensor YAML

web_server:
    port: 80


light:
  - platform: binary
    name: "Blue Light"
    output: light_output
    id: led_light
    restore_mode: ALWAYS_OFF


output:
  - platform: gpio
    pin: GPIO2
    id: light_output
    inverted: true


sensor:
- platform: adc
  pin: A0
  id: "adcMoisture"
  accuracy_decimals: 5
  unit_of_measurement: '%'
  filters:
    - calibrate_linear:
      - 0.32324  -> 100.0
      - 0.69336 -> 0
  name: "Plant - Moisture Level"
  update_interval: 30s
- platform: adc
  pin: A0
  id: "adcRaw_Sensor_Data"
  accuracy_decimals: 5
  name: "Plant - Sensor Voltage"
  update_interval: 30s
- platform: wifi_signal
  name: "Plant - WiFi Signal Sensor"
  update_interval: 30s

Calibrate the Device

Screenshot 2023-05-02 152130.jpg

You'll need a glass of water to calibrate the device. I suggest watching the video to see how I did it but the process is straightforward.

From your sensor webpage (the same place you went to when you clicked "visit device" in the step above) note the sensor voltage when completely dry. Then copy the HIGHEST value from your measurements and update the "calibrate_linear" part of the code with the voltage that goes to -> 0 Which is completely dry.

Then place only the black part of the sensor into water and then take the voltage readings and update the YAML with the LOWEST value you record.

Once both are updated your device is calibrated and ready for use!

Build Your Automations

Screenshot 2023-05-02 154832.jpg

The rest is up to you! Automations can do anything in Home Assistant. The video covers a sample automation where the blue light on the sensor clicks on when too dry. This is great for STEM teachers who can show children that when it turns blue, its time to water. You can also create any number of automations in Home Assistant to take actions when the low moisture is detected. If you have a Google Home or Alexa available it can announce that things need to be watered. Create a dashboard in Home Assistant to show your moisture levels. You can even use power relays to turn on watering if you desire. Phone notifications. You name it! Your options are truly limitless!

Enjoy Your Plants

Enjoy all the time you get back only focusing on the plants that need watering!