Hi,bros
im trying to make auto irrigation code without delay (and also LCDless) by using 'millis()' .
Components are
-
solenoide valve connected with relay.
-
soil moisture sensor.
-
arduino uno r3.
proto type is as follows.
//pre-
int SMS = A0; // soil moisture sensor
int relay = 10; // relay
unsigned long t2 = 0; // previous time
const long delaytime = 30000; // target time
//setup
void setup ()
{
pinMode(relay, OUTPUT);
Serial.begin (9600);
}
//loop
void loop ()
{
unsigned long t1 = millis(); // current time
float output = analogRead(SMS);
float BP = 100; // base point water content
Serial.println(output);
Serial.println(BP);
delay(1000);
if (t1 - t2 >= delaytime)
{
if (output < BP)
{
digitalWrite(relay, HIGH);
}
else
{
digitalWrite(relay, LOW);
}
t2 = t1;
}
}
but... it doesn't work thoughtfully and needs improvement.
purpose of this code is
-
To provide sufficient water for a fixed time. (like 30000ms above)
for a long-term experiment, to keep plants from dying in hot weather. -
Could i inversion if (output < BP) to if (t1 - t2 >= delaytime) ?
coz i think irrigation is most important part of this code. -
If the soil moisture rises, I want to watering it for a fixed time.
but now , when soil moisture increases, it stops in a short time.
if bros has some better way to make those things better, plz give me some advices.
thx