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
