Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15454

Trying to control a pump with only a button

$
0
0

My skills are ranging from begginer to intermediate.

Im using a one button library in this code to use the button as a switch
what im trying to do is when i press the button it should execute the code below and when i press the button again the loop should break.

any help would be much appreciated.
thank you so much

void Nightshade() {
  int i = 0;
  while (i < 1) {
    SoilMoistureValue = analogRead(A4);  //SM sensor
    SoilMoisturePercent = map(SoilMoistureValue, AirValue, WaterValue, 0, 100);
    Serial.print("Nightshade");
    Serial.println(SoilMoistureValue);
    if (SoilMoisturePercent <= 70) {
      Serial.print(SoilMoisturePercent);
      Serial.print("%");
      digitalWrite(SMrelay, LOW);  //water pump on
      delay(700);
    } else if (SoilMoisturePercent > 70) {
      Serial.print(SoilMoisturePercent);
      Serial.print("%");
      digitalWrite(SMrelay, HIGH);  //water pump off
      delay(700);
    }
    
    Serial.println();
    continue;
  }
}

14 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 15454

Trending Articles