// This simulation is to add intermittent control to an Auto Return wiper motor for a tractor.
// When the Slide Potentiometer is all the way to the left, wiper motor is in continuous mode.
// The further you move the slide Potentiometer to the right, the longer the Intermittent Delay is (20 Seconds Max)
// The blue LED is to simulate when the Auto Return Wiper Motor would powered by a 12V source
int sensorPin = A1; // Delay Slider Potentiometer
int motorPin = 2; // To Wiper Relay
int interval = 0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(motorPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
if (sensorValue <= 4) { // Determine the minimum potentiometer position before intemittent wiper is activated
interval = 0;
}
else interval = (2000 + (sensorValue * 18)); // 2000 is the time for a complete wipe, sensorValue determine the maximum intermittent in seconds
static unsigned long lastTime = 0;
if (millis() - lastTime >= interval)
{
lastTime = millis();
//Serial.println(interval);
//Serial.println(sensorValue);
digitalWrite(motorPin, LOW);
digitalWrite(LED_BUILTIN, HIGH);
delay (400); // Pulse the motor to activate auto-return
digitalWrite(motorPin, HIGH);
digitalWrite(LED_BUILTIN, LOW);
}
}