hi
i have this code for watering system
if ((output_value < 40)&&(output_value > 70))
which i have looked up on the forum
it would like to look at sensor and if its 40 to turn valve on which it does and then turns off again ,i would like it to keep on untill sensor is 70 ,not sure if this code would do that, i think it will but then if it reaches 70 i dont want it to come back on again untill its at 40 again thats the problem im having,basically it will give the plants a good soaking and then not turn back on until they are dry again
int sensor_pin = A0 ;
int output_value = 0;//changed
int valve_pin = 8 ;//relay
void setup ( ) {
Serial.begin(9600);//changed
Serial.print ("Reading From the " );
Serial.print (" Moisture = ");
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print ("Reading From the " );
lcd.setCursor(0, 1);
pinMode (valve_pin, OUTPUT);
delay (2000);
}
void loop ( ) {
output_value = analogRead (sensor_pin);
output_value = map (output_value , 1023 ,0 , 0 , 170);
lcd.clear ( );
lcd.setCursor (0, 0);
lcd.print (" Moisture = ");
lcd.print (output_value);
lcd.setCursor (0, 1);
//if (output_value < 40)//changed
if ((output_value < 40)&&(output_value > 70))//changed
{
lcd.print (" Valve: ON ");
digitalWrite(6, HIGH); //green
digitalWrite(7, LOW); //red
digitalWrite (valve_pin , LOW); //Relay operates on opposite signal
delay (1000);
}
else
{
if (output_value > 70)//changed
lcd.print (" Valve: OFF ");
digitalWrite(6, LOW); //green
digitalWrite(7, HIGH); //red
digitalWrite (valve_pin , HIGH); //Relay operates on opposite signal
delay (1000);
}
delay(1000);
}
i had thought maybe about having a variable for a low_ output_value =40 and a variable for high_output_value =70 still not sure if this will work ,ive done bit of programming over the years with if then else statements but pretty lost with arduino ide any help would be most welcome
colin