Speedometer using vehicle speed sensor signal getting floaty results

I have this prodject "Working" just need some advice on how to approach a few issues.
Just sitting at idle from start up I am getting very erratic results in my display anywhere from 11 to 150 mph just at idle.
I am using pulseIn to measure the timing of the pulses then calculate the speed.
I am beginning to think pulseIn is to sensitive for what I am using it for?
It also appears that I need some form of averaging readings out but it is obvious I need to get stable readings first. I seem to be having a noise problem.
Is there some smarter way of pulling this off or any advice on how to to clean up my readings?

#include <WiseChipHUD.h>

// Notes 
// built around a sparkfun redbord turbo
// vhicle is set to 4000 PPM square wave pulse 0-5v  
// PPM = Pulses Per Mile 
// mesuring the time between pulses in micro seconds
// vss input pin = 12
// maxamum display number is 199
//
WiseChipHUD myHUD; //sets up myHUD
unsigned long VSS; // vhucle speed sensor input  
int MPH; 

void setup() {
  pinMode(12, INPUT);
myHUD.begin(); // sets up myHUD
SerialUSB.begin(9600); 
    delay(3000);// delay to get car started and running
myHUD.clearAll();// clears all segments
//while (!SerialUSB);  //===================================================debug code requires moniter to be open before continung =======================
          // cool start up sequince for display 
    for (int i = 0; i< 199; i += 5) {
         //myHUD.setTirePressure(i, 1);
         myHUD.setSpeedometer(i); }
         delay(1000);
myHUD.clearAll(); //clears start up display 
    myHUD.setSpeedometer(0); // sets redings to zero 
}

void loop() {
  delay(1000);
VSS = pulseIn(12, HIGH, 10000000); // IF NO PULSES IN 10 SECONDS TIME OUT and return zero mesured in microseconds 
//VSS = 12345;// ==========Testing Code will simulate VSS signal should be 72 mph COMMENT ME OUT!!!!!=======================
if (VSS != 0) // changed to VSS from MPH change back if nessary 
{
MPH = 900000/VSS;// math for microsconds to mph
}
if (VSS == 0)
{
  MPH = 0;
}
if (MPH > 199)
{
  MPH = 0;
}
abs(MPH); //  round down to the nerist whole number 

//===================================================Serial====================================================
       SerialUSB.println("VSS Times Microseconds");
       SerialUSB.println(VSS, DEC); // send data over usb serial connection
       SerialUSB.println("MPH"); 
       SerialUSB.println(MPH, DEC);

//=================================================Dispay======================================================
myHUD.setSpeedometer(MPH);//sets display to calculated number

}// end of void loop

Small output of the serial monitor from idle

VSS Times Microseconds
12420
MPH
72
VSS Times Microseconds
3880
MPH
0
VSS Times Microseconds
71913
MPH
12
VSS Times Microseconds
29622
MPH
30
VSS Times Microseconds
37831
MPH
23
VSS Times Microseconds
76486
MPH
11
VSS Times Microseconds
57869
MPH
15
VSS Times Microseconds
79062
MPH
11

Thanks for having a look Hive mind of the interwebs

Noise can be a big problem in auto installations.

Where does you sensor pick up it's signal..?

Cabling may need to be shielded type.

4000 pulse per mile ...?? can't imagine where the sensor is.

If your car has an OBDII port, it would be a ton more reliable to use a bluetooth OBD2 scanner. You can get vehicle speed from the scanner using ELMduino.h. The lib is installable via the Arduino IDE's Libraries Manager and comes with examples. Example use-case

bluejets:
Noise can be a big problem in auto installations.

Where does you sensor pick up it's signal..?

Cabling may need to be shielded type.

4000 pulse per mile ...?? can't imagine where the sensor is.

The ECU is sending out that signal it is usually picked up by the stock speedometer I am just taped into that wire that is already coming off of the engine control computer.
I will look into shielding the wire.

Power_Broker:
If your car has an OBDII port, it would be a ton more reliable to use a bluetooth OBD2 scanner. You can get vehicle speed from the scanner using ELMduino.h. The lib is installable via the Arduino IDE's Libraries Manager and comes with examples. Example use-case

I am replacing a stock dashboard in a 1961 Chevy with a hud element odb2 or gps are options but the ls3 engine computer has a speed output wire so I figured I could just tap into that easier then the can bus system.

Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Show us the arduino circuit and how you connect to the ECU.

Thanks.... Tom... :slight_smile:

PulseIn only measures the ON or OFF time of the pulse. It doesn’t measure the period Between edges, which is probably what you need for this calculation. So depending on how wide the HIGH pulse is you may get considerable inaccuracies that will need a “fudge factor”.

Having said that it doesn’t account for your wild readings when stationary, which are likely due to noise.

A better approach, rather than software timing, would be to use T2 in hardware pulse count mode. You can either have it count pulses for you, or capture the timer value on the positive or negative going edge. All without any software intervention. You”ll need to clean up the noise first though....

Used this very feature to couldn’t wheel rotation pulses on my Audi the other week.

Do you have access to a scope?

TomGeorge:
Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Show us the arduino circuit and how you connect to the ECU.

Thanks.... Tom... :slight_smile:

very simple I added the 10k pull down in an attempt to solve this floating issue

pcbbc:
Do you have access to a scope?

Just put my scope on the line and im getting 2-5V of ac noise. This leaves my wondering how the stock or aftermarket speedometers filter it out