如何在Arduino中安装10秒持续时间和1分钟间隔带电磁阀&土壤湿度传感器?

时间:2014-10-09 18:21:57

标签: arduino sensor

所以我有这个项目,这是一个自动喷水器,我使用电磁阀控制水,由arduino和土壤湿度传感器控制。代码正在工作,直到我把while条件放在else子句上并添加了延迟。我必须在水喷洒中持续10秒,并且在水再次流动之前间隔1分钟,直到传感器达到所需的水分。 Pleeeease看看。

const int soil_moisture_sensor = A0;
int ledPin_Red = 13;
int ledPin_Green = 12;


void setup(){
  Serial.begin(9600);
  pinMode(ledPin_Red, OUTPUT);
  pinMode(ledPin_Green, OUTPUT);

}

void loop() {
int soil_moisture_level = analogRead(soil_moisture_sensor);
  if (soil_moisture_level <=560 && soil_moisture_level <=700 ) {
           digitalWrite(ledPin_Red, LOW);//when the water is enough 
               digitalWrite(ledPin_Green, HIGH);//GREEN LED Lights up
        Serial.println("water is enough!");
            }

    else if (soil_moisture_level <=360 && soil_moisture_level > 360 && soil_moisture_level <= 560) {
        digitalWrite(ledPin_Red, HIGH);// LED RED lights up
                digitalWrite(ledPin_Green, LOW);
                Serial.println("the water is half full!");
                            }
    else {
             while (soil_moisture_level > 700)
              {
                  digitalWrite(ledPin_Red, HIGH);//LED RED on
                  delay(10000);//10 secs on of red led
                  digitalWrite(ledPin_Red, LOW);//LED RED off
                  delay(60000);//60 secs or 1 min interval
                  digitalWrite(ledPin_Green, LOW);
                  Serial.println("no more water");
              }
         }
        delay(2000); //2000 ms = 2 secs
}

非常感谢您的帮助! thaaaaanks! :d

1 个答案:

答案 0 :(得分:0)

看起来你的比较器倒退了。应该是soil_moisture_level&lt; 700