Go Down

Topic: Stay off till some point. Answered....thanks guys (Read 961 times) previous topic - next topic

SAButter

Jan 29, 2013, 06:08 pm Last Edit: Jan 30, 2013, 02:27 am by SAButter Reason: 1
I wanting to upgrade my spring water treatment system for my house. The way the system works now is spring water is constantly being filtered and sterilized then dumped into a 1,600 gallon tank. As the tank fills up the water overflows out a drain. What I'm wanting to do is have the tank completely filled then a solenoid shut off the water till the level drops below say %50 and then open the solenoid to fill it again.

I have a 7-seg water level indicator driven by a nano and ultrasonic Rx/Tx that's on the tank now and works great. I just have no idea how to set a output to come on till some point and then stay off till some other point.

If some one can point me in a direction I would appreciate it
Thanks 

wildbill

A couple of if statements in loop should do it, based on whatever the depth sensor is telling you. Post the code you have so far.

SAButter

#2
Jan 29, 2013, 06:21 pm Last Edit: Jan 29, 2013, 06:23 pm by SAButter Reason: 1
lol I never thought of that. Keep this in mind I'm only using one 6" display for the level indicator.

Code: [Select]
#include <NewPing.h>

#define TRIGGER_PIN  5  // digital output #3 Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     4  // digital Output #2 Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

int gPin = 12;                
int bPin = 11;                
int dPin = 10;                
int ePin = 9;               // 7 seg display  
int cPin = 8;                
int aPin = 7;                
int fPin = 6;                


void setup() {
 Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
 
 pinMode(aPin, OUTPUT);        // sets the digital pin as output on 7 seg display
 pinMode(bPin, OUTPUT);        
 pinMode(cPin, OUTPUT);        
 pinMode(dPin, OUTPUT);        
 pinMode(ePin, OUTPUT);        
 pinMode(fPin, OUTPUT);
 pinMode(gPin, OUTPUT);
}

void loop() {
 delay(200);                      // Wait 200ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 
 unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).

 Serial.print(uS / US_ROUNDTRIP_IN); // Convert ping time to distance in inch "IN" or "CM" and print result
 Serial.println();                   // prints to monitor
 
 int val = (uS / US_ROUNDTRIP_IN); //
 
 if(val > 01 && val < 10)         // decimal 0 on display
 {
 digitalWrite(aPin, LOW);        
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, LOW);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, HIGH);
 }
 else if (val > 11 && val < 20)   // decimal 1 on display
 {
 digitalWrite(aPin, HIGH);        
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, HIGH);
 }
 else if (val > 21 && val < 30)   // decimal 2 on display
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, LOW);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, LOW);
 }
 else if (val > 31 && val < 40)
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, LOW);
 }
 else if (val > 41 && val < 50)
 {
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
 }
 else if (val > 51 && val < 60)
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
 }
 else if (val > 61 && val < 70)
 {
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, LOW);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
 }
 else if (val > 71 && val < 80)
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, HIGH);
 }
 else if (val > 81 && val < 90)
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, LOW);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
 }
 else if (val > 91)
 {
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
 }
}


ash901226

urm i dont knw if the return is in analog value or digital value but my example should apply to your application what so ever
ok
first you should know how high the water is now,
then you need to set how high the water should be at its highest
then you should set how low the water could be b4 the water should be filling in to the tank

then it would be as a simple as
(return digital Value)
if (WaterNow==SetHighPoint)then shut valve;
if (WaterNow==SetLowPoint)then open valve;


(return analog value)
if (WaterNow(what analog value that you get for the sensor) is >= SetHighPoint(this is where you set the value of max water level)then shut valve ;
if (WaterNow is <= SetLowPoint(set the minimum value of water) ) then open valve;



this should point you to the rite direction

SAButter


(return digital Value)
if (WaterNow==SetHighPoint)then shut valve;
if (WaterNow==SetLowPoint)then open valve;

That might work I'll have to try it thanks

wildbill

Use >= and <= tests, not ==. Otherwise you may miss the crucial measurement and drain your cistern. Make sure that the set points are far enough apart that the solenoid isn't in any danger of being rapidly cycled - although it sounds like you already have this under control.

LarryD

As a side issue, when it comes to important stuff like flooding etc. you should have a backup circuit.
Something like a float/limit switch independant of your controller.
It would provide a cutoff to the filling of the tank at an extreme level.
The way you have it in your schematic isn't the same as how you have it wired up!

ash901226

SAButter you need to use my second hint not the first since it return a value not just high and low...

SAButter

I see the differences in the two now.

Yea the wife and kids would not be happy if the discovered one morning they were out of water.
Thanks guys

PaulS

Quote
Yea the wife and kids would not be happy if the discovered one morning they were out of water.

Even worse would be to be knee-deep in it.

PeterH


What I'm wanting to do is have the tank completely filled then a solenoid shut off the water till the level drops below say %50 and then open the solenoid to fill it again.


Surely a float valve with some hysteresis is all you need here? I don't see any need for it to be controlled electrically never mind electronically, from what you've described so far.
I only provide help via the forum - please do not contact me for private consultancy.

SAButter

#11
Jan 30, 2013, 02:32 am Last Edit: Jan 30, 2013, 02:49 am by SAButter Reason: 1


What I'm wanting to do is have the tank completely filled then a solenoid shut off the water till the level drops below say %50 and then open the solenoid to fill it again.


Surely a float valve with some hysteresis is all you need here? I don't see any need for it to be controlled electrically never mind electronically, from what you've described so far.


There is two reasons why it's electric/electronic. One reason is I have a solenoid in the water circuit so if i loose power for some reason or the UV bulb burns out it will cut the water off filling the tank. I have a photo cell in the UV filter housing if the bulb goes out the water gets cut if not I'm dumping unsanitized water into my tank. The other reason it's electronic is the tank is in a water shed 80 yards up over the house on the hill. In the summer time when it's dry and the spring not producing good or not at all. I have to walk up and check it every day but with the 7 seg display I can just look up and see what the tank level is. If it gets low I have to start haling it in.

Go Up