Skip to content

ESP8266 in combination with a eight port multiplexer to support up to 8 capacitive soil moisture sensors

Notifications You must be signed in to change notification settings

Tobi0892/esp8266-4051-multiplexer-plant-sensor

Repository files navigation

ESP8266 Multi Capacitive Soil Moisture Sensor

ESP8266 in combination with a eight port multiplexer to support up to 8 capacitive soil moisture sensors.

The esp8266 reads the sensors every 10 minutes, transfers the readings via MQTT to a broker and goes back to deep sleep. The MQTT messages and can be picked up by i.e. Home Assistant.

  • Mode 1: USB powered
  • Mode 2: Battery powered (optional solar)

The code is written in MicroPython.

Mode 1: USB powered

Parts required

A usb charger and micro usb cable is assumed to be available.

Circuit diagram

mode 1 wiring

Mode 2: Battery powered

Use more batteries in parallel if you want (a) to decrease the time between sensor readings or (b) prolong the time until the next charging cycle or (c) compensate for smaller solar panels.

The solar panel is optional, of course you can also charge the batteries manually with a charger once they are drained. If you use a solar panel, you need to connect it via the micro usb port to the esp8266

Note: the Wemos D1 mini Pro v2.0.0 already has a built-in charging module.

Additional parts required

Circuit diagram

mode 2 wiring

Setup

Configuration

Use the config.json to configure the esp8266 (no changes in boot.py or main.py required).

{
  "hostname": "NAME_OF_ESP8266",
  "wifi": {
    "ssid": "YOUR_WIFI_NAME",
    "password": "YOUR_WIFI_PASSWORD",
  },
  "mqtt": {
    "user": "MQTT_USER",
    "password": "MQTT_PASSWORD",
    "broker": "MQTT_BROKER_IP",
    "port": 1883,
    "topics": "TOPIC_NAME"
  }
}

Flashing Code to ESP8266

I prefer PyCharm and the respective MicroPython plugin. Nevertheless, you can use any other suitable editor.

Create a configuration for each of the three files and flash them onto the esp8266. You can use the MicroPython REPL to watch the execution of the programs:

Connecting to WiFi...connected
Connecting to MQTT...connected
Sending: {"analog": "481", "percent": "7", "updated": "07.02.2020 23:12:25"} 
Going back to sleep...

Home Assistant

Add i.e. two mqtt sensors to your sensors.yaml (your one esp8266 published to both topics as it operates multiple soil moisture sensors)

- platform: mqtt
  name: "Ficus Benjamina"
  state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor0"
  value_template: "{{ value_json.percent }}"
  unit_of_measurement: "%"
  json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor0"
  icon: mdi:leaf
- platform: mqtt
  name: "Zitronenbaum"
  state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor1"
  value_template: "{{ value_json.percent }}"
  unit_of_measurement: "%"
  json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor1"
  icon: mdi:fruit-citrus
- platform: mqtt
  name: "Balsamapfel"
  state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor2"
  value_template: "{{ value_json.percent }}"
  unit_of_measurement: "%"
  json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor2"
  icon: mdi:sprout

And the following to ui-lovelace.yaml to display the two sensors in the lovelace frontend (Custom multiple entities card is used in this example)

  - type: markdown
    style: !include /config/ui-lovelace/style/title.yaml
    content: Pflanzen

  - type: entities
    entities:
      - type: custom:multiple-entity-row
        entity: sensor.ficus_benjamina
        hide_state: true
        primary:
          entity: sensor.ficus_benjamina
          attribute: analog
          unit: ''
          name: 'Analog'
        secondary:
          entity: sensor.ficus_benjamina
          attribute: percent
          name: 'Wasser'
          unit: '%'
      - entity: sensor.zitronenbaum
        hide_state: true
        type: custom:multiple-entity-row
        primary:
          entity: sensor.zitronenbaum
          attribute: analog
          unit: ''
          name: 'Analog'
        secondary:
          entity: sensor.zitronenbaum
          attribute: percent
          unit: '%'
          name: 'Wasser'
      - entity: sensor.balsamapfel
        hide_state: true
        type: custom:multiple-entity-row
        primary:
          entity: sensor.balsamapfel
          attribute: analog
          unit: ''
          name: 'Analog'
        secondary:
          entity: sensor.balsamapfel
          attribute: percent
          unit: '%'
          name: 'Wasser'

Result in lovelace frontend:

lovelace

Detail view:

lovelace_details

Schematics

Build pictures

Two sensors placed in a plant each sensors

Indoor case (source) indoor_case

Outdoor case with top cover (source) outdoor_case

Three sensors connected to the esp (3 more available - multiplexer supports up to 8) sensors_connected

Front view of the connectors (the wholes could have been drilled better) front

Micro usb power connected power

VCC and GND JST connectors glued in place all_inputs

6 analog pins (multiplexer channels) for 6 soil moisture sensors glued in place analog pins

Case prepared Case

Mode 1 completed without case and ability to connect 4 moisture sensors (2 more have been added after taking the picture) Mode one completed without case

Sleep pin soldered to be able to wake up from deep sleep Sleep Pin soldered

Wiring below esp8266 (not all connections are visible from the top) Wiring

Back with soldered connections Back

Multiplexer wired to headers for esp8266 without connectors for sensors multiplexer

Back of esp8266 and multiplexer wiring back_plain

Capacitive soil moisture sensors protected with hot glue soil front

Also pins at back are protected soil_back

About

ESP8266 in combination with a eight port multiplexer to support up to 8 capacitive soil moisture sensors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages