Dosing Fertilizers System - Best cheap way to set 8 relay-connected peristaltic mini-pumps (step motors)

Hello, my first post here, I’m really impressed with HA community. My very first steps on creating an automated watering system with variable and easily perishable fertilizers.

Why do I need this?
The fertilizers I use in my garden are organic, and very perishable. They need to be mixed in the watering water in the moment of watering the plants, not before.
Most of the fertilizers are in a liquid state, except for one, which is thicker, but still a liquid.
Fertilizers need to be administered with precision. The minimum unit I use is 1ml. I learned that some cheap pumps can measure with an acceptable precision the amount of liquid they pull off if there’s a way to control precisely the duration of the time they are switched on. In my case, the minimum duration I will need is 1 second (for 1ml of fertilizer).
I normally do this manually, but I need it to be handled automatically, at least when I’m out for vacations.

So, I spent the whole day researching and here is the draft I have so far.

Bill of materials

  • 8 peristaltic pumps (still need to figure out the voltage)
  • a 8 channel relay 5V, arduino compatible;
  • an ESP32 Node MCU or an ESP8266 (i have a couple of spare Wemos D1 Mini clones that I could use ideally);
  • a power supply to feed the relay (still need to figure out the convenient model)
  • a power supply for the ESP device (I have an old phone charger that I could use ideally)
  • a PC fan (5V?), some magnets and a magnetic mixer, for mixing
  • tubes for connecting everything.

My doubts so far:

  • Is it possible to create such automation in HA?
  • Will a relay+ESP be the best way to get this kind of precision in duration?
  • Am I doing well with my bill of material? Am I missing something or would you do something different?
  • Since I’m also a noob on electronics, how shall I look to the voltages of the different devices in this particular situation?

I thank you in advance for any help I can get with this project!

1 Like

Does that one smells like licorice?

Sure - or even directly on the esp (with esphome that could be even easier than in ha)

It will be precise enough. The relays will be the “laziest” part in the chain - still precssion within one second should be achievable. The esp loops every 16ms and this is the theoretical minimum for a action. If you use solid state relays or even just mosfets you can probably get very short timings with that (but I doubt that’s really in need for your project)

Both are up to the task the only problem with the esp8266 is the limited amount of GPIO’s. You can’t even control the 8 relays easily but you might just make use of a port expansion module like done here:

https://khaz.me/cheap-and-easy-control-of-8-relays-through-home-assistant/

LGTM :+1: You can use the same 5V PSU for the esp and relays. Not sure how the mixing will be done but you will figure that out or know it already :wink:

Easiest is to have the same voltage across all devices, but it’s also no problem if like the pumps for example will be 12V. You can then use a 12V PSU and a DC-DC converter (like in the linked article) to get it down to 5V for the esp and relays.

Welcome and keep us posted :seedling:

1 Like

@Planeta, thank you very much for your answer. First things first:

Not in this case, it is actually a bit smelly. But I heard that these kind of devices can be easily adapted to different purposes :slight_smile:

Yeah, that’s how I’m looking forward to do.

Thank you for this clarification. I’m about to buy a local used regular relay, but in other case perhaps I would give a shot for the solid state ones, since they are kind of cheap if waiting is not a problem. Anyhow, as you say, for this kind of project, I won’t need a precision more than one second, so the regular relay should work.

Have not thought about GPIO’s…I was checking for prices and getting an ESP32 is currently cheaper than the port expansion, so I guess I’m going with that.

Yes, I have a used 5V PSU incoming and I will try to use it for all. The pumps will need their own 12v PSU tough. For mixing I’m thinking about something I saw from Led Gardener. PC fans, magnets, and magnetic stirs. Something to think after I got stuff running.

Will keep you posted!

So, I finally had some time to startup with some tests.
I went forward and got a couple of 28BYJ-48 Step motors + ULN2003 Driver Boards as in this kit. I 3d printed some casing for my first mini-pump, using this stl.
I put everything together, including the 3mm silicone tube, and this is the final result:



I followed some wiring diagram for Wemos D1 Mini I found in youtube and and reached this point for the complete assemble:

Now I’m facing the first challenges, because I can’t find a way to control the step motor trough Home assistant.
I followed the official instructions for the ESPHome Stepper component that I’ve found here.
My ESPHome device config is like so:

esphome:
  name: stepper1

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - logger.log: "Speed updated"
        - stepper.set_target:
            id: stepper1
            target: !lambda 'return target;'

stepper:
  - platform: uln2003
    id: stepper1
    sleep_when_done: true
    pin_a: D1
    pin_b: D2
    pin_c: D3
    pin_d: D4
    max_speed: 250 steps/s 
    
ota:
  password: "xxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Stepper1 Fallback Hotspot"
    password: "gttVq24mOPHi"

captive_portal:
    

My HA config file earned this bunch:

# STEPPERS
input_number: 
  stepper_control:
    name: Stepper Control
    initial: 0
    min: -1000
    max: 1000
    step: 1
    mode: slider

And my automations.yaml file got this:

- id: '1661897634736'
  alias: Control Stepper
  trigger:
    platform: state
    entity_id: input_number.stepper_control
  action:
  - service: esphome.stepper1
    data_template:
        target: "{{ trigger.to_state.state | int }}"

All I can get is this in my dashboard:
Untitled

But whatever I do there, the motor does not move. I feel it warm tough.

My log for the ESPHome device is like so:

Another issue seems to be the fact that the pins show out of place…

After I installed the final config in the device, the 2 lights that were lit in the stepper driver are now off, and there is a continuous blue light in the Wemos.

Probably many things are happening, where shall I start?

Thanks in advance for any help I can get!

I finally found my mistake. It was in the automations code. It should have been:

  alias: Write Stepper Value to ESP
  trigger:
  - platform: state
    entity_id: input_number.stepper_control
  action:
  - service: esphome.stepper1_control_stepper
    data_template:
      target: '{{ trigger.to_state.state | int }}'

Now, I’m moving forward in order to be able to fully control the amount of liquid that comes out from each pump. Going nowhere just with the default stepper slider input number.

EDIT: almost forgot…also added a 5V power supply to the project, here is my updated wiring:

Hi and thank you for posting this “how-to” looking forward to downloading the YAML file and adapting them to my setup. A couple of questions: First off if you use the ESP8266 do you still use D1, D2, D3, and D4? Second question: Do you need the automation part for this to work? Not entirely sure what the automation yaml does. Thank you.

It is a pleasure to contribute to this generous community. Im using a ESP8266 and I found out that as long as you make everything correspond in the pins of the ESPHome, It shall be okay - You could use whatever pins you like. Somewhere in the future, I will try connecting more than one driver to a ESP device, somehow using this principle, hopefully it will work.
Not sure if the automation is needed but I know that while my automation was not working, my motor was not spinning.
I’ve spent today some good time checking the official information regarding this stepper component, maybe you’ll also find it useful. Good luck!

Thank you for responding to my questions. I noticed you used the Wemos 8266 I used the GEEKCREIT DOIT ESP-F Devkit V4 board. This is the 32pin devboard and I am not certain which pins to use for the driver board as in pin_a: D1

    pin_b: D2
    pin_c: D3
    pin_d: D4

LC Technology supply an 8-channel relay board with on-board ESP-8266 (ESP-12F) module:
http://www.chinalctech.com/cpzx/Programmer/512.html

Available from Aliexpress.com:
Esp8266 Wifi Eight-way Relay Development Board Ac 250v/dc 30v Esp-12f Linkage Trigger Delay Adjustable Timing Cyclic On - Relays - AliExpress

Could save you a LOT of wiring. Here is the ESPHome YAML code I use for mine. It functions as an eight-channel lighting controller, providing eight separate on/off switches for low-voltage lighting.

esphome:
  name: front-yard-lights
  platform: ESP8266
  board: esp12e

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: !secret

ota:
  password: !secret

wifi:
  ssid: !secret
  password: !secret
  fast_connect: false
  power_save_mode: NONE
  reboot_timeout:  5min
  use_address: front-yard-lights.local
  domain: .local
  manual_ip:
    static_ip: 192.168.1.24
    subnet:    255.255.255.0
    gateway:   192.168.1.1
    dns1:      208.67.222.222
    dns2:      208.67.220.220

#
# Eight GPIO relay outputs, 
# exposed as switches in Home Assistant,
# one for each lighting zone
#
switch:
  - platform: gpio
    pin: GPIO16
    name: Zone1
    id: relay1
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO14
    name: Zone2
    id: relay2
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO12
    name: Zone3
    id: relay3
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO13
    name: Zone4
    id: relay4
    restore_mode: always_off

  - platform: gpio
    pin: GPIO15
    name: Zone5
    id: relay5
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO0
    name: Zone6
    id: relay6
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO4
    name: Zone7
    id: relay7
    restore_mode: always_off
    
  - platform: gpio
    pin: GPIO5
    name: Zone8
    id: relay8
    restore_mode: always_off
1 Like

I would try to use any “D” pin available, as long as I make the respective correspondence in the ESPHome device code.

Interesting, I will give it a look. Thanks!
@FredTheFrog do you think this could work with a single ULN2003 Driver Board? And if so, how exactly?

The relays are single-pole double-throw units, and will only switch one signal each. Easiest method is one driver board (if absolutely necessary) for each relay. Now, if the +VDC current supplied to the center pole of each relay is sufficient (not sourced from the ESP GPIO pin) a driver board may not be required. The power supply for the motors would be separate/isolated from the GPIO pin.

Thank you for putting time in your answer. Since I’m not into electronics, I’m unsure if I got everything. Let’s say that I would be able to connect a driver board per relay, how could I control it through HA/ESPHome? To where would I connect the 1N1, 1N2, 1N3, 1N4 pins of each driver board?

I apologize, as I am just finishing my first :coffee: this morning. I now see you are using stepper motors, where multiple signals/poles are necessary to drive each device. I’m not experienced using steppers, so someone with more knowledge would have to assist. Good luck!

It may help to check out the various ESPHome lawn/landscape irrigation threads, as there is code available there for duration and scheduling, from which you could benefit.

Thank you! Have a nice coffee!!! :slight_smile: I will check your suggestions.

1 Like

So, after experimenting a bit with different tubing, I found that my mini pump would run more consistently when using 2mm ID x 3mm OD silicon tubes. Also, I need something to hold the tube in place. For now, I’m using a simple paper clip.
Here is a short video of a working prototype.

I also found out that in order to pump 1ml of liquid, I would need to activate the pump about 10.000 steps. This is precise enough for administrating fertilizers, as I initially intended.

So, now I could use some advice. How can I extend my control of the pump?
Currently I can only control the stepper in a limited amount of steps, with the default slider:


Also, I still dont understand how can I get rid of the absolute position.
I was checking the ESPHome stepper component documentation, but I’m afraid I’m still too novice to understand the more advanced stuff in there.
What I need is, let’s say, a button that can reset the position of the slider, and, let’s say, a box where I can input the precise number of steps I need the pump to make.

Perhaps someone can help me in how to start?

Thank you very much.

Here is an updated for the ones interested.
With the honourable help of the community, particularly TinyDoT, I made some progress in controlling a stepper motor for fertigation purposes.
Here is my current control dashboard:
imagem

Improvements:

  • Now I can control the stepper movement trough an input number;
  • I now have a sensor displaying the current position of the stepper;
  • I now have an automation that always resets the stepper position and the stepper control input number, every time the stepper position state changes, with one second delay.

Here is the updated code for everything:
ESPHome device:

esphome:
  name: stepper1

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxx"
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - logger.log: "Speed updated"
        - stepper.set_target:
            id: stepper1
            target: !lambda 'return target;'
    - service: stepper1_position
      variables:
        position: int
      then:
       - stepper.report_position:
            id: stepper1
            position: !lambda 'return position;'

stepper:
  - platform: uln2003
    id: stepper1
    sleep_when_done: true
    pin_a: D1
    pin_b: D2
    pin_c: D3
    pin_d: D4
    max_speed: 250 steps/s 

sensor:
  - platform: template
    name: "Stepper Position"
    unit_of_measurement: steps
    lambda: return id(stepper1).current_position;
    update_interval: 1s
    
ota:
  password: "xxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Stepper1 Fallback Hotspot"
    password: "xxxxxxxxxxxxxxx"

captive_portal:
    

HA Config:

# STEPPERS
  stepper_control:
    name: Stepper Control
    initial: 0
    min: -500000
    max: 500000
    step: 100
    mode: box

My automations file:

- id: Stepper Reset to Zero
  alias: Stepper Reset to Zero
  trigger:
  - platform: numeric_state
    entity_id: sensor.uptime_sensor_stepper1
    below: -120
  action:
  - service: esphome.stepper1_stepper1_position
    data:
      position: '0'
  - service: esphome.stepper1_control_stepper
    data:
      target: '0'
- id: '1666632846795'
  alias: Reset to Zero after state change (1 sec)
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.stepper_position
    for:
      hours: 0
      minutes: 0
      seconds: 1
  condition: []
  action:
  - service: automation.trigger
    data: {}
    target:
      entity_id: automation.stepper_reset_to_zero
  - service: input_number.set_value
    data:
      value: 0
    target:
      entity_id: input_number.stepper_control
  mode: single

My next steps:

  • create an automation that adds the appropriate fertilizers, in the appropriate dosage, according to the growing stage of the plants;
  • set up a pH meter to correct the fertigation pH level in the above mentioned automation;
  • set up a mixer, possibly using stirring magnet(s) and a pc fan;
  • set up everything with the relay - as promised in the beginning of the thread.

Will keep you posted. I really enjoy this community! Thanks :slight_smile:

Hi, thanks for your code, I’m busy getting it to work. I think in your HA Config file you miss the first line:

# HA Config 
# STEPPERS
input_number:             #you were missing this part
  stepper_control:
    name: Stepper Control
    initial: 0
    min: -500000
    max: 500000
    step: 100
    mode: box
1 Like

Hi,have You finished this project? Where have You defined sensor.uptime_sensor_stepper1?
Thanx

Hey there, it’s been a while…Sorry all for the unresponsiveness. Lately, I’ve been able to come back to this and I feel that the first prototype can be shared soon.
Nevertheless, I’m having some electrical dilemmas. Let me show you:

Each ULN2003 driver board controls one 28BYJ-48 step motor, plugged to a D1mini.
Every D1mini shall have it’s own power source via USB.
I’m not using D1mini as power sources for the step motors.
I can set the system to only allow a single motor to work at a time.

1 - how many driver boards can I plug in parallel to this power supply?
In the image you can see that it was tested with 2. But can I do it with 8?
2 - If I can go ahead to make the parallel connection of the 8 motors, are there any tips in how exactly do so? Are there more appropriated connectors than the basic Dupont tips I’m using?
3 - Is there a more adequate way to power up the eight D1mini’s each with a single USB Cable? Are there any USB splitters for example?

Thanks!

Update: Also, I still have a spare 8 Relay that it wont be suitable for the initial purpose after all…