Tractor intermittent wiper motor control

Hello people, I need help to improve a project that consists of controlling an Auto-Return Wiper Motor for my tractor that adds variable intermittent motor control via a Slide Potentiometer. I am using a small Arduino Nano V3.0 for this.

Basically, how it works is when the Slide Potentiometer is all the way to the left, the wiper motor is working in continuous mode, the further you move the slide Potentiometer to the right, the longer the Intermittent Delay is (set at 10 Seconds Max) .

The problem I have now is when the slide potentiometer is set for longer intermittent delay and I need to activate the wiper motor immediately in continuous mode (ex. blowing snow hitting the windshield fast after going in a corner of a building), it will not engage immediately after I slide the potentiometer all the way to the left, it will wait for the full-time delay to pass before going in continuous mode.

Is there something I can add to my code so that continuous mode is activated as soon as the slide potentiometer is moved to the far left?

You can see it on wokwi.com here:
https://wokwi.com/projects/360461321219183617

and here is my current code


// 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 (10 Seconds Max) 
// The blue LED is to simulate when the Auto Return Wiper Motor would be powered by a 12 V 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 <= 1) { // Determine the minimum potentiometer position before intermittent wipers is activated
   	interval = 0; }
    
        else interval = (1 + (sensorValue * 9)); // Determine the maximum intermittent seconds
         
     //Serial.println(interval);
     //Serial.println(sensorValue);
    digitalWrite(motorPin,LOW);
    digitalWrite(LED_BUILTIN, HIGH);
    delay (200); // Pulse the motor to move wiper arm to deactivate the Hall Effect Sensor
    digitalWrite(motorPin, HIGH);
    digitalWrite(LED_BUILTIN, LOW);   
    delay (interval); 

    }
    
    

Any help would be appreciated

Cheers,

Grab pen and paper and note what this is doing. At maximum the reading is 1023. Time 9 it's 9027, 9 seconds, + one. During that time (delay(interval) the execution is suspended and the pot/slider is not read. Expect a 9 second delay when changing to direct action.

I understand, but is there something that can be added before the loop?
or what I need to accomplish is impossible because it is in a loop and has to go through the delay...

Any way to do what I want with a different code?
Novice in coding Arduino...

Thanks

You can replace the delay with a millis() based timer. The response is not delayed when moving the slider left.

// 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 (10 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 <= 1) { // Determine the minimum potentiometer position before intemittent wiper is activated
    interval = 0;
  }

  else interval = (1 + (sensorValue * 9)); // Determine the maximum intermittent 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 (200); // Pulse the motor to move wiper arm to deactivate the Hall Effect Sensor
    digitalWrite(motorPin, HIGH);
    digitalWrite(LED_BUILTIN, LOW);
    //delay (interval);
  }

}


1 Like

Don't delay the entire loop and the slider reading! Just delay the wiper action!
Use millis() to decide. Look for the topic "Blink without delay"!
The Search Forum up to the right in this window should be tried.

Thanks, that work now as expected.

https://wokwi.com/projects/360461321219183617

Cheers

Use a push button or foot switch to override the timer, pulse the motor, then reset the timer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.