Hello Everyone,
I am new to Arduino and have been doing a bit of research. A little background on my project and what I am trying to archive with it.
I have a car that I converted to an electric fan from a mechanical belt driven fan. In all electric fan vehicle's, when the air conditioner is switch on, under 20mph the fan is turned on as well. Anything over 20mph the fan is turned off.
So I am trying to archive this same behavior with Arduino by reading the pulse count from the Vehicle Speed Sensor, its a 5v square-wave.
I have borrow this code from research on this forum and did some modifications. I am not 100% sure and need a little help verifying it.
unsigned long startPulse;
unsigned long twentyMPH = # of pulses;
unsigned long tenMPH = # of pulses;
byte pulseState;
byte prevState;
byte pulsePin = 5;
byte digitalPin = 13;
byte acfanon = HIGH;
byte acfanoff = LOW;
void setup()
{
}
void loop()
{
pulseState = digitalRead(pulsePin);
if (( prevState == 0 ) && ( pulseState > 0 ))
{
if ( micros() - startPulse <= twentyMPH )
{
digitalWrite(digitalPin, acfanoff);
}
else if ( micros() - startPulse >= tenMPH )
{
digitalWrite(digitalPin, acfanon);
}
startPulse = micros();
}
prevState = pulseState;
}
Thanks
Jay