I should start by saying im not a programmer, will be obvious when you look at the code I guess.
im making a pump controller with a source container and three containers that get filled from the source.
I made water level sensors from for the containers.
i want the pumps to run if the containers are empty but only if the source container has water in it.
this works fine if the source is already empty when I start the arduino up but if the pumps are running while the source empties they keep running.
here is the code.
//three pumps controlled by relays
//three fans controlled by pwm tip120
//four water level sensors
//----------------------------------------------
//WATER LEVEL SENSORS
//EATCH SENSOR HAS THREE WIRES, TWO LEVELS AND A 5V INPUT.
// water level sensor 1, has two A-inputs
// controlles pump 1
int levelSensor1Low = A0;
int levelSensor1HIGH = A1;
// water level sensor 2, has two A-inputs
// controlles pump 2
int levelSensor2Low = A2;
int levelSensor2HIGH = A3;
// water level sensor 3, has two A-inputs
// controlles pump 3
int levelSensor3Low = A4;
int levelSensor3HIGH = A5;
// water level sensor 4, has two A-inputs
// indicates if source water container is empty
int levelSensor4Low = A6;
int levelSensor4HIGH = A7;
int wls1L;
int wls1H;
int wls2L;
int wls2H;
int wls3L;
int wls3H;
int wls4L;
int wls4H;
int z=90; // If circuit is not displaying correct digit then adjust this value from 100 to 1023 .
//----------------------------------------------
//FANS
// blows on sculpture 1
int fan1 = 5;
// blows on sculpture 2
int fan2 = 6;
// blows on sculpture 3
int fan3 = 7;
//----------------------------------------------
//PUMPS
// fills vaporicer container at sculpture 1
int pump1 = 30;
// fills vaporicer container at sculpture 2
int pump2 = 31;
// fills vaporicer container at sculpture 3
int pump3 = 32;
void setup() {
// put your setup code here, to run once:
pinMode(levelSensor1Low,INPUT);
pinMode(levelSensor1HIGH,INPUT);
pinMode(levelSensor2Low,INPUT);
pinMode(levelSensor2HIGH,INPUT);
pinMode(levelSensor3Low,INPUT);
pinMode(levelSensor3HIGH,INPUT);
pinMode(levelSensor4Low,INPUT);
pinMode(levelSensor4HIGH,INPUT); // defining input pins
pinMode( pump1, OUTPUT);
pinMode( pump2, OUTPUT);
pinMode( pump3, OUTPUT);
pinMode( fan1, OUTPUT);
pinMode( fan2, OUTPUT);
pinMode( fan3, OUTPUT); // defining output pins
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// Read the state of all the water level sensors
wls1L=analogRead(levelSensor1Low);
wls1H=analogRead(levelSensor1HIGH);
wls2L=analogRead(levelSensor2Low);
wls2H=analogRead(levelSensor2HIGH);
wls3L=analogRead(levelSensor3Low);
wls3H=analogRead(levelSensor3HIGH);
wls4L=analogRead(levelSensor4Low);
wls4H=analogRead(levelSensor4HIGH);
//if source container is empty
if(wls4L<z && wls4H<z)
{
// pumps wont run
// indicator turns on
Serial.println("source container is empty");
delay (1000);
// serial info
}
else
{
//----------------------------------------------
if(wls1L<z && wls1H<z) // if container 1 is empty fill it
{
// run pump 1
digitalWrite(pump1, HIGH);
}
if(wls1L>z && wls1H>z) // if container 1 is full stop pumping
{
// stop pump 1
digitalWrite(pump1, LOW);
}
//----------------------------------------------
if(wls2L<z && wls2H<z) // if container 2 is empty fill it
{
// run pump 2
digitalWrite(pump2, HIGH);
}
if(wls2L>z && wls2H>z) // if container 2 is full stop pumping
{
// stop pump 2
digitalWrite(pump2, LOW);
}
//----------------------------------------------
if(wls3L<z && wls3H<z) // if container 3 is empty fill it
{
// run pump 3
digitalWrite(pump3, HIGH);
}
if(wls3L>z && wls3H>z) // if container 3 is full stop pumping
{
// stop pump 3
digitalWrite(pump3, LOW);
}
//----------------------------------------------
// serial info
Serial.println("WL-sensor1");
Serial.println(wls1L);
Serial.println(wls1H);
Serial.println("WL-sensor2");
Serial.println(wls2L);
Serial.println(wls2H);
Serial.println("WL-sensor3");
Serial.println(wls3L);
Serial.println(wls3H);
Serial.println("WL-sensor4");
Serial.println(wls4L);
Serial.println(wls4H);
delay(1000);
}
}
any ideas on how to solve this? thanks in advance.
fixed it.
//three pumps controlled by relays
//three fans controlled by pwm tip120
//four water level sensors
//----------------------------------------------
//WATER LEVEL SENSORS
//EATCH SENSOR HAS THREE WIRES, TWO LEVELS AND A 5V INPUT.
// water level sensor 1, has two A-inputs
// controlles pump 1
int levelSensor1Low = A0;
int levelSensor1HIGH = A1;
// water level sensor 2, has two A-inputs
// controlles pump 2
int levelSensor2Low = A2;
int levelSensor2HIGH = A3;
// water level sensor 3, has two A-inputs
// controlles pump 3
int levelSensor3Low = A4;
int levelSensor3HIGH = A5;
// water level sensor 4, has two A-inputs
// indicates if source water container is empty
int levelSensor4Low = A6;
int levelSensor4HIGH = A7;
int wls1L;
int wls1H;
int wls2L;
int wls2H;
int wls3L;
int wls3H;
int wls4L;
int wls4H;
int z=90; // If circuit is not displaying correct digit then adjust this value from 100 to 1023.
int k=0;
//----------------------------------------------
//FANS
// blows on sculpture 1
int fan1 = 5;
// blows on sculpture 2
int fan2 = 6;
// blows on sculpture 3
int fan3 = 7;
//----------------------------------------------
//PUMPS
// fills vaporicer container at sculpture 1
int pump1 = 30;
// fills vaporicer container at sculpture 2
int pump2 = 31;
// fills vaporicer container at sculpture 3
int pump3 = 32;
void setup() {
// put your setup code here, to run once:
pinMode(levelSensor1Low,INPUT);
pinMode(levelSensor1HIGH,INPUT);
pinMode(levelSensor2Low,INPUT);
pinMode(levelSensor2HIGH,INPUT);
pinMode(levelSensor3Low,INPUT);
pinMode(levelSensor3HIGH,INPUT);
pinMode(levelSensor4Low,INPUT);
pinMode(levelSensor4HIGH,INPUT); // defining input pins
pinMode( pump1, OUTPUT);
pinMode( pump2, OUTPUT);
pinMode( pump3, OUTPUT);
pinMode( fan1, OUTPUT);
pinMode( fan2, OUTPUT);
pinMode( fan3, OUTPUT); // defining output pins
Serial.begin(9600);
}
void loop() {
k=0;
// put your main code here, to run repeatedly:
// Read the state of all the water level sensors
wls1L=analogRead(levelSensor1Low);
wls1H=analogRead(levelSensor1HIGH);
wls2L=analogRead(levelSensor2Low);
wls2H=analogRead(levelSensor2HIGH);
wls3L=analogRead(levelSensor3Low);
wls3H=analogRead(levelSensor3HIGH);
wls4L=analogRead(levelSensor4Low);
wls4H=analogRead(levelSensor4HIGH);
//if source container is empty
if(wls4L<z && wls4H<z)
{
// pumps wont run
// indicator turns on
Serial.println("source container is empty");
k=1;
delay (1000);
// serial info
}
//----------------------------------------------
if(wls1L<z && wls1H<z && k<1) // if container 1 is empty fill it
{
// run pump 1
digitalWrite(pump1, HIGH);
}
if(wls1L>z && wls1H>z || k==1) // if container 1 is full stop pumping
{
// stop pump 1
digitalWrite(pump1, LOW);
}
//----------------------------------------------
if(wls2L<z && wls2H<z && k<1) // if container 2 is empty fill it
{
// run pump 2
digitalWrite(pump2, HIGH);
}
if(wls2L>z && wls2H>z || k==1) // if container 2 is full stop pumping
{
// stop pump 2
digitalWrite(pump2, LOW);
}
//----------------------------------------------
if(wls3L<z && wls3H<z && k<1) // if container 3 is empty fill it
{
// run pump 3
digitalWrite(pump3, HIGH);
}
if(wls3L>z && wls3H>z || k==1) // if container 3 is full stop pumping
{
// stop pump 3
digitalWrite(pump3, LOW);
}
//----------------------------------------------
// serial info
Serial.println("WL-sensor1");
Serial.println(wls1L);
Serial.println(wls1H);
Serial.println("WL-sensor2");
Serial.println(wls2L);
Serial.println(wls2H);
Serial.println("WL-sensor3");
Serial.println(wls3L);
Serial.println(wls3H);
Serial.println("WL-sensor4");
Serial.println(wls4L);
Serial.println(wls4H);
Serial.println("k");
Serial.println(k);
delay(1000);
}
added another int that changes if the source is empty. hope this helps anyone...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.