# rpm counter

**URL:** <https://forum.arduino.cc/t/rpm-counter/695457>\
**Category:** General Guidance\
**Created:** [February 10, 2021, 7:28am UTC](https://forum.arduino.cc/t/rpm-counter/695457 "2021-02-10T07:28:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 7:28am UTC](https://forum.arduino.cc/t/rpm-counter/695457/1 "2021-02-10T07:28:56Z")

</div>

Hello  
Have some questions  
For a project I have to make a speedometer with a hall sensor.  
Have you read a lot about this already and only have a few questions?  
You can measure your rpm by measuring the time between 2 pulses and then calculating rpm or measure the amount of pulses in 1 sec.  
Which of these is the most accurate?

Maybe somebody already has what I'm looking for?  
It is a circuit with a hall ([https://www.gotron.be/arduinor-compatible-magnetic-hall-holzer-sensor-2-st.html](https://www.gotron.be/arduinor-compatible-magnetic-hall-holzer-sensor-2-st.html)) and a lcd 16x2

Thanks in advance for the help  
Jef Van Roy

---

<div class="post-metadata">

**Author:** ![Riva](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/riva/32/1013044_2.png) [@Riva](https://forum.arduino.cc/u/Riva)\
**Post date:** [February 10, 2021, 7:53am UTC](https://forum.arduino.cc/t/rpm-counter/695457/2 "2021-02-10T07:53:28Z")

</div>

> jefvr:  
> You can measure your rpm by measuring the time between 2 pulses and then calculating rpm or measure the amount of pulses in 1 sec.  
> Which of these is the most accurate?

The most accurate is to count pulses over one second

Your link does not work and it appears your trying to link to [here](https://www.gotron.be/arduinor-compatibele-magnetische-hall-holzer-sensor-2-st.html)

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 8:10am UTC](https://forum.arduino.cc/t/rpm-counter/695457/3 "2021-02-10T08:10:25Z")

</div>

Oke thanks  
can you tell why? because when i am chearching they say its more accurate when they count the time between 2 pulses.  
i have no idea everybody says something others.

Any advice or good circuits that work ?  
Or some other forums?  
My link works thats the sensor i juse (for some more info about the sesnor).  
Its maybe my sentence construction that confuses you.  
I am sorry but i am not the best in englisch.

Thanks for the qiuck respons.  
Jef

---

<div class="post-metadata">

**Author:** ![Riva](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/riva/32/1013044_2.png) [@Riva](https://forum.arduino.cc/u/Riva)\
**Post date:** [February 10, 2021, 8:58am UTC](https://forum.arduino.cc/t/rpm-counter/695457/4 "2021-02-10T08:58:34Z")

</div>

Depending on how fast your pulse period is you can usually determine the results more accurately by counting them over a fixed period of time than the time between pulses as fixed time period helps with reducing rounding errors you may get compared to calculating time between each period.  
The acid test is to try both methods and see what works best for you.

The web page you linked to seems to have a clone module of [KY-003](https://arduinomodules.info/ky-003-hall-magnetic-sensor-module/). The site I linked to has a simple wiring diagram and sketch to try.

Depending on what model of Arduino your connecting to and how you expect to display the frequency will determine the place to start looking for or writing code.

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 9:07am UTC](https://forum.arduino.cc/t/rpm-counter/695457/5 "2021-02-10T09:07:48Z")

</div>

Thanks

I was thinking of a lcd 16x2 and an arduino uno.  
just the basics

Jef

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [February 10, 2021, 9:14am UTC](https://forum.arduino.cc/t/rpm-counter/695457/6 "2021-02-10T09:14:52Z")

</div>

> Riva:  
> The most accurate is to count pulses over one second

IMHO it would be slightly more accurate to measure the time for a number of pulses. Counting pulses in a fixed period runs the risk of just catching or just missing the last one.

In practice I suspect measuring the time between pulses would be perfectly satisfactory. It was certainly good enough for me when controlling a small DC motor using 1 pulse per revolution. At 16,000 RPM there were about 3700 microsecs between pulses so the error due to micros() incrementing by 4 was inconsequential.

...R

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 9:22am UTC](https://forum.arduino.cc/t/rpm-counter/695457/7 "2021-02-10T09:22:07Z")

</div>

Oke maybe some more info  
Its for a diesel engine.  
With one pulse per revolution.  
I think with a max of 8000 rpm.  
i will never have to measure 8000rpm it is gone be more around 3000rpm.

Jef

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [February 10, 2021, 9:56am UTC](https://forum.arduino.cc/t/rpm-counter/695457/8 "2021-02-10T09:56:33Z")

</div>

> jefvr:  
> Oke maybe some more info

What exactly do you need help with ?

...R

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 10:06am UTC](https://forum.arduino.cc/t/rpm-counter/695457/9 "2021-02-10T10:06:42Z")

</div>

What you think is the best and maybe also the easiest to explain to someone who is not the best with arduuino and programming.  
Maybe some tips or forums where i can find such circuits and codes?

and it was just some more info about my project.

it will help a lot.  
Jef

---

<div class="post-metadata">

**Author:** ![Blackfin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/blackfin/32/238871_2.png) [@Blackfin](https://forum.arduino.cc/u/Blackfin)\
**Post date:** [February 10, 2021, 12:17pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/10 "2021-02-10T12:17:03Z")

</div>

> jefvr:  
> Oke maybe some more info  
> Its for a diesel engine.  
> With one pulse per revolution.  
> I think with a max of 8000 rpm.  
> i will never have to measure 8000rpm it is gone be more around 3000rpm.
> 
> Jef

I would find the period between pulses and update the internal representation of RPM once per revolution. Think about how crappy it would be if the tachometer in your car jumped only once a second to the currently-measured engine speed. As well, if you want to log data you probably want a granularity finer than one-second.

8000RPM? What kind of diesel engines are these that might turn that fast?

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [February 10, 2021, 12:21pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/11 "2021-02-10T12:21:47Z")

</div>

> jefvr:  
> Maybe some tips or forums where i can find such circuits and codes?

I have not used a hall sensor myself but it seems from the link in Reply #1 that you already have a working sensor module. I presume it produces a pulse every time the magnet passes the sensor.

The [code in this link](https://forum.arduino.cc/index.php?topic=564223.msg3844595#msg3844595) is the program I have used with a QRE1113 reflective optical sensor which also produces a pulse every time it detects the white stripe.

...R

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 12:28pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/12 "2021-02-10T12:28:29Z")

</div>

> Blackfin:  
> 8000RPM? What kind of diesel engines are these that might turn that fast?

that's what the people in the workshop say  
but does not matter, it is usually used at lower speeds.  
so i am going for rpm with the time between pulses

Thank you for the reply

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 12:33pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/13 "2021-02-10T12:33:29Z")

</div>

> Robin2:  
> The [code in this link](https://forum.arduino.cc/index.php?topic=564223.msg3844595#msg3844595) is the program I have used with a QRE1113 reflective optical sensor which also produces a pulse every time it detects the white stripe.

thanks for the answer it helps a lot.  
this code is not for measuring rpm or am i wrong ?  
it is just for detecting pulses.  
sorry but i am not the best with arduino programming yet .  
Jef

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 12:59pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/14 "2021-02-10T12:59:13Z")

</div>

I have found this.

thanks for the help  
Jef

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 1:04pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/15 "2021-02-10T13:04:25Z")

</div>

```cpp
# include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);
float value=0;
float rev=0;
int rpm;
int oldtime=0;
int time;

void isr()
{
rev++;
}

void setup()
{
lcd.begin(16,2);
attachInterrupt(0,isr,RISING);
}

void loop()
{
delay(1000);
detachInterrupt(0);
time=millis()-oldtime;
rpm=(rev/time)*60000;
oldtime=millis();
rev=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" RPM TESTER ");
lcd.setCursor(0,1);
lcd.print( rpm);
lcd.print(" RPM");
lcd.print(" ");
attachInterrupt(0,isr,RISING);
}

```

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [February 10, 2021, 1:17pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/16 "2021-02-10T13:17:24Z")

</div>

> jefvr:  
> this code is not for measuring rpm or am i wrong ?

It calculates and prints the number of microseconds between pulses. I presume you can convert that to RPM if you need to.

...R

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [February 10, 2021, 1:23pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/17 "2021-02-10T13:23:27Z")

</div>

Your latest code has a number of issues, although it may work.

Any variable used in an interrupt should be marked volatile.

rev is counting pulses - there is no need to make it a float. Even at 8000 rpm, a byte is enough.

It's more conventional to use noInterrupts while you use rev rather than detach and attach.

You may want to use blink without delay techniques rather than a delay if your code has to do anything else.

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 1:29pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/18 "2021-02-10T13:29:04Z")

</div>

Oke thanks for al the info.  
But i am a really big noob in programming so i have to learn a lot.  
I will try my best .

always open for help,info,tips and tricks!  
Thanks for the help  
Jef

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [February 10, 2021, 1:36pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/19 "2021-02-10T13:36:54Z")

</div>

It all depends on the speed.

At your speed of no more than 133 pulses per second simply measure time between pulses. That'll be the most accurate. if you're down to 600 rpm missing one pulse is a 10% error.

In kHz range I'd look for the time taken for a number of pulses, to have a larger time for better accuracy.

Mind: pulse length itself may be a factor here, so make sure to count from falling edge to falling edge, not falling edge to rising edge or the other way around, which is what the pulseIn() function does.

In the MHz range more likely pulses per time unit (where time is in the millisecond range for a couple thousand pulses). Pulse duration and missing that one last pulse are not a factor now.

---

<div class="post-metadata">

**Author:** ![jefvr](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jefvr](https://forum.arduino.cc/u/jefvr)\
**Post date:** [February 10, 2021, 1:56pm UTC](https://forum.arduino.cc/t/rpm-counter/695457/20 "2021-02-10T13:56:58Z")

</div>

oke i understand it a little bit  
its depend on the speed that i have to measure

but if i want to measure a speed of 600rpm or 3000rpm i need 2 different codes or how i have to do that ?

sorry i am a little bit confused  
Jef

[Next page](https://forum.arduino.cc/t/rpm-counter/695457.md?page=2)
