solved: TB6612 Motor driver for watering system

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

solved: TB6612 Motor driver for watering system

#1 Post by werner_g » 24 Apr 2018, 22:42

solved: I changed from GPIO2 (D4) to GPIO5 (D1) - now it works! Still I would like to get suggestions for a more sophisticated code.


Based on the Tutorial rules I am trying to build up my garden watering system using a bipolar relay - so I just need short pulses of around 40msec. My motor driver / H-bridge is TB6612 and I need two pins (in my case IN1 and IN2 on GPIO's 2 and 4): 0-1 to open the valve; 1-0 to close the valve. Here are my rules:

Code: Select all

On System#Boot do
GPIO,2,0
GPIO,4,0
endon

On Clock#Time=All,21:35 do
Pulse,4,1,100
Pulse,2,0,100
timerSet,1,1 // 1sec Timer
On Rules#Timer=1 do 
GPIO,2,0
GPIO,4,0
endon

On Clock#Time=All,21:36 do
Pulse,4,0,100
Pulse,2,1,100
timerSet,2,1 // 1sec Timer
On Rules#Timer=2 do 
GPIO,2,0
GPIO,4,0
endon
But I have problems: during boot, the relay gets powered for about 4 seconds, and afterwards the blue WIFI-LED on the D1miniPro is always on - but both is not programmed. And - I have no idea if my code is OK since I don't know how long a pulse is. Maybe here is somebody how can share his similar watering system with me. Thanks.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#2 Post by alabama » 12 Jun 2018, 13:03

Hi Werner,

I want to use some valves which work with pole changing mechanism and searching ho I can control this by ESPEasy. So I found your post. Can you give me some more details on your system - especially the hardware? It seems that you do exactly what I try to do.

Thank you,
alabama

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#3 Post by werner_g » 13 Jun 2018, 08:31

Hi alabama,

I'll answer tomorrow.

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#4 Post by werner_g » 14 Jun 2018, 14:07

So, now I have a little time to explain my project. This are my hardware parts:
- Valve PEARL NX-7367-675
- WeMOS D1mini
- SparkFun Motortreiber-Dual TB6612FNG (EXPTech EXP-R05-969)

But of course you can use any other H-bridge-drive / Motor driver. This device is very simple to connect with the ESP. Just the two pins for each input and one for standby. And you have two output ports. Each one changes polarity depending on your input.The final rules in my ESP are:

Code: Select all

On System#Boot do
   GPIO,4,2	// at first set both to input 
   GPIO,5,2	// to stay save - later it’s an output
   GPIO,16,0	// STBY on, do nothing 
endon

On startwatering do
//   GPIO,16,1
   Pulse,16,1,40
   Pulse,4,1,10
   Pulse,5,0,10    //start watering (open valve)
      Publish aussen/state/WM/Garten01/watering,startwatering
//   GPIO,16,0
   timerSet,1,600   //timer 1 set for 10 minutes
endon

On stopwatering do
      timerSet,1,0//timer 1 set to halt, used to stop watering before the timer ends!
endon
 
On Rules#Timer=1 do
//   GPIO,16,1
   Pulse,16,1,40
   Pulse,4,0,10
   Pulse,5,1,10  //stop watering (close valve)
      Publish aussen/state/WM/Garten01/watering,stopwatering
//   GPIO,16,0
endon
With NodeRED I can now activate /deactivate the valve using MQTT. But You can also work with HTTP-commends. I still have problems with the valve. Nominal this should work with 3V inputs, but to have reliable switching, it is better to use 5 or 6 V. 10msec-pulses are OK.

Further plans are the integration of:
- water flow sensor just to check if water flows only during watering
- capacitive soil moisture sensor
- weather forecast from DarkSky or other

Would be fine to see your setup, maybe we can share our experiences.
Last edited by werner_g on 14 Jun 2018, 22:25, edited 1 time in total.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#5 Post by alabama » 14 Jun 2018, 17:57

I think that I have the same Valves. I have this ones:

http://www.royal-gardineer.de/Bewaesser ... -919.shtml

the H-bridge I want to use are this ones:
https://www.amazon.de/gp/product/B01BMR ... UTF8&psc=1

All in all I want to control 4 valves with two of this H-bridges with FHEM. with one
NodeMcu V3 or WeMOS D1mini.

Now I'm waiting for the H-bridges. The voltage comes by the Solarpanel and at last there shall be an additional valve to avoid suprises after the holidays (or reduce the danger for it).
Of cause I will report when I'm started. It will take time, I fear.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#6 Post by alabama » 09 Jul 2018, 01:14

Now I have one little problem with my Royal Gardeneers: It seems that they don't want to work with every kond of electricity. Even not with the laboratory power supply which is set to 3V (or a little more like 3.7V) and max. 2 A, also not with the 12V Photovoltaic via the L7850. But it works with the Samsung INR18650 batterie.

I don't understand this.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#7 Post by alabama » 05 Sep 2018, 16:06

Now the next step is done - right at time when the summer is ending.

I use 2 parts of the TB6612. Good to know: All pins of PWMA, PWMB and Stby has to be connected to HIGH in this case.
Further I use 4 Royal Gardeneer valves.
At least the control is done by use of a NodeMCE V3 where I use the pins D1, D2, D3, D4 for the one and D5, D6, D7, D8 for the other TB6612.

The voltage comes from my little PV with 12V by 2 L7805CV, one for the electronic devices by additional use of a condasator and the other for the valves. I saw that the valves will work if I use the 5V of the L7805CV.

Inside espeasy version mega-20180826 I can define under "hardware" the state of the pins at boot, but GPIO 4 and 5 are not interrested in this settings, they always HIGH after boot. So I use the rule

Code: Select all

On System#Boot do
GPIO,4,0
GPIO,5,0
endon
The settings while operation will be later done by FHEM with someting like

Code: Select all

http://192.168.xxx.xxx/control?cmd=Pulse,4,1,100

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#8 Post by werner_g » 08 Sep 2018, 17:39

Fine to hear that. What is your application - do you combine the valves with soil moisture sensors?

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#9 Post by alabama » 10 Sep 2018, 09:53

For some years I have two soil moisture sensors. One is this one:
https://www.elv.de/FS20-Bodenfeuchtesen ... tail_32273

And the other is this:
https://www.gardena.com/at/produkte/bew ... 900898401/

The FS20 is used with a selfmade sensor, because the original was broken after some years. I have to make a better one, this one can not be calibrated so exactly as I want.
The Gardena was from my old system and is included into the smarthome by this

https://www.elv.de/Funkende-Schalter-%E ... tail_45478

But honestly, I use this effectiv only about 3 week each year while our holidays. All the other time we check manually wether ther must be watered or not. Until this year I use a Gardena watering system with its own computer and this part:

https://www.heise.de/preisvergleich/gar ... 56362.html

Included in the smarthome until now this was only by manipulating the value of the both soil moisture sensors. But this spring the display of the computer was broken, so I can't re-program it, and right two days before our holiday this year it looses it's program. So the first step was to change the Gardena computer by a standard magnetic valve which is controlled by this

https://raspberrymaticshop.de/Homematic ... automation

dirrect with FHEM.
Disadvantage so far is that I can only control all 6 strands of irrigation together. With the new system four strands are to be controlled individually.

Until now the control if it shall be watered ist done something like:
- if the temperature while the day is once higher than 20°C and
- if it is not raning more than 8 ltr/m^2 while this day and
- if one of the soil moisture sensors say the soil is dry
it will be watered.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#10 Post by alabama » 18 Sep 2018, 12:55

Unfortunately I have crashed some of my TB8812 while soldering. Now I have a solution with sockets, so all the sensible components are only included after soldering. Unfortunately they are not available in the shop where I bought it and the other shop is much more expensive. Anyway, now it works. Perhaps next time I'll try to use something like this:
https://www.google.de/url?sa=i&rct=j&q= ... 4320972990
(of cause I hope there is no "next time")

And You are right, the valves only work save with voltage of 5V. And my L7805 shall give 1.5A. But even by use of a capacitor it seems to be not enough for both the valves and the electronic parts. So I use two of them in parallel.

Up to now I use in my test 2sec pulse. Of cause I'll reduce this, if it works. I think it will be better to repeat the puls 3 - 4 times to be sure that it works. On the other hand I have the flow meter to get the feedback if the valve has switched.

Now I have some idea for optimizing with view to reduce the energy. I have written that I use the homematic actor to control the main valve. So I think it will be possible to put the input voltage of the nodeMCU-V3 (control the TB6612 and the magnetic valves), ESP8266-01 (control the flow meter) also behind the homematic actor so that they only working if they realy used. Of cause I have to check whether the start of the controllers is really save.

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#11 Post by werner_g » 20 Sep 2018, 13:45

Why don't you use one single MCU for both? My ESP8266 (WEMOS D1mini) is responsible for controlling waterflow, switching the valve and inputting the soil moisture sensor. To reduce the power consumption you could use the sleep mode, because activity all 30 minutes should be enough.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#12 Post by alabama » 20 Sep 2018, 13:56

Yes, this is an idea. But can I use more than 8 GPIO from one MCU? I use H bridges, because I use 4 valves. Later I want to use even more, if everything works fine. The sleep mode is somthing I need to learn about, right. Is it possible to use the sleep mode not time controlled but event controlled? For the moisture sensors 30 minutes are okay, but the flow meter shall be finer while the water flows but do nothing while the rest of the day.

The history is that I had first used only the flow meter with the ESP8266-01 - later I bought some more comfortable MCUs and WEMOS', So the part of the flow meter is working and included in my FHEM. And I want to wait to change this until I'm sure that everything else really works fine.

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#13 Post by werner_g » 20 Sep 2018, 16:36

Yes, four valves needs a lot of IO's. This is also my roadmap. I will try to manage it with I²C. WEMOS (and others) are devivering motor shields with I²C and 2x TB6612. And for sleep mode - I also have to find out how to implement this.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#14 Post by alabama » 20 Sep 2018, 19:16

I see we think the same way😀. Like I told I thought about this WEMOS when I damaged my last devices and since some days 3 of this wait in my cellar for first tests.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#15 Post by alabama » 21 Sep 2018, 13:01

Last days I made some test runs. I control the watering up to now by FHEM with commands like

Code: Select all

http://192.168.xxx.xxx/control?cmd=Pulse,4,1,100
Later I will transfer the most part of the controlling in the rules of the NodeMCU and give only the impuls for the start from FHEM. But I saw this days that not every command from FHEM reaches the NodeMCU very save. Now I send 3 times with distance of 4s an puls with length 200ms. In the test phase I start the 4 valves each for 5 mintes and send then the identical signal like above to stop (also 3 times). Between each phase there are puses of also 5 minutes. All in all that means that 8 times with distance of 5 minutes come 3 identcal signals with distance 4s. For example I saw this morning in the log that 2 times from 8 only 2 signals are get instead of 3. Unfortunately the main valve also dont work exactly this time the first time this summer and so no water flows. So my flow meter can't give me the information whether the valves really opened. I don't understand, my batteries shall give me more than enough energy, but sometimes one of the valves doesn't switch. But perhaps this depends on the little time between my actions while the test phase. Later there will me at least several minutes between them.

Next I will optimize the controll so that FHEM only gives one command in the regular cases and the main algorith is written inside the rules. Additional the NodeMCU shall send a message by mail to tell me what happens.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#16 Post by alabama » 08 Oct 2018, 15:33

These are my current rules:

Set 1: Initialisation and individual watering of 4 lines. After 1 h every opend line shall be closed. This shall help if the closing will be forgotten.

Code: Select all

On System#Boot do
  GPIO,4,0
  GPIO,5,0
  timerSet,8,60      //Set Timer 8 for the next event in 60 seconds
endOn

On Rules#Timer=8 do
  Pulse,13,1,200
  Pulse,12,1,200
  Pulse,0,1,200
  Pulse,4,1,200
  TaskValueSet,12,1,0 //sets ‘Dauer#Dauer’ to 0
  notify 1, "System gestartet oder alle Ventile nach einer Stunde sicherheitshalber geschlossen"
endOn

On Beregnungsstart_1 do
  notify 1, "Beregnung 1 startet"
  Pulse,15,1,200  
  timerSet,8,3600      //Set Timer 8 for the next event in 3600 seconds
endOn

On Beregnungsstop_1 do
  notify 1, "Beregnung 1 stoppt"
  Pulse,13,1,200
endOn

On Beregnungsstart_2 do
  notify 1, "Beregnung 2 startet"
  Pulse,14,1,200
  timerSet,8,3600      //Set Timer 8 for the next event in 3600 seconds
endOn

On Beregnungsstop_2 do
  notify 1, "Beregnung 2 stoppt"
  Pulse,12,1,200
endOn

On Beregnungsstart_3 do
  notify 1, "Beregnung 3 startet"
  Pulse,2,1,200
  timerSet,8,3600      //Set Timer 8 for the next event in 3600 seconds
endOn

On Beregnungsstop_3 do
  notify 1, "Beregnung 3 stoppt"
  Pulse,0,1,200
endOn

On Beregnungsstart_4 do
  notify 1, "Beregnung 4 startet"
  Pulse,5,1,200
  timerSet,8,3600      //Set Timer 8 for the next event in 3600 seconds
endOn

On Beregnungsstop_4 do
  notify 1, "Beregnung 4 stoppt"
  Pulse,4,1,200
endOn
Set 2: Standard watering with variable time (up to now choosable but constant time for all 4 lines) and 5 minutes pause between the single lines.

Code: Select all

On Standardberegnung do
  TaskValueSet,12,1,%eventvalue% //sets ‘Dauer#Dauer’ to a number
  TaskValueSet,12,2,1            //sets ‘Dauer#aktiv’ to 1
endOn

On Dauer#Dauer do
  if [Dauer#aktiv]=1
    notify 1, "Standardberegnung 1 startet"
    Pulse,15,1,200  
  TaskValueSet,12,2,0            //sets ‘Dauer#aktiv’ to 0
  timerSet,1,[Dauer#Dauer]
  endif
endOn

On Rules#Timer=1 do  //When Timer1 expires, do
  notify 1, "Standardberegnung 1 stoppt"
  Pulse,13,1,200
  timerSet,2,300
endOn

On Rules#Timer=2 do  //When Timer2 expires, do
  notify 1, "Standardberegnung 2 startet"
  Pulse,14,1,200
  timerSet,3,[Dauer#Dauer]
endOn

On Rules#Timer=3 do  //When Timer3 expires, do
  notify 1, "Standardberegnung 2 stoppt"
  Pulse,12,1,200
  timerSet,4,300
endOn

On Rules#Timer=4 do  //When Timer4 expires, do
  notify 1, "Standardberegnung 3 startet"
  Pulse,2,1,200
  timerSet,5,[Dauer#Dauer]
endOn

On Rules#Timer=5 do  //When Timer5 expires, do
  notify 1, "Standardberegnung 3 stoppt"
  Pulse,0,1,200
  timerSet,6,300
endOn

On Rules#Timer=6 do  //When Timer6 expires, do
  notify 1, "Standardberegnung 4 startet"
  Pulse,5,1,200
  timerSet,7,[Dauer#Dauer]
endOn

On Rules#Timer=7 do  //When Timer7 expires, do
  notify 1, "Standardberegnung 4 stoppt"
  Pulse,4,1,200
  timerSet,8,300
endOn

jochenv
Normal user
Posts: 5
Joined: 12 May 2019, 09:34

Re: solved: TB6612 Motor driver for watering system

#17 Post by jochenv » 12 May 2019, 09:39

Hi,
I want to use the Royal Gardiner valves with the L298N motor driver. I managed to get the code right and the drive shows the correct voltage but the valve(s) don't respond. They make a faint sound when I put my ear close but don't switch. I never heard what the switching sounds like. Perhaps you can give me an idea? Does it make a "click"? Can I have broken them by using 1sec as impulse duration?
Thanks
Jochen

jochenv
Normal user
Posts: 5
Joined: 12 May 2019, 09:34

Re: solved: TB6612 Motor driver for watering system

#18 Post by jochenv » 12 May 2019, 09:41

It might be good to add that i tried with 3.6V and 5.2V

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#19 Post by alabama » 12 May 2019, 11:21

There is only a short click. In one direction it is much louder. Did you try with water?

Mine are running with 3.3V, as far as I remember. And I first also thougt that I hab killed them, but suddenly they worked. But I killed more than one motor shield while soldering them ....

jochenv
Normal user
Posts: 5
Joined: 12 May 2019, 09:34

Re: solved: TB6612 Motor driver for watering system

#20 Post by jochenv » 12 May 2019, 21:15

i actually only made dry tests so far. does it make a difference to add water? i tried blowing into one end to see if something would happen. ok, i’ll try with water and batteries instead of dry and with the motor shield:-)

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: solved: TB6612 Motor driver for watering system

#21 Post by alabama » 13 May 2019, 00:50

Exactly what I did - without success. You will not bring t to switch by blowing, I fear. Try it with water under preasure.

werner_g
Normal user
Posts: 24
Joined: 11 Jun 2017, 14:19

Re: solved: TB6612 Motor driver for watering system

#22 Post by werner_g » 13 May 2019, 14:02

A 100 msec-pulse is enough, could also be 50msec. At minimum you should use 1A. I am using a 5V/2A charger power supply and - very important - you should buffer the supply voltage (I am using 5V) of the motor shield with 100µF or more!!! Then, you would hear a very strong 'click' in one direction, and a smooth 'clack' in the other direction. No need to have water in the pipe!

jochenv
Normal user
Posts: 5
Joined: 12 May 2019, 09:34

Re: solved: TB6612 Motor driver for watering system

#23 Post by jochenv » 18 May 2019, 13:19

I just connected the valve directly to the power supply. Now I know what to look out for:-) With an electrolytic capacitor (1000µF, all I have right now) across the "power in" of the driver nothing happens. Or does it have to be in line or is the capacitor the wrong type?
thx
jochen

flummy
Normal user
Posts: 1
Joined: 23 Jun 2019, 21:38

Re: solved: TB6612 Motor driver for watering system

#24 Post by flummy » 23 Jun 2019, 22:09

Need to pick up that thread again., because I m trying to solve something like this :
werner_g wrote:
13 May 2019, 14:02
A 100 msec-pulse is enough, could also be 50msec. At minimum you should use 1A. I am using a 5V/2A charger power supply and - very important - you should buffer the supply voltage (I am using 5V) of the motor shield with 100µF or more!!! Then, you would hear a very strong 'click' in one direction, and a smooth 'clack' in the other direction. No need to have water in the pipe!
@werner: I'm sure, you are a German :) is it possible to write you an email?
can, you describe (or show a drawing or something like this) how the connection should look like? (especially the part to buffer the supply)

You would help me a lot
thanks in advance

Andreas

jochenv
Normal user
Posts: 5
Joined: 12 May 2019, 09:34

Re: solved: TB6612 Motor driver for watering system

#25 Post by jochenv » 24 Jun 2019, 22:34

after a break i am still fighting with the TB6612 and the valves. can you please post the schematic of your setup? i seem to be to dim to figure it out myself.
thanks a lot!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests