Pump Control with HC-SR04

Continuing the discussion from Subtitute for function pulseIn:

Hi all,

My name is Luc, I'm a total novice in software, but finally starting to test and try some little projects I had in mind for a long time. One of them is control of a feed-pump for a water-tank.
The Tank is filled with a solar-driven 12v pump, and I want to have it run as little as possible and obviously only during daytime hours to save the battery.

I thought best to use the HC-SR04, and found Timb's sample with the digole display:

  • I wanted to use the code to control the level of water, say pump on when reaching a certain level and pump off when reaching 'full' level (this will also help me avoid too much cycling of the pump and if I'd leave it always on with a pressure switch, it would waste a large amount of energy when it's almost full ). I don't have a display available I simply want to measure the water level and be able to use those values to start and stop the pump.

Then there's a later add-on, being:
The shower upstairs is fed by another 12v Pump. running off the same battery and panel. Thing is that I don't want the feed-pump to run when the shower pump is on, as it would be too much a drain on the battery.
So that would mean 2 relays that I hook up, where relay One is normally open (feed-pump not getting 12v) and relay Two (the shower-pump) is normally closed and getting coninuous supply of 12v for on-demand water supply.

So what I see from the code of Timb, I guess I'd take out the Digole display code and then add rules to switch on / off the two relays.

Hope someone can help me with this.

Thanks and regards,
Luc

1 Like

I’m sure exactly what you need though…

Which library or functionality are you looking for? :slight_smile:

Pulsein() function?

You could use a DPDT relay for the shower with one set of contacts controlling the shower pump normally-open and the other set blocking power to the feed-pump normally-closed. That way when the shower pump is on, the feed-pump does not get power.

For the tank level if you don't want the ultrasonic sensor, there are sensors like this:

Or float sensors, or conductive sensors etc. Just look for something safe for drinking water.

1 Like

BKO, thanks for the suggestions, appreciate all the work you put into Spark. Your tutorials are fun to start experimenting…

As for the DPDT relay, good and simple suggestion. Going to look more into that.
Have to find one that can handle 20A, 12v, as that is one of the issues I have (outside battery drain) as these pumps pull a lot. Normal operation is at 7A, but the feed-pump has a 10meter head so it goes up to 15A max.
The charge controller is 20A, so it shuts down automatically if it exceeds that.

But, is it then not easier to use a normal N/C-COM-N/O relay and given that the shower pump is always available, that this one is connected to the NC and COM, where the Feed-Pump is connected to the NO and the same COM?
The relay and Feedpump On signal would then be driven by the Water-Level sensor and a timer to avoid running during night.
To avoid the shower being cut-off when someone is using it, I’d have to put a flow sensor or pressure sensor in that side that blocks the feedpump from switching on during shower use.

I do like to use the HC-SR04 as I already have it here. But if another sensor is better, I’d have to order that.
Only getting the program running… still trying that…no luck so far.

Thanks for your help so far,
Luc

Hello Kenneth,

I’m trying to get the HC-SR04 working.
I’ve read and tried to use the examples in the thread on it, but not having an LCD and being a total beginner, I’m lost so to say.

I’ve tried to follow this example: http://www.instructables.com/file/F1T3TQ2H994BXMB
Where I am hoping that the signal for the LED’s could be used to control relays instead. If that first step is done, I’m half-way there I think. After that it will be to put timer and some logic in there for the spark to decide when which pump gets power.

Thanks and regards,
Luc

Sure if that works out for you! If you have a separate set of contacts, as in DPDT, then you can always make that work.

Use the ultrasonic sensor if you have it--it has the benefit of being non-contact. A couple of points on that from reading the datasheet. It is a 5V device so you may need level shifters, particularly on the trigger. The measurement seems to be time from trigger to start of echo return gives you distance in the way that seems pretty easy. The datasheet said range in cm = uSDelay / 58 so for good sized tank of 1 m in depth time could be between 58us for 1 cm to 5800us (5.8ms) for 1m so you might just want to record the start time of micros() when you send the trigger and then interrupt on the return echo and capture another micros() and use the difference. It is not like you are driving a car around with the sensor and I would think the maximum rate of change of the water level is pretty slow in computer terms.

hello BKO, thanks for the quick reply… I’m going to try to get some examples running first, and from there see if I can get a handle on the coding and how it works.
Will take some time, but I’m slowly figuring it all out. Hope to get more specific questions later.
Thanks and regards,
Luc

I’ve used this float switch on home brewery project before and it worked as expected. You can set it to normally open or closed.

There’s also capacitive liquid sensing. Here’s an Arduino library that a fella wrote. Maybe you could use it as a jump off point. Or use your Spark to trigger events on the arduino?

1 Like