Read Vehicle speed sensor

I wrote program to read number of pulses of Vehicle speed sensor(VSS). It works correctly and read this 5V pulses, but I have problem when there occure some unstability in system and on the pin occure some 0.4V pulse. It count this like a VSS pulse but I would not like read this. Have you an idea how can I filter this unstability?

What device is that takes 0.4V as logical 1 level?

I think what Blimpy is trying to say is "If it's only 0.4V, why is it messing up your count?"

Try a resistor and capacitor. Google for "RC Network". Do you have an oscilloscope? It will be easier to see what's happening if you do.

That 0.4V is not logical 1. It is unbalance on voltage in the car. It occur when I press brake or turn on winkers.

I would like count only pulses from VSS sensor which are 5V, but interrupt count every voltage change on input.
I have only oscilloscope via sound card in PC. I see there that the VSS pulse has 5V and this mess about 0.2 - 0.4V.
I think that RC network don´t help me, because it filter only frequencies and frequency of this mess is variable.
I am affraid if I use RC Network, that system not react on fast VSS pulses. VSS pulse come every 1 feet. It might be one pulse every 0.01 second.
I need to filter signals lower than 0.8 V.

Put a print screen of that oscilloscope signal... The RC filter you calculate to pass your pulses frequency and reject higher frequency noise. If any.
It could be a power supply problem.

Schematics and code please. They-re important here. When people see them, they become more able and willing to help.

Right signal

False signal

Code

void setup(){
  
    
  noInterrupts(); 
  TCCR1A = 0; 
  TCCR1B |= ((1 << CS10) | (1 << CS11)); 
  TIMSK1 |= (1 << TOIE1); 
  TCNT1 = 3036; 

  pinMode(dist_pin, INPUT);

  attachInterrupt(digitalPinToInterrupt(dist_pin), distance_count, FALLING);
  
  interrupts();
 

}

void loop(){

  
}

ISR(TIMER1_OVF_vect) { 
  counter++; 
  if(counter > 3){

    speed = pulse_distance * dist_pulse_count * 3600;

    if(speed > 3){
      avg_speed_divider++;
      avgSpeed();
      maxSpeed();
    }

    dist_pulse_count = 0;
    counter = 0;
    } 
  TCNT1 = 3036; 
}

void distance_count(){
  dist_pulse_count++;                     // při přerušení přičítá 1 do čítače
  pulse_count++;
  //traveled_distance += pulse_distance;    // při přerušení přičítá ujetou vzdálenost dle délky pulzu
}

void maxSpeed(){
  if(speed > max_speed) max_speed = speed;
}

void avgSpeed(){
  all_speed_values += speed;
  avg_speed = all_speed_values / avg_speed_divider;
}

did you tried to read input pin in distance_count() and if it is high just return without incrementing any counter?

eventually with a few microseconds delay, so if it is a valid fall it doesnt read high.

EDIT
or, did you tried to enable interrupt on LOW instead of FALLING?

a low pass filter might smooth out that short glitch, I see your normal pulses are much longer.

Dont' use LOW mode for interrupts unless you know what you are doing!!!

Sounds like you are not using star-grounding so will see gournd currents from other circuits. Which
is of course the norm for a vehicle where the chassis is ground.

+0.4V will not register on an Arduino pin as HIGH.

-0.4V on the other hand could be causing bad things to happen.

There may also be very short pulses of a higher voltage happening.

Try adding 1k in series to mitigate this, and 1nF or 10nF to ground on the pin to filter out high speed
glitches. Even a pulse a few 10's of nanoseconds wide can trigger an interrupt, you have
to clean up the incoming signal properly really...

Dont' use LOW mode for interrupts unless you know what you are doing!!!

Could you please share a link or short info about these problems? I haven't found examples of LOW interrupt handling and wondered why.

Because it interrupts the main program continuously while the input is low. The program never gets a chance to run and the interrupt handler gets 100% of the processor time. Except 50-90% of that is just the interrupt entry/exit action, so you have effectively killed your chip from doing any processing at all while that input stays low.

I very much thank all of you. I tried R 1k and C 10 nF and it is good. It gives me good signal. I tried second way. I used diod in series and it is too right function.