Author Topic: Moteino Based Battery Operated Sprinkler Valve  (Read 39773 times)

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Moteino Based Battery Operated Sprinkler Valve
« on: April 17, 2015, 05:34:04 PM »
Well, I've finally gotten the Sprinkler Valve deployed and tested and, hopefully, will be successfully maintaining the water level in my stream from now on.

For the moment, I'll post the PDF of the schematic and a snap of the unit.  I'll post more (eagle files, code, circuit/code description) later this weekend.

Tom

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #1 on: April 17, 2015, 09:44:33 PM »
Another wonderful project-post in the making, thank you Tom, keep up this great work, can't wait to see more!

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #2 on: April 18, 2015, 09:56:45 AM »
I have attached below the Eagle Files, an Example Sketch that will operate the valve (no radio code is included in the example), and a few photos (as many as will fit) showing some aspects of the implementation.

Project Description

Using Moteino with an RFM69HW radio, I wanted to be able to remotely control a standard irrigation valve entirely from batteries and have these batteries last, at a minimum, an entire season of watering.  At my home I have SOME irrigation that had been installed by the previous owner, but there are areas that are not covered by the existing system.  Obviously I will need to supply water to these areas, but I didn't want to complicate the new installations with the added complexity of supplying power and control wires to each of the areas that needed new valves - basically I wanted the freedom to place a valve anywhere I could access a water supply.

Given that I already have my home, yard, and workshop covered with Moteino networks, this was the first and foremost consideration.

The first step was to figure out how to open an irrigation valve using batteries.  Most valves I had seen were 24VAC valves. These drew a lot of power and, even if they were operable with a DC supply, running on DC would consume even more power.  Then I discovered DC Latching Solenoids.  These solenoids magnetically latch at either open or closed position and you only need a very hefty pulse to overcome the magnetic latch and drive the solenoid to its opposite state.  It takes a lot of power to drive them, but power is only required for the very brief time it takes to trip.

I purchased one of these solenoids to measure its characteristics (irrigation companies do not supply specifications for these) and discovered that I could operate it with a 12 volt pulse as short as 10mS.  To switch state, I simply applied the DC voltage in the opposite phase. I also discovered that the current would peak at about 1Amp.  Not something I wanted to supply from batteries!

Given the need to drive the solenoid with two opposite polarity signals, an H-bridge driver was the obvious choice and, given that I only needed this 12V supply for a very brief period of time, a switching boost circuit was another obvious element.

I considered using a boost regulator to generate the 12V but realized that I didn't need an accurate voltage, I just needed 'enough' voltage.  Also, I only needed the voltage when the Moteino had already concluded that it needed to change the valve's state and it would have nothing to do while waiting for the voltage to be generated so...

The next obvious conclusion was to use the Moteino processor to generate the switching pulses and monitor the resulting voltage until it was 'enough', then simply fire off the H-bridge to trip the solenoid.

So the overall functional block was clear.  I would have a switcher charge up a capacitor to 'enough' voltage and then use the H-bridge to dump the cap into the solenoid in the proper polarity.  Through experimentation, I determined that 470uF was enough to supply the energy needed to trip the solenoid if I charged it to 12 volts.  Being a conservative guy, I doubled this in the final design.  This would take longer to charge, but would be more reliable at tripping sluggish solenoids, and it wasn't too critical how long it took (as long as it wasn't so excessive that it drained my batteries).

The final choice was the choice of the inductor to boost the voltage into the capacitor.  Here I carefully applied the WIHOH(1) method of component selection and chose a 220uH inductor I had used on another project.

With this circuit implementation, then, I could use a simple loop of back to back digitalWrites(2) driving the gate of Q5, first ON to push current into the inductor (via the 33ohm current limiter) and then OFF to have L1 flyback the current into C1, charging -VSOLENOID to a negative voltage until, after so many pulses, the Moteino would do an analogRead of the A0 pin to check on how much charge was available.  The outer loop continued until there was 'enough'.  Q5 was then turned off and Q1 or Q3 was turned on to switch on the high side of the H-bridge.  One of the cross coupled gates for Q2 and Q4 would then be biased on, thereby completing the circuit to drive the solenoid.

In the circuit, Q6 was added simply to open up the current path through the inductor when the switcher was powered down.  Net is that there is literally no current flowing to the H-Bridge or Switcher once C1 is discharged.

Note that the radio uses a PCB mounted Helix antenna.  I used this so that the weatherproof box was truly weather proof with no openings as required by a straight wire antenna.  This reduces the gain quite a bit, but the device still has plenty of signal margin and is a nice compact package.

Notes:
1: WIHOH - What I Have On Hand.
2. digitalWrites were replaced with assembler code (see next post)

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #3 on: April 18, 2015, 11:13:18 AM »
This post covers some design details that wouldn't fit (or too much detail) in the previous post.

Coding Details

As noted in the original post, the digitalWrites were replaced with Assembler code.

The back to back digitalWrites worked, charging the capacitor reliably, but, when examining the signal at the junction of L1, R3, and D1, I discovered that most of the time the voltage was ringing, meaning that there was wasted energy - no charge being pumped into the cap during the ringing.  (See 1st photo below)

Looking at the loop timing, it appeared that the 'tight' C-coded loop was pretty 'loose', taking a little over 27uS to complete one cycle and, during the 'off' phase of Q5, only about 3uS was actually charging the cap.  This told me that the loop needed to be tighter than I could get with the built-in I/O functions. 

I decided that the easiest thing to do was simply switch to assembler during this phase so that I could control the timing more accurately and with shorter cycles.  After some tweaking, I ended up with about 7uS ON, 7uS OFF as the optimum cycle time.  This was longer than the 3uS/3uS cycle I expected from the ringing trace, but taking the longer time to charge the inductor ended up charging the capacitor quicker and resulting in the shortest overall time.  (See 2nd photo below)

Current Consumption

In terms of current drain on the battery, this Mote spends most of it's time sleeping.  It spends 10 minutes sleeping if it's 'idle' (the valve is not ON) and simply reports into the Gateway its status at the end of every 10 minute interval.  Every hour it adds a complete status block which includes its current transmit level and battery voltage. 

Either of these transmissions to the Gateway may trigger the Gateway to reply that effectively says "I've got 'something' for you".   If the Mote is ready to accept the 'something', then it sends a new packet to the Gateway telling it "Ok, give it to me".   Normally1 this would occur when some daemon running on the home server determines that the Valve should be turned on and had sent the command to be forwarded to the sleeping Mote.

When the Mote receives the command to turn on the valve, it sets a timer based on the default time or a time included in the request, opens the valve, and changes its 'sleep' time to 10 seconds and its 'report' interval to one minute.  This prevents the Mote from snoozing through its turn off time and gives the Gateway a shorter window to command the Mote to override its timer and shut off the valve immediately (within one minute, anyway).  During this time, the Mote reports that the valve is open and the time remaining.

When the time is exhausted or overridden, the Mote reverts back to its 'Idle' cycle times.

Net is that MOST of the time, the Mote is operating just a few mS out of 600 seconds or ~0.02% duty cycle.  With its 3300mAH batteries and <20uA sleeping current, the Mote will rot before the batteries run down due to current drain.

So the worst case load is when turning the valve on or off.  As it turns out, the current required is less than what the RFM69HW radio consumes during transmit, however, the power to charge up the cap takes a lot longer than it takes to transmit the periodic status packet (840mS vs 3mS) (see third photo below) so overall current drain is higher.

Looking at the fourth photo below, which measures the current drawn on the battery during the charge/fire cycle, you can see (in the yellow trace) the current drawn over time.  The scale is 1mA/1mV so the peak, right at the beginning, is approximately 61mA, but quickly levels off to about 29mA for the remainder of the cycle.  If this occurred often, the batteries would drain quickly, but it's unlikely that a pair of cycles would occur more than a couple of times a week.  Using a worst case scenario (one ON/OFF cycle per day) the power consumed would be (2 x 840mS/(24hr/day*3600seconds/hr)) * ~38mA = ~74uA average power consumed.  Add the 25uA for sleeping and the occasional transmission, gives us about ~100uA average current drain, or, with 3300mAH batteries, equals about 'ARLT'2 (3.67years), which exceeds my goal of lasting at least one season by 'enough'...

Notes:
1. The 'got something' may alternatively include a request to download a new code update or command to reboot.  The Mote can reject these if it determines that it's too busy (valve is open) or the battery level is too low to reliably download.  Note that this code is NOT included in the example code.  The example simply shows how to control the Valve electronics.
2. 'ARLT': A Really Long Time

That's pretty much it.  Ask questions if you got 'em...

Tom

john4444

  • Jr. Member
  • **
  • Posts: 71
  • Country: us
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #4 on: April 18, 2015, 01:09:27 PM »
Tom, nicely done!
I appreciate that you did things 'good enough' without waisting time/money pushing for 'as good as you could get'. For example: you used the helix antenna (which looks great by the way) instead of trying to seal up a ΒΌ-wave which would have been too large for the enclosure.

Before studying the schematic closely, I was wondering how you swapped the polarity of the "negatively" charged solenoid-capacitor. Your H-bridge delt with that nicely. Also, I think that I would have waisted a lot of time trying to keep the cap charged so that it would trigger the valve right after receiving a on/off signal. Because you don't keep the cap charged, the voltage divider resistors don't drain off your charge and you don't have to keep topping off the cap.

You mentioned that 12-v reliably triggers the solenoid in the valve.
However, I must be mis-reading the scope traces. They appear to show the charge only reaching about 6-v.

Very nice write-up to go with the project.
Thanks for sharing, John
John AE5HQ

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #5 on: April 18, 2015, 01:29:13 PM »
Tom, nicely done!
Thanks!  I appreciate the feedback!
Quote
<snip>
You mentioned that 12-v reliably triggers the solenoid in the valve.
However, I must be mis-reading the scope traces. They appear to show the charge only reaching about 6-v.
<snip>
Good catch!  I failed to mention that as my 5000 byte limit on a posting was quickly approaching!  In fact, after 'talking' to Lukapple, I decided that the example code should include the parameters to set the voltage at 9V for his solenoid as well as 12V for mine.  In the process of messing about with that, I discovered my solenoid works very well at this voltage also (probably the difference between testing with 470uF cap and using a 1000uF cap). 

I didn't include the scope trace that shows the actual voltage measured (it's 9.76V), but you're right that the voltage is slightly more than 6V below ground, but the + side of the cap is referenced to +VBAT (3.2V nominal, 3.45V in this test) making the voltage across the capacitor that much higher.  As a 'bonus', attached below is the 'missing' trace.

Tom

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #6 on: April 18, 2015, 01:50:01 PM »
Tom,
thanks a lot for sharing this beautiful masterpiece with us. And thanks for sketch example that include parameters for 9v pulse.
It's time to order PCB and components for this project.  :D

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #7 on: April 23, 2015, 10:25:35 PM »
Sticky!

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #8 on: August 27, 2015, 05:59:41 AM »
Very nice, Tom!  It looks like you made your own PCB.  If you were so inclined, I think you should sell these as a kit.  You're right: being able to add a valve wherever you want without having to run wire is great.  Also, working on your sprinkler heads is a lot easier and faster if you can control the valve wirelessly!

FWIW, I once did have a battery operating sprinkler valve with a latching solenoid.  It was made by DIG Irigation, but it was purely timer based and had no wireless component.  IIRC, it used either one or two ordinary 9 volt batteries, and that one or two batteries lasted about a year.

Of course, the worst thing would be for the valve to run out of battery while in the open position.  So, I guess you must have a way of determining before you open the valve that your system can guarantee it will also have enough power to close it!


TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #9 on: August 27, 2015, 09:16:06 AM »
Very nice, Tom!  It looks like you made your own PCB.  If you were so inclined, I think you should sell these as a kit.  You're right: being able to add a valve wherever you want without having to run wire is great.  Also, working on your sprinkler heads is a lot easier and faster if you can control the valve wirelessly!
Thanks. They've been working well all Summer long (I've got 4 deployed).  The current version uses my older polling code so I can only change to ON state within a ten minute window.  Once it goes ON, the polling cycle changes to once every minute, but the ON commands are self timed - the polling override is mainly used during testing and sprinkler head setup.  When I get back to my home, I'll update the code to use the ListenMode updates so I can send them commands at any time.
Quote

FWIW, I once did have a battery operating sprinkler valve with a latching solenoid.  It was made by DIG Irigation, but it was purely timer based and had no wireless component.  IIRC, it used either one or two ordinary 9 volt batteries, and that one or two batteries lasted about a year.
Yes, this controller will work with the DIG solenoids.  I'm using Hunter's but made the controller generic enough that the latest version will actually drive the Orbit Expansion Valve (22V, 3A!).  Battery consumption since April has been negligible.  These are running from 2 AA Lithium.

Quote
Of course, the worst thing would be for the valve to run out of battery while in the open position.  So, I guess you must have a way of determining before you open the valve that your system can guarantee it will also have enough power to close it!
Yeah, I anticipated that and won't open the valve if the battery state is marginal.

BTW, the latest version includes a Soil Moisture Sensor so I can monitor moisture at the same point.  I'm not ready to completely close the loop, however.  Too much information goes into the irrigation decision (weather forecast, other moisture sensors, etc) than just localized soil moisture.

Tom
« Last Edit: August 27, 2015, 09:32:21 AM by TomWS »

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #10 on: September 12, 2015, 03:22:35 AM »
Quote
Using a worst case scenario (one ON/OFF cycle per day) the power consumed would be (2 x 840mS/(24hr/day*3600seconds/hr)) * ~38mA = ~74uA average power consumed.

Tom, this is a really cool project - and I will need to build something similar next summer at the latest. A slight inaccuracy in your calculation makes it even more attractive:

Let's look at the worst case of two switches per day again:

2 x 0.840s / (24hr/day * 3600 seconds / hr) * 38mA = 0.74uA !!!

In other words if one had a suitable booster circuit this project could run for years on a CR2032 coin cell in theory. However the current circuit would quickly lead to brown outs with a run down battery.

This is an example of the more general problem of how to use coin cells for sensors that don't work with 2V. There are ultra low voltage boost regulators that look suitable for this kind of application (e.g. http://www.ti.com/lit/ds/symlink/bq25504.pdf). However I don't have enough space on a Tino.

As you found out I think with small inductors it just takes high frequencies to drive a boost converter in continuous mode. So running the 328p at say 128khz for low power consumption would not really work as far as I understand. And with a coin cell you probably need to use a very high duty cycle for the boost switch to harvest only the beginning of the flyback spike - again even higher frequencies needed.

Anyway - food for thought ... Any ideas?
« Last Edit: September 12, 2015, 04:43:34 AM by joelucid »

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #11 on: September 12, 2015, 05:15:55 AM »
Quote
So running the 328p at say 128khz for low power consumption would not really work as far as I understand.

Actually as I look at your 14uS periodicity I guess that would almost be doable with 128khz and fast PWM on the 328p. Run at 256khz to be on the safe side and account for the lower voltage and you'd have very little power waste at the 328p (about 0.2mA).

Of course the other problem is surviving the charging periods voltage wise. Probably use very small charging periods (say 5ms and measure VCC and stop before you drop below 2V). Then let VCC recover and repeat until target voltage reached.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #12 on: September 12, 2015, 08:18:26 AM »
Given the progress we've made with the coin cell motes, it is tempting to look at doing a prototype design just to come up with something that would be useful where it's necessary.  In this particular case, however, I had plenty of room for 2 AA Lithium primary batteries (~15 times more power than a coin cell) and the risk is too great if the battery isn't 'ready' to close an open valve...

I purposefully avoided a separate booster circuit in this case just to prove that the AVR can provide the excitation necessary to boost to 25V 3A pulse.  All I needed (besides the usual collection of inductor, cap, etc) was a couple of FETs.  And you know how much I LOVE using FETs.   ;D

Tom

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #13 on: September 12, 2015, 08:43:31 AM »
This is an example of the more general problem of how to use coin cells for sensors that don't work with 2V. There are ultra low voltage boost regulators that look suitable for this kind of application (e.g. http://www.ti.com/lit/ds/symlink/bq25504.pdf).
...
Anyway - food for thought ... Any ideas?
Yeah, TI has been doing some interesting stuff in energy harvesting.  For a Landscape (or Pond  ;) oriented Mote, this device coupled with a solar cell & super cap would literally work forever without a battery.  Of course, if it is was in a Pond you'd have to periodically clean off green slime and dead fish.

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Moteino Based Battery Operated Sprinkler Valve
« Reply #14 on: September 14, 2015, 05:24:38 AM »
Quote
The risk is too great if the battery isn't 'ready' to close an open valve...

We'll make it work. Just imagine the satisfaction of seeing your sprinkler come on and knowing it was switched on (and will continue to be for the next decade) by a single cr2032. Watering your lawn will never be the same ...