# rpm counter

Hello
Have some questions
For a project I have to make a speedometer with a hall sensor.
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) and a lcd 16x2

Thanks in advance for the help
Jef Van Roy

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

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?
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

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. 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.

Thanks

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

Jef

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

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

jefvr:

What exactly do you need help with ?

...R

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?

it will help a lot.
Jef

jefvr:
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?

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 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

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

Robin2:
The code in this link 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

I have found this.

thanks for the help
Jef

``````# 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);
}
``````

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

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.

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

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.

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