How to control dc latching relay

Hi,

I am working on a project involving using a soil moisture sensor to control an irrigation valve that has been converted to use a dc latching relay.

My application is pretty simple. I want the soil moisture sensor to turn on the valve until soil moisture returns to a specific value. This is a research project so I will be using a data logger and a flow meter but these are topics for another time.

My challenge at this point is writing the code. Since the relay is a latching relay and activated by a pulse how do I stop the pulse from repeating as the code loops? As I understand the latching mechanism, every pulse causes the relay to activate. For example, if the valve is open, a pulse will cause it to close. The next pulse will cause it to open, and so on.

Steps

  1. Check the moisture sensor.
  2. If the value indicates wet soil, do nothing. Check the sensor again after a 5 minute delay.
  3. If the value indicates dry soil, send a pulse to the relay and open the valve.
  4. Once the value indicates wet soil, send a pulse to the relay to close the valve.

Since every pulse "triggers" the relay, I can't figure out how stop pulses from being sent repeatedly.

Is this where the "while" function should be used?

Thanks

Since the relay is a latching relay and activated by a pulse how do I stop the pulse from repeating as the code loops?

Why is the code looping while the valve is open? IF that is reasonable, then you need to remember whether the valve should be open and whether it is open. If it should be open, but is not, open it. If it should be open, and is open, move along folks, nothing to see here. If it should not be open, but is open, close it. If it should not be open, and is not open, move along folks, nothing to see here.

Maybe a while loop, maybe through state checking (finite state machine)... the latter is the more common as it allows you to do more.

Post your code for detailed suggestions.

if(valve==closed)
if(moisture < 50)
digitralWrite(relay, HIGH)
delay(250) // double whatever the relay needs, but not longer !!!! you can burn out the coils)
digialWrite(relay.LOW)
valve=OPEN // this stops this section from being repeated while the valve open
{
{

you read the moisture [time? gallons? ] and if it falls below 'x' then you would want to open the valve
if the valve is closed, you check to see if the moisture is too low

you run water for "X" [ gallons? minutes ? soil moisture ? ]
after running for X

if (valve==open)
if(conditions met.....
digitalWrite(relay, HIGH) // assuming the same pins close in a toggle fashion
delay(250) // this will be on the data sheet of how long of a pulse
digitalWrite(relay, LOW)

if you need to reverse the voltage to change the state of the relay, then you need an H-bridge
if the same pins get a second pulse, then you only need to send the second pulse.
if you have a 2 coil, then you need to have coil1 and coil2 ......

some latching relays have 2 coils, one to open, one to close
some latching relays have 1 coil and your reverse the voltage
some latching relays need 1 pulse to open, a second pulse to close, ie: each pulse will change state.

in my work, I deal with all three types of latching relays.
the 3rd is usually a mechanically held relay, think ball-point pen. where one push extends the point, a second push retracts.

[note] I found some coils need a higher current signal to activate than my power supply delivers. You can create a cap/resistor circuit to charge the cap so you have that higher current available to change the state of the relay.

Thanks very much for your reply. I have played around with the solenoid on the Toro valve and discovered that reversing the polarity of the 12 volt battery causes the solenoid to extend or retract which in turn, opens or closes the valve.

I'm afraid I don't understand the h bridge very well in spite of reading a few articles and watching a couple of videos. I also checked the Arduino h bridge shields which seem to be primarily designed to control motors. I think I will order an L298N and play with to try to better understand how to use an H bridge in the future.

In the meantime, I already own a relay shield so, my plan is to use two relays, each controlled by a separate pin from the Arduino. Both the relays will be powered by the battery but with the power wires reversed on the second relay. My theory is that when my moisture sensor reaches a given dry value, I will have a pin activate the relay that is wired to the solenoid as plus to minus. The solenoid has a plunger that, when retracted, allows the valve to open and pass water. Once the moisture sensor reaches a given wet value, I will shut off the first pin and have the second pin activate the relay that is wired minus to plus. This should cause the solenoid plunger to extend and shut the valve off.

Does this make any sense to you or am I completely off base?

Thanks again,
Jim

jfcmoore:
Thanks very much for your reply. I have played around with the solenoid on the Toro valve and discovered that reversing the polarity of the 12 volt battery causes the solenoid to extend or retract which in turn, opens or closes the valve.

re-read this :
some latching relays have 2 coils, one to open, one to close
some latching relays have 1 coil and your reverse the voltage
some latching relays need 1 pulse to open, a second pulse to close, ie: each pulse will change state.
are you saying that if you put a pulse on it, that it will change state to one state, and if you put a pulse on it, that it will go to the other state ?
or, that when you apply power it goes to one state ( latching)
and when you remove power it goes to the other state ? (non-latching)

if you actually have a latching relay, then your plan should burn out the coil.
the coil it not designed to be driven continuously.
it only needs a pulse to change state.

if you look at your Form-C relays ( common, normally open, normally closed)
you would connect one lead of the coil to the common of one relay
and the other lead to the common of the other relay.

then both of the normally closed leads of the relay to ground.
when there is no power, everyting goes to ground, and no power passes.

the NO or Normally Open goes to your 12 volts

When you want to extend, you change the state of one relay.
that would put 12V on one lead of the coil, the other going to ground would complete the circuit. and the coil would energize.

You then remove the signal. then everything goes to ground and nothing changes.

when you want to change the state of the valve, you just energize the other relay.

in all cases, when you energize the relay, it for only for a second. a pulse.

draw that out. one coil wire goes to one common of one relay, the other coil goes to the common of the other relay.
then look at what would happen when you energize one relay. then the other.

draw it and follow the lines. it should make sense pretty quickly.

once you grasp that, then
replace each NO and each NC of the relay and write in transtor.
the H-Bridge should make sense then.

sorry, but Unbuntu has nothing that even comes close to the capabilities of PAINT for a simple drawing program or I would have drawn it out for you.

Got to a Windoze PC here is a simple paint.

Perfect! That does make a lot of sense. I'll give it a try today on a small scale. I also now understand much better how the H bridge works. I did plan on just pulsing the relays with the Arduino and still have a little confusion remaining regarding how the looping will work but I think once I build the model and see it in action it will become more clear.

Thanks again for you time and expertise.

I hope I don't bore you but I'm going to share a little background regarding this project. I worked as an agronomist for the United States Golf Association for 33 year and retired in 2015. Much of my job involved dealing with the environmental challenges facing golf courses - with the greatest emphasis being to reduce water consumption by courses. One of the most efficient ways to accomplish significant water savings is to eliminate irrigation in the turfgrass areas surrounding tees. With this in mind, I am experimenting with a type of tee construction that involves applying water via a subsurface system to create a suspended water table. Essentially, a bathtub is built to allow the control of the exact height of the water table or reservoir. By selecting the correct particle size of the rootzone material, water is drawn up the roots via capillary action. A soil moisture sensor is used to determine when more water must be added to the system. I have built small scale models of the design and used a highly accurate TDR moisture sensor to check the volumetric water values of various depths of the rootzone. This is how I will calibrate the Arduino and operation of the sensor.

Since the experimental tee is actually on a golf course, I will need to compare water consumption of this tee to others that are irrigated in the conventional manner. Thus I need to collect data on my experimental tee. I will be using a flow meter and data shield to determine 1) how much water is applied over a given time period, 2) how often the system has to be recharged, and 3) how long the recharging takes place. This will be compared to the amount of water applied to an adjacent tee. Based on my scale models, I am confident I will be able to achieve and very significant reduction in water use. Since the area surrounding the tee will be converted to extremely drought tolerant plant material, the lack of irrigation will also result in significant savings in mowing, labor, fuel, and fertilizer/chemical usage.

Finally, there is no patent or copyright involved in this process. Even though I'm retired I am still on the USGA's research committee and stay active in golf course resource conservation efforts. I have two sons that are golf course superintendents so it also helps keep me close to them. My third son writes construction management software for a company in Houston. He has heard all of my old stories about writing small programs in BASIC back when PC's were first introduced. He gave me the Arduino as a birthday present, knowing that I would enjoy learning something new.

Again, I hope all this did not put you to sleep! Thanks again for your help.
Jim

Small world,

My brother is a professor and teaches agriculture did some work on grasses in golf courses after he got his PhD.

I played golf once, stepped on a rake, best balls I hit that day.

I will take a look at an H-Bridge you can buy to see if it would be easy to set up and use.
the benefit of the h-Bridge is that there are no moving parts and very little energy to change state.

The L298 is a great Stepper motor driver and also a double H-Bridge. low cost and seems like if it would work, you could just buy the thing and then use it.

jfcmoore:

Since the experimental tee is actually on a golf course, I will need to compare water consumption of this tee to others that are irrigated in the conventional manner. Thus I need to collect data on my experimental tee. I will be using a flow meter and data shield to determine 1) how much water is applied over a given time period, 2) how often the system has to be recharged, and 3) how long the recharging takes place. This will be compared to the amount of water applied to an adjacent tee. Based on my scale models, I am confident I will be able to achieve and very significant reduction in water use. Since the area surrounding the tee will be converted to extremely drought tolerant plant material, the lack of irrigation will also result in significant savings in mowing, labor, fuel, and fertilizer/chemical usage.

data logging ? are you doing that locally ?
Seems like you would need to send back to the clubhouse and then upload to the web.
There are a few line-of-sight RF units you can use that should work on the open expanse of the fairways.

I thought about that and decided against it for now. Based on my model and my calculations of expected water use, I don't anticipate the valve having to open more than a few times per week at the most. I'm at this course frequently (at least 3 times per week) since I have other projects there as well as this one. It will not be a problem to remove the sd card and copy it to my laptop. I have been reading about some of the options offered on this site for wireless data collection and sharing and it certainly is worth considering in the future. For now, it is a "walk before I run" scenario. :slight_smile:

Thanks,
Jim