Window wiper control

Hello,

I looking to control the window wiper motor using the standard wiper stalk but i cannot use the factory wiring because most of it is missing, I've got google to generate most of the code and just want someone to look over it and give any advise,

const int intermittentButtonPin = 2; // Button for intermittent mode
const int lowSpeedButtonPin = 3; // Button for low speed
const int mediumSpeedButtonPin = 4; // Button for medium speed
const int highSpeedButtonPin = 5; // Button for high speed
const int potPin = 6; // Potentiometer pin for intermittent interval control
const int wiperPin = 9; // Wiper motor control pin
const int washerButtonPin = 10; // Button for washer activation
const int parkSignalPin = 11; // Park signal pin from wiper motor

int wiperState = 0; // 0: Park, 1: Off, 2: Intermittent (potentiometer), 3: Low, 4: Medium, 5: High
int intermittentTimer = 0; // Timer for intermittent wiper delay
int washerTimer = 0; // Timer for washer function duration

void setup() { 
  pinMode(intermittentButtonPin, INPUT_PULLUP);
  pinMode(lowSpeedButtonPin, INPUT_PULLUP);
  pinMode(mediumSpeedButtonPin, INPUT_PULLUP);
  pinMode(highSpeedButtonPin, INPUT_PULLUP);
  pinMode(potPin, INPUT);
  pinMode(wiperPin, OUTPUT);
  pinMode(washerButtonPin, INPUT_PULLUP);
  pinMode(parkSignalPin, INPUT);
}

void loop() {
  // Read button states
  int intermittentButtonState = digitalRead(intermittentButtonPin);
  int lowSpeedButtonState = digitalRead(lowSpeedButtonPin);
  int mediumSpeedButtonState = digitalRead(mediumSpeedButtonPin);
  int highSpeedButtonState = digitalRead(highSpeedButtonPin);

  // Update wiper state based on button presses
  if (intermittentButtonState == LOW) {
    wiperState = 2; // Intermittent (potentiometer)
  } else if (lowSpeedButtonState == LOW) {
    wiperState = 3; // Low speed
  } else if (mediumSpeedButtonState == LOW) {
    wiperState = 4; // Medium speed
  } else if (highSpeedButtonState == LOW) {
    wiperState = 5; // High speed
  } else if (wiperState == 0) { // Wiper off
    digitalWrite(wiperPin, LOW);
  }

  // Read washer button state and activate washer function
  int washerButtonState = digitalRead(washerButtonPin);
  if (washerButtonState == LOW) {
    washerTimer = millis();
    wiperState = 5; // Activate high speed wipers during washer
  } else if (millis() - washerTimer > 2000) { // Washer duration (2 seconds)
    wiperState = 0; // Turn wipers off after washer duration
  }

  // Read park signal and activate parking if not already parked
  int parkSignal = digitalRead(parkSignalPin);
  if (parkSignal == HIGH && wiperState != 0) {
    wiperState = 0; // Set wiper state to park
    // ... (optional: additional logic for park position control)
  }

  // Control wiper motor based on state
  switch (wiperState) {
    case 1: // Off
      digitalWrite(wiperPin, LOW);
      break;
    case 2: // Intermittent (potentiometer)
      { // Block for intermittent case
        int potValue = analogRead(potPin);
        int delayTime = map(potValue, 0, 1023, 1000, 10000);

        if (millis() - intermittentTimer > delayTime) {
          digitalWrite(wiperPin, HIGH);
          intermittentTimer = millis();
        } else if (millis() - intermittentTimer > delayTime / 2) {
          digitalWrite(wiperPin, LOW);
        }
      }
      break;
    case 3: // Low speed
      analogWrite(wiperPin, 50); // Set PWM duty cycle for low speed
      break;
    case 4: // Medium speed
      analogWrite(wiperPin, 150); // Set PWM duty cycle for medium speed
      break;
    case 5: // High speed
      analogWrite(wiperPin, 255); // Set PWM duty cycle for high speed
      break;
    case 0: // Park
      // ... (optional park logic)
      digitalWrite(wiperPin, LOW); // Stop wiper motor
      break;
  }
} // Closing curly brace for loop()

here is the pinout of the wiper stalk

Draw a diagram showing which arduino pins connect to which wires in that wiring diagram.

1 Like

What happens when you run it?

Your potentiometer should be on an Analog Input (Uno/Nano A0 - A5).

If you can make the LO/MD/HI buttons to work, when you push LOW, MED, HI, the WIPER motor starts once, but pushing LOW, MED, HI buttons again does nothing.

INTERMITTENT does nothing (a button-press issue).

PARK button disables all buttons, then enables all buttons.

To simulate on WOKWI.COM...

sketch
const int intermittentButtonPin = 2; // Button for intermittent mode
const int lowSpeedButtonPin = 3; // Button for low speed
const int mediumSpeedButtonPin = 4; // Button for medium speed
const int highSpeedButtonPin = 5; // Button for high speed
const int potPin = A0; // 6; // Potentiometer pin for intermittent interval control
const int wiperPin = 9; // Wiper motor control pin
const int washerButtonPin = 10; // Button for washer activation
const int parkSignalPin = 11; // Park signal pin from wiper motor

int wiperState = 0; // 0: Park, 1: Off, 2: Intermittent (potentiometer), 3: Low, 4: Medium, 5: High
int intermittentTimer = 0; // Timer for intermittent wiper delay
int washerTimer = 0; // Timer for washer function duration

void setup() {
  pinMode(intermittentButtonPin, INPUT_PULLUP);
  pinMode(lowSpeedButtonPin, INPUT_PULLUP);
  pinMode(mediumSpeedButtonPin, INPUT_PULLUP);
  pinMode(highSpeedButtonPin, INPUT_PULLUP);
  pinMode(potPin, INPUT);
  pinMode(wiperPin, OUTPUT);
  pinMode(washerButtonPin, INPUT_PULLUP);
  pinMode(parkSignalPin, INPUT);
}

void loop() {
  // Read button states
  int intermittentButtonState = digitalRead(intermittentButtonPin);
  int lowSpeedButtonState = digitalRead(lowSpeedButtonPin);
  int mediumSpeedButtonState = digitalRead(mediumSpeedButtonPin);
  int highSpeedButtonState = digitalRead(highSpeedButtonPin);

  // Update wiper state based on button presses
  if (intermittentButtonState == LOW) {
    wiperState = 2; // Intermittent (potentiometer)
  } else if (lowSpeedButtonState == LOW) {
    wiperState = 3; // Low speed
  } else if (mediumSpeedButtonState == LOW) {
    wiperState = 4; // Medium speed
  } else if (highSpeedButtonState == LOW) {
    wiperState = 5; // High speed
  } else if (wiperState == 0) { // Wiper off
    digitalWrite(wiperPin, LOW);
  }

  // Read washer button state and activate washer function
  int washerButtonState = digitalRead(washerButtonPin);
  if (washerButtonState == LOW) {
    washerTimer = millis();
    wiperState = 5; // Activate high speed wipers during washer
  } else if (millis() - washerTimer > 2000) { // Washer duration (2 seconds)
    wiperState = 0; // Turn wipers off after washer duration
  }

  // Read park signal and activate parking if not already parked
  int parkSignal = digitalRead(parkSignalPin);
  if (parkSignal == HIGH && wiperState != 0) {
    wiperState = 0; // Set wiper state to park
    // ... (optional: additional logic for park position control)
  }

  // Control wiper motor based on state
  switch (wiperState) {
    case 1: // Off
      digitalWrite(wiperPin, LOW);
      break;
    case 2: // Intermittent (potentiometer)
      { // Block for intermittent case
        int potValue = analogRead(potPin);
        int delayTime = map(potValue, 0, 1023, 1000, 10000);

        if (millis() - intermittentTimer > delayTime) {
          digitalWrite(wiperPin, HIGH);
          intermittentTimer = millis();
        } else if (millis() - intermittentTimer > delayTime / 2) {
          digitalWrite(wiperPin, LOW);
        }
      }
      break;
    case 3: // Low speed
      analogWrite(wiperPin, 50); // Set PWM duty cycle for low speed
      break;
    case 4: // Medium speed
      analogWrite(wiperPin, 150); // Set PWM duty cycle for medium speed
      break;
    case 5: // High speed
      analogWrite(wiperPin, 255); // Set PWM duty cycle for high speed
      break;
    case 0: // Park
      // ... (optional park logic)
      digitalWrite(wiperPin, LOW); // Stop wiper motor
      break;
  }
} // Closing curly brace for loop()
diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -205,
      "left": 172.8,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn2",
      "top": -157,
      "left": 172.8,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn3",
      "top": -109,
      "left": 172.8,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn4",
      "top": -61,
      "left": 172.8,
      "attrs": { "color": "green" }
    },
    { "type": "wokwi-potentiometer", "id": "pot1", "top": -1.3, "left": 182.2, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn5",
      "top": -166.6,
      "left": -48,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": -224.4,
      "left": -53.8,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo1",
      "top": -57.6,
      "left": 249.6,
      "attrs": { "text": "INT" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo2",
      "top": -105.6,
      "left": 249.6,
      "attrs": { "text": "LOW" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo3",
      "top": -153.6,
      "left": 249.6,
      "attrs": { "text": "MEDIUM" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo4",
      "top": -201.6,
      "left": 249.6,
      "attrs": { "text": "HIGH" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo5",
      "top": -105.6,
      "left": -115.2,
      "attrs": { "text": "PARK" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo6",
      "top": -163.2,
      "left": -115.2,
      "attrs": { "text": "WASHER" }
    },
    {
      "type": "wokwi-text",
      "id": "legendservo7",
      "top": -220.8,
      "left": -115.2,
      "attrs": { "text": "WIPER" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn6",
      "top": -109,
      "left": -48,
      "attrs": { "color": "green" }
    }
  ],
  "connections": [
    [ "nano:GND.2", "btn4:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn3:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn2:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn1:2.l", "black", [ "v0" ] ],
    [ "nano:2", "btn4:1.l", "green", [ "v0" ] ],
    [ "nano:3", "btn3:1.l", "green", [ "v0" ] ],
    [ "nano:4", "btn2:1.l", "green", [ "v0" ] ],
    [ "nano:5", "btn1:1.l", "green", [ "v0" ] ],
    [ "pot1:VCC", "nano:5V", "red", [ "v28.8", "h-153.9" ] ],
    [ "nano:GND.2", "btn5:2.r", "black", [ "v0" ] ],
    [ "nano:10", "btn5:1.r", "green", [ "v0" ] ],
    [ "nano:9", "led3:A", "green", [ "v0" ] ],
    [ "nano:GND.2", "led3:C", "black", [ "v-177.6", "h-144.5" ] ],
    [ "nano:A0", "pot1:SIG", "green", [ "v24", "h220.3" ] ],
    [ "nano:11", "btn6:1.r", "green", [ "v0" ] ],
    [ "nano:GND.2", "btn6:2.r", "black", [ "v0" ] ],
    [ "nano:GND.1", "pot1:GND", "black", [ "v14.4", "h114.7" ] ]
  ],
  "dependencies": {}
}

Not all wipers park the same. You should validate how yours does before building something that will not work. You should also wire for a minimum of LR (Locked Rotor) current as the wiper blade can stall.

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