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.


#include <FreqMeasure.h>

void setup() {

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum +;
    count = count + 1;
    if (count > 30) {
      float frequency FreqMeasure.countToFrequency(sum / count);
      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.


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