#include <Servo.h>
//Define the pins used for input and output
const int AnPin = A0;
const int WiperPin = 7;
//Define the constants used
const int WetnessLimit = 50;
//Create servo object to control a servo
Servo Wiper;
//Define the variables used
int SensorReading;
int Wetness;
int WiperTimer;
void setup() {
Wiper.attach(WiperPin);
//Start serial communication
Serial.begin(9600);
}
void loop() {
//Read the sensors output
SensorReading = analogRead(AnPin);
Wetness = map(SensorReading, 0, 1024, 100, 0);
//Print the value to the computer
Serial.println(Wetness);
if (Wetness >= WetnessLimit) {
Wiper.write(180);
delay(500);
Wiper.write(0);
delay(1000);
exit(0);
}
else (Wetness <= WetnessLimit); {
Wiper.write(0);
}
//Add a delay bewteen readings.
delay(1000);
}