Hello all,
I am new to the forums and new to doing complex things with arduinos. I am attempting to use an arduino to create an intermittent windshield wiper system for a classic chevy truck. So far I have a 5v regulator that necks the voltage from 12V down to 5V for the arduino nano I am using.
I am using the original windshield wiper switch which works off of grounding, so in order to sense when the switch is in the different positions I had to use the internal pull-up resistors. However what I am finding is that for some reason one of my pins that goes to the switch to read whether to activate the washer pump relay is always reading high. I don't really have a good way to draw the full circuit for you so this was the best I could do.
Please let me know if there is any more information you need.
Hopefully that image helps a little (sorry that it looks like it was drawn by a kid).
Below is my code.
#define pot_pin A1
int Pot_Volt = 0; //"voltage integer value 0 to 1023 from rehostat"
float Pot_Percent = 0; //"Pot_volt value turned into a percentage"
int Pulse_time = 0; //"time in ms of timer pulse"
int Pot_Volt_Map = 0;
int int_relay_signal = 9; //Signal to activate intermittent relay
int int_relay_trigger = 7; //Trigger to activate intermittent relay
int washer_relay_signal = 3; //Signal to activate washer pump
int washer_relay_trigger = 5; //trigger to activate washer pump relay
unsigned long pulse_previous_millis = 0;
unsigned long relay_previous_millis = 0;
unsigned long pulse_current_millis = 0;
unsigned long relay_current_millis = 0;
unsigned long monitor_previous_millis = 0;
unsigned long monitor_current_millis = 0;
const long monitor_interval = 2000;
int int_relay_signal_val= 0;
int washer_relay_signal_val= 1;
void setup() {
// put your setup code here, to run once:
pinMode(int_relay_signal, INPUT_PULLUP);
pinMode(int_relay_trigger, OUTPUT);
pinMode(washer_relay_signal, INPUT_PULLUP);
pinMode(washer_relay_trigger, OUTPUT);
digitalWrite(washer_relay_trigger, HIGH);
digitalWrite(int_relay_trigger, HIGH);
Serial.begin(9600);
}
void Monitor() {
int_relay_signal_val = digitalRead(int_relay_signal);
washer_relay_signal_val = digitalRead(washer_relay_signal);
monitor_current_millis = millis();
Serial.println();
Serial.print("Monitor Previous Millis:");
Serial.print(monitor_previous_millis);
Serial.println();
Serial.print("Monitor Current Millis:");
Serial.print(monitor_current_millis);
if (monitor_current_millis - monitor_previous_millis >= monitor_interval) {
monitor_previous_millis = monitor_current_millis;
Serial.println();
Serial.print("int_relay_signal:");
Serial.print(int_relay_signal_val);
Serial.println();
Serial.print("washer_relay_signal:");
Serial.print(washer_relay_signal_val);
Serial.println();
Serial.print("Monitor Previous Millis:");
Serial.print(monitor_previous_millis);
Serial.println();
Serial.print("Monitor Current Millis:");
Serial.print(monitor_current_millis);
Serial.println();
Serial.print("Pulse Previous Millis:");
Serial.print(pulse_previous_millis);
Serial.println();
Serial.print("Pulse Current Millis:");
Serial.print(pulse_current_millis);
Serial.println();
Serial.print("Relay Previous Millis:");
Serial.print(relay_previous_millis);
Serial.println();
Serial.print("Relay Current Millis:");
Serial.print(relay_current_millis);
}
}
void Wash() {
if (washer_relay_signal_val == 0) {
digitalWrite(washer_relay_trigger, LOW);
} else {
digitalWrite(washer_relay_trigger, HIGH);
}
}
void Pot() {
Pot_Volt = analogRead(pot_pin);
Serial.println();
Serial.print("Pot digital voltage = ");
Serial.print(Pot_Volt);
Pot_Volt_Map = map(Pot_Volt, 549, 1023, 0, 1023);
Serial.println();
Serial.print("Mapped Value:");
Serial.print(Pot_Volt_Map);
Pot_Percent = ((float)Pot_Volt_Map / (float)1023);
Serial.println();
Serial.print("Pot percenrtage = ");
Serial.print(Pot_Percent);
Pulse_time = ((float)Pot_Percent * (float)15000 + (float)5000);
Serial.println();
Serial.print("Pulse time = ");
Serial.print(Pulse_time);
}
void relay() {
relay_current_millis = millis();
if (relay_current_millis - relay_previous_millis >= Pulse_time) {
relay_previous_millis = relay_current_millis;
pulse_previous_millis = relay_current_millis;
digitalWrite(int_relay_trigger, LOW);
Serial.println();
Serial.print("Int Pulse Engaged");
}
pulse_current_millis = millis();
if (pulse_current_millis - pulse_previous_millis >= 1000) {
pulse_previous_millis = pulse_current_millis;
digitalWrite(int_relay_trigger, HIGH);
Serial.println();
Serial.print("Int Pulse Disengaged");
}
}
void loop() {
Monitor();
Serial.println();
Serial.print("int relay signal:");
Serial.print(int_relay_signal_val);
if (int_relay_signal_val == 1) {
Serial.println();
Serial.print("Int relay signal:");
Serial.print(int_relay_signal_val);
Pot();
}
if (washer_relay_signal_val == 0) {
Wash();
}
if (int_relay_signal_val == 1) {
relay();
} else {
digitalWrite(int_relay_trigger, HIGH);
}
}
Now as you can see from the code there is a lot more circuitry and wiring other than what I showed in the image above, as there are two relays and a circuit to read the resistance of a rheostat (not potentiometer).
However none of those things should be the problem from what I can tell, unless they are causing some sort of noise that I am ignorant on.
The problem is that the washer_relay_signal is always high, the int_relay_signal on pin 9 works though. And I checked all my grounds, and ensured that the switch was grounding to the common when pressed etc.
Everything hardware side seems to be fine. My main question is if there is anything wrong with my code or if my sensing circuits need to be isolated or if there is a problem with some of the grounding routing. Also as you can see there are a lot of serial printing that I have added just to try and find where the problem is.
Hopefully someone can help me figure this out. Please and thank you.