I’m developing an automatic watering system with an Arduino MEGA 2560.
The idea is that one pot at the time gets watered(10 in total). The pump is not strong enough to do more than one valve. Each pot has its own Soil Moister Sensor (Sparkfun), if the thresholdDown is <=300 a valve and 0.5 sec. later the pump will open/run (via relay’s). If the thresholdUp is >= 700 the pump- and valve relay's will switch off.
So far there are no errors in the sketch while compiling and uploading. In fact it works pretty nice. The problem is that the sketch keeps on going and not wait for the first valve to be finished.
I did try [if … else] Controle Structures as well as [Break] and [Continue], but didn’t had luck with these choices.
The idea is:
Messure pot 1, if dry(theresholdDown) --> valve and pump running
wait till it's wet (thresholdUp) --> pump and valve closed, move to pot 2
or
Messure pot 1, if wet (thresholdUp) --> do nothing, move to pot 2
After the last one the loop still may go on (When this works well, I will ad an RTC so it runs at a certain time).
So I do hope if anyone can help me out.
Here is a part of my code, the whole code wil be in the attachment:
void loop(){
// set the relay's
//1st set Soil moisture sensors + relay's
int sensorValue1;
sensorValue1 = analogRead(sensorPin1); //Reads SMSP value.
if (sensorValue1 <= thresholdDown){
digitalWrite(relayPin1, HIGH); //solenoid valve1 open
delay(500); //0.5 sec. delay between valve and pump
digitalWrite(relayPin0, HIGH); //solenoid Pump running
}
//sensorValue1 = analogRead(sensorPin1); //Not necessary
else if (sensorValue1 >= thresholdUp){
digitalWrite(relayPin0, LOW); //solenoid Pump stopped
delay(500); //0.5 sec. delay between valve and pump
digitalWrite(relayPin1, LOW); //solenoid valve1 closed
//digitalWrite(sensorPin1, LOW); //Actief maken natest met aansturing via NPN transistor
}
delay(500); //print value's every 0.5 sec.
sensorValue1 = analogRead(sensorPin1);
Serial.print("sensor1 = " );
Serial.println(sensorValue1);
// end sensor 1
// 2nd set Soil moisture sensors
int sensorValue2;
sensorValue2 = analogRead(sensorPin2); //Reads SMSP value.
if (sensorValue2 <= thresholdDown){
digitalWrite(relayPin2, HIGH); //solenoid valve2 open
delay(500); //0.5 sec. delay between valve and pump
digitalWrite(relayPin0, HIGH); //solenoid Pump running
}
//sensorValue2 = analogRead(sensorPin2); //Not necessary
else if (sensorValue2 >= thresholdUp){
digitalWrite(relayPin0, LOW); //solenoid Pump stopped
delay(500); //0.5 sec. delay between valve and pump
digitalWrite(relayPin2, LOW); //solenoid valve2 closed
}
delay(500); //print value's every 0.5 sec.
sensorValue2 = analogRead(sensorPin2);
Serial.print("sensor2 = " );
Serial.println(sensorValue2);
// end sensor 2
Begin__code_sprinkler_mar10b.ino (6.22 KB)