Good afternoon, I have a T56 manual transmission with what I am guess is a two wire Hall Sensor for the VSS. I am looking to read this sensor so I can trigger a relay to control the reverse lockout and a transmission cooler. I have an Arduino Uno, and currently have one end of the sensor to ground and the other to pin A0. Currently when running the Serial Monitor I get a steady reading of 45/46mph.. when it should be zero. When I spin the input shaft I get anything from 0mph to 150mph, so on the bright side I have managed to get some type of reading from the sensor. I have pieced code together from multiple different sources to come up with what I currently have. I am open to any suggestions on how to clean up this code to get it to read properly.
Original code in post #28 Converting pulses into speed - #27 by gcjr
const int RESET = 18; // pin for RESET
//------------------------------------------
volatile unsigned long VSS_count = 0;
unsigned long VSS_prior_count = 0;
int pin_VSS = A0;
int currentMillis;
unsigned long lastMillis;
unsigned long VSS_new_count;
int teeth = 17;
float diffRatio = 3.42;
int WheelCirc = 2126; //mm
float toothDistance = (1.0 / (teeth));
float disttravelled = WheelCirc / diffRatio;
unsigned long elapsedTime;
unsigned long speedRaw;
int pulsegroup = 0;
unsigned long time;
float value;
//--------------------------------------------------
void setup()
{
Serial.begin (9600);
pinMode(RESET, OUTPUT);
digitalWrite(RESET, LOW);
delay(1); // keep reset low min 1ms
digitalWrite(RESET, HIGH);
//---------------------------------------------------
toothDistance = toothDistance * disttravelled;
//---Speed Input Count-----------------------------------
pinMode(pin_VSS, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pin_VSS), pulse, RISING);
//---------------------------------------------------
}
void loop() {
noInterrupts ();
VSS_new_count = VSS_count;
interrupts ();
time = millis();
pulsegroup = VSS_new_count - VSS_prior_count;
if (pulsegroup >= 20) {
elapsedTime = (time - lastMillis);
speedRaw = ((VSS_new_count - VSS_prior_count) * 60 * 1000 / (toothDistance * elapsedTime)) / 10;
VSS_prior_count = VSS_new_count;
lastMillis = time;
}
value = (analogRead(VSS_new_count));
Serial.print("Value: ");
Serial.print(value, 1);
Serial.println(" mph");
delay(500);
}
void pulse() {
VSS_count = VSS_count + 1;
}