/* StartDC */ int DC = 9; // the PWM pin the DC motor is attached to int Sensor = A5; // the Analog Read pin to which the sensor is attached int MoistureRead; // sensor value read int MoistureValue; // calculated RH value from calibration const int CriticalLO = 60; // critical RH percentage to start the pump void setup() { pinMode(DC, OUTPUT); pinMode(Sensor, INPUT); MoistureValue=70; // initial value Serial.begin(9600); } void loop() { MoistureRead = analogRead(Sensor); // read when wet MoistureValue = (798-MoistureRead)/3.75; // values from calibration: 798=air, 424=water Serial.println(MoistureValue); while (MoistureValue < CriticalLO){ analogWrite(DC, 70); delay(1000); MoistureRead = analogRead(Sensor); // read when dry MoistureValue = (798-MoistureRead)/3.75; Serial.println(MoistureValue); } analogWrite(DC, 0); delay(1000); }