Frequency Messure

Hi There.

I am using an Uno to measure frequency on a motor, and then print on the Serial monitor. I am using the FreqMeasure library and i works fine, but when motor stops Serial monitor shows last measured frequency. How do I get it to show “0” with some simple code?

Here’s a link to the library.

Thanks.

#include <FreqMeasure.h>

void setup() {
  Serial.begin(57600);
  FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      float frequency FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }
  }
}

Here's a link to the library.

Where's your code?

Updated with code, Sorry..

How do I get it to show "0" with some simple code?

Add an else clause to this if:

void loop() {
  if (FreqMeasure.available()) {

...though you may only want to do that after a timeout.

AWOL

Could you elaborate how to do this ? Thanks

Set a variable to the current value of millis() each time you get a valid reading.
Compare that time to the current time when you're not getting valid readings, and take appropriate action