How can I make my SensorValue value update automatically? I am trying to make the SensorValue variable update itself if the condition of SensorValue < Maxdryness or SensorValue >= Maxdryness is false at any time. I want to be able to switch my moisture sensor between dry and wet soil and make it turn my motor on or off as needed automatically.
if(incomingData.indexOf("Auto on")>=0) // if received command is to turn system automatic
{
auto_flag = 1;
message1 = "System is now automatic";
send_message(message1); // Send a sms back to confirm that the motor is turned auto
if (readSoil() >= Maxdryness)
{
Serial.println("Soil is good.\r");
digitalWrite(wetSoil, HIGH);
digitalWrite (drySoil, LOW);
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,LOW);
delay(1000);
}
else
{
Serial.println("Low Soil Moisture detected.\r");
digitalWrite(wetSoil, LOW);
digitalWrite (drySoil, HIGH);
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,LOW);
}
delay(1000);
Serial.print("Soil Moisture = ");
Serial.println(readSoil());
delay(1000);//take a reading every second
auto_flag = 0;
}
My project involves sending SMS to turn the system on or off manually, Motor on, Motor off but I wanted an option to make the system run by itself without having to manually turn the motor on or off myself. Hence Auto on. This auto can be turned off by Auto off. I don't know how to make the system run while on Auto on to turn the motor off by switching my soil moisture probe from the dry soil into the wet soil and vice versa from wet to dry and turning the motor on. If the condition of SensorValue is >= Maxdryness I want it to stop and only turn on when the value is < the Maxdryness.