Subscribe to RSS feed

splitbrain.org - electronic brain surgery since 2001

Automated Plant Watering

Our balcony is commonly known as the “Garden of Death”. Kaddi and I love to have herbs and flowers on the balcony but we suck at watering the plants. For years I said that we should have some kind of automatic system for that. This year I finally decided to build one.

Pictures at the very end.


Electronics

The basic circuit is simple. Everything is powered by a NodeMCU – an ESP8266 based board with WiFi and lots of GPIOs. There are two components: a swim sensor to warn when the water in the tank gets too low and a MOSFET that's controlling the power to the pump. The level sensor is connected to D1 (GPIO5) and ground, a 10k resistor reduces the current. The MOSFET is connected to ground, 3.3V and D2 (GPIO4) again using a 10k resistor for less current.

The pump requires 12V, the NodeMCU is powered by a 5V micro USB connector. I decided to use a 12V power supply and a readymade 12v to 5v converter.

Circuit Design

Software

The software side was relatively easy, too. The NodeMCU is programmed in Lua and even though I never coded in that language before I was able to cobble up some software that's able to read the sensors, set up WiFi and to send/receive messages through MQTT. This way I could add the whole system into my Home Assistant1) setup.

I had some trouble making the MQTT client correctly reconnect when the broker restarted. In the end I used the deprecated autoreconnect feature. If someone has an idea how to fix this, I'm open for pull requests.

Hardware

Next was the actual watering hardware. There is no water connection on our balcony, so I needed a tank based solution. I found a waste bin at IKEA that had exactly the right size for the little metal shelf we have. It holds 28 liters. The pump I bought has an 8mm exhaust connector so that determined the size of my main line. To be able to regulate the water amount per plant, I ordered some adjustable sprinkler heads which had 4mm connectors. To branch off the main line I needed some T-connectors (8/4/8).

Assembly

Time for assembly. I bought a cheap plastic container to be used as housing for the electronics. I mounted everything on a piece of cardboard. A second piece connected by M4 screws gives the whole thing stability. The pump cable was too short and had to be extended. To waterproof the connection I put shrink wrap on the individual wires, then wrapped it in Sugru.

The swim sensor needed an 11mm hole but all I had was a 10mm drill. So I used that and took a file to it. Turned out to be a perfect fit and absolutely water tight. The cable for the pump goes through the lid – I made some space (ab)using my soldering iron to melt the plastic.

To mount the controller electronics I decided to hot glue a neodymium magnet into the bottom of the box. Another one in the tank holds the box in place.

How to beat gravity? Once everything was setup, I encountered a problem. Since the tank is placed on that metal shelf, it's slightly higher than the main line watering the plants. That of course meant that once the pump started, water was pulled by gravity with no way to stop.

My first idea was to introduce a one-way valve at the highest point. It would not let water out, but let air in once the pump stopped to produce pressure. In a first test it worked perfectly, but later on for some reason it failed to work. It seems that the negative pressure created by the gravity was not enough to pull the valve back from close to open.

I finally came up with a silly low tech solution that works surprisingly well. I simply replaced the valve with a piece of tube that goes back into the tank (above water level). Now the pump pumps a bit of water back into the tank (luckily the pressure is still enough for the main line) but when the pump stops, the tube acts as an air vent breaking the water column. Problem solved.

The main line tube was mounted using zip ties and we got some little hook thingies from the hardware store to fix the output tubes. To hold the pump in place, I hot glued a piece of wood into the tank and then used wood screws to mount the pump.

Home Assistant Devices

Home Assistant Screen Home Assistant is used to actually control the whole system.

I configured two devices in Home Assistant: a MQTT Binary Sensor for the water level and a MQTT Switch to turn on and off the pump.

binary_sensor:
  - platform: mqtt
    state_topic: "/home-assistant/balcony/sensor/waterlevel"
    name: "Water Level"
    payload_on: "1"
    payload_off: "0"

switch:
  - platform: mqtt
    name: Pump
    command_topic: "/home-assistant/balcony/switch/pump"
    state_topic: "/home-assistant/balcony/sensor/pump"
    payload_on: "1"
    payload_off: "0"

This already is enough to turn on the water by a simple click.

Home Assistant Automation

Of course watering should be automatic. For now I just defined a simple timer. In the future I want to add some weather checks as well (no need to run if it's raining).

automation:
  - alias: 'Water the plants'
    trigger:
      platform: time
      at: '10:00:00'
    action:
      - service: switch.turn_on
        entity_id: switch.pump

  - alias: 'Stop watering the plants'
    trigger:
      platform: time
      at: '10:01:00'
    action:
      - service: switch.turn_off
        entity_id: switch.pump

  - alias: 'Warn on low water'
    trigger:
      platform: state
      entity_id: binary_sensor.water_level
      from: 'on'
      to: 'off'
    action:
      - service: notify.pushbullet
        data:
          message: 'Balcony is out of water!'

A moisture sensor could be attached to the NodeMCU later on as well.

Pictures

Part List

Part Bought at Price2)
NodeMCU Amazon.de 7.99€
Swim Sensor Amazon.de 8.07€
IRF520 MOSFET eBay.de 4.58€
DC connector eBay.de 2.87€
24v to 5v DC converter Amazon.de 9.67€
12v power supply Amazon.de 7.88€
Pump Amazon.de 8.49€
Plastic container local “dollar” store 1.80€
FILUR bin IKEA.de 6.99€
4mm Tube, 2 meters Amazon.de 2.77€
8mm tube, 5 meters Amazon.de 6.43€
Sprinkler Valves 25pcs Amazon.de 6.28€
Tube T-Connectors 12pcs eBay.de 8.00€
One Way Valve local hardware store 3.79€
Hook thingies 10pcs local hardware store 4.79€
Sum: 90.40€

Additional parts like resistors, wires, hot glue etc. I already had.

Please note: with more patience and ordering directly from China, you could cut those costs in half at least. All you have to do is wait a month or two for shipping.

Tags:
diy, iot, electronics, nodemcu, home-assistant
Similar posts:
1)
Home Assistant should get it's own blog post some day
2)
including shipping if applicable
Posted on Saturday, June the 10th 2017 (18 months ago).

Comments?

blog comments powered by Disqus