GM VSS to read mph and trigger relay

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;
}

I think this line is suspect. “analogRead() should have an integer representing the pin number from which you want to read an analog value. Even though you are using an analog input pin you are using it to read a digital signal, and your ISR is doing the reading.

I am assuming VSS refers to “vehicle speed sensor”. Please advise if this is correct or not.

You make this assignment in your declarations:

And this assignment in setup:

Why?

I have not followed your sketch execution all the way through but it appears to me that there are many reasons why it won’t work. I believe the analog read is the reason you are getting a non-zero reading with the vehicle motionless.

The sensor probably outputs pulses, you read pulses with a DIGITAL input.

Yes, VSS stands for Vehicle Speed Sensor.

I appreciate the tips that I have conflicting code with one trying to use analog read on a digital input. That being said, I now cannot get any type of reading when trying to use pluseIn to read the sensor. ( I am trying to get down to the basics now so I am starting from scratch)

#define VSS_PIN 5

void setup() {
   Serial.begin(9600);
   pinMode(VSS_PIN, INPUT_PULLUP);
}

void loop() {
    unsigned long duration = pulseIn(VSS_PIN, HIGH, 10000000);
     Serial.println(VSS_PIN);
  

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