//WaterPlant_Ed2.ino 01/11/2020 12:26:13 #include Servo servomotor1; //833 air //632 water //vars char IncomingValue = 0; const int AirValue = 833; //you need to change this value that you had recorded in the air const int WaterValue = 632; //you need to change this value that you had recorded in the water int intervals = (AirValue - WaterValue) / 3; int soilMoistureValue = 0; int ServoPosition = 1; //1 = original home position, 0 = watering unsigned int igUpdateTime; void setup() { servomotor1.attach(12); servomotor1.write(120);//set @ home position Serial.begin(9600); // open serial port, set the baud rate to 9600 bps igUpdateTime = millis(); } void loop() { //Excute loop every 0.5 minute - if this time interval is changed, the App Timers must be changed too if((millis() - igUpdateTime) > 30000) { igUpdateTime = millis(); if(Serial.available() > 0) { IncomingValue = Serial.read(); if(ServoPosition == 0) { servomotor1.write(120);//original position ServoPosition = 1; } switch (IncomingValue) { case '1': servomotor1.write(0);//watering ServoPosition = 0; break; case 'M': soilMoistureValue = analogRead(A0); Serial.print(soilMoistureValue); Serial.println(); break; } } } }