Reading speed signal from ABS

Hi all!
I'm new to the world of Arduino so probably even though I think I've informed myself enough, I'm making a trivial mistake.

I need to read this signal coming from an ABS control unit.
The signal communicates the vehicle speed to the ECU.

pwm

As you can see is 2,72Vpp

I would like that when this signal reaches 160Hz a LED will light up

I try different solutions but noone seems read the correct frequency value

this is one of my test:

#include <FreqCount.h>

#define LED_PIN 13
#define FREQ_PIN 5
#define THRESHOLD 160

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
  FreqCount.begin(100);
}

void loop() {
  if (FreqCount.available()) {
    unsigned long count = FreqCount.read();
    Serial.print("Frequenza ");
    Serial.print(count * 10);
    Serial.println(" Hz");
    if (count * 10 > THRESHOLD) {
      digitalWrite(LED_PIN, HIGH);
    } else {
      digitalWrite(LED_PIN, LOW);
    }
  }
}

You can try this code:

#include <FreqCount.h>

#define LED_PIN 13
#define FREQ_PIN 5
#define THRESHOLD 160

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
  FreqCount.begin(100);
}

void loop() {
  if (FreqCount.available()) {
    unsigned long count = FreqCount.read();
    Serial.print("Frequency: ");
    Serial.print(count * 10);
    Serial.println(" Hz");
    if (count * 10 > THRESHOLD) {
      digitalWrite(LED_PIN, HIGH);
    } else {
      digitalWrite(LED_PIN, LOW);
    }
  }
  delay(100);
}

Thank you very much for the help.
The only difference (apart from obviously the translation of frequency into English which I forgot to do because I'm Italian), is that with the "delay(100)" in the serial monitor the frequency is more readable but still completely wrong.
This is the log of a 66Hz frequency

Did you connect that signal directly to your Atduino?
Which Arduino are you using?

Really sorry, right questions.

Yes, I have connected the signal directly on pin 5 (I also tryed in Pin 3) because of the 2,7 Vpp.

I testing the solution on Uno R3 because of a Starter Kit, when it works, I plan to transfer it to a smaller Arduino Micro.

Well you should not do that with a signal hat goes positive and negative. Negative voltages will damage the UNO.
First you a circuit that will make that signal usable as an input to the arduino.

1 Like

I knew somehow I was screwing up… I try to create a circuit with a NE555P that I have in the lab.

The problem of incorrect reading, however, I also encounter with a bench Signal Generator in square waves.

The FreqCount library might not work at low frequencies.
Try using the FreqMeasure library.
Make sure that your square wave generator only goes from 0V to 5V and not over 5V

1 Like

Finally back to work after a few days of illness.
I managed to transform the signal into a 0-5v square wave that I can read using the library "FreqCounter.h" even if not precisely.

Unfortunately I can not read anything with the library "FreqMeasure.h".

#include <FreqMeasure.h>

const int ledPin = 13;
const float threshold = 160.0;

void setup() {
  Serial.begin(115200);
  FreqMeasure.begin();
  pinMode(ledPin, OUTPUT);
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      float frequency = FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      if (frequency > threshold) {
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
      sum = 0;
      count = 0;
    }
  }
}

why not measure the time between pulses. anything < 6.25 msec is > 160 Hz

drive the Arduino pin configured as INPUT_PULLUP thru a transistor with a diode wired oppositely across the base emitter of the transistor to limit the voltage

thanks for reply.

I have the +/- 2.5v problem (post #5)

However I can't figure out why FreqMeasure.h doesn't work

what is the 2.5V problem?
is an ISR being used to detect the spike?

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