#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; unsigned int igUpdateTime; void setup() { servomotor1.attach(12); Serial.begin(9600); // open serial port, set the baud rate to 9600 bps igUpdateTime = millis(); } void loop() { //Excute loop every 10 seconds if((millis() - igUpdateTime) > 10000) { igUpdateTime = millis(); if(Serial.available() > 0) { IncomingValue = Serial.read(); switch (IncomingValue) { case '1': servomotor1.write(0);//watering break; case '0': servomotor1.write(120);//original position break; case 'M': soilMoistureValue = analogRead(A0); Serial.print(soilMoistureValue); Serial.println(); break; } } } }