Go Down

Topic: Pulse Counting (Read 1 time) previous topic - next topic

superedd

Hello, This is my first time here and I am fairly new, I am looking for a simple way to count pulses coming from a sensor, Any suggestions

Thanks in advance

Superedd

PaulS

Quote
I am looking for a simple way to count pulses coming from a sensor, Any suggestions

1, 2, 3, ...

What kind of sensor? How long are the pulses? How frequently do they arrive? Counting 10 1 second pulses a minute is trivial. Counting 10000 pulses per millisecond is a bit more challenging.

Darwoon

You can't count pulses coming from a sensor, but count the speed your arduino board get sensor values.
What's your arduino board ? Uno has a 16Mhz clock... it can easily make 10 000 loop if you're just reading the tension (but not using Serial.print, then you have only 300 loops  :P).
Count the number of loop for a second  e.g., comparing the time you began with millis() (returns the number of milliseconds since the board began running your current program).

UKHeliBob

Set a counter to zero
Every time a pulse arrives from the sensor add one to the counter
That's it really

As has been suggested, more details would help.
Have you written any code to read the sensor, whatever it is ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

superedd

Hi Everyone thanks for all your posts and help, i will explain in more detail what i am trying to accomplish:

I need to count pulses coming from a Geartooth sensor, which will provide a pulse every time a "tooth" will pass it, the gear i am using have 70 teeth and its turning at 1500 rpm therefore the frequency of the pulses are at about 1750 Hz.

I intend to use another hall effect sensor to reset the counter each time the gear is making a full turn so its need to count only up to 70.

I use Arduino Mega 2560

Any suggestion commands / code will be greatly appreciated

Superedd

PaulS

To deal with 1.750 pulses per second, reliably, you probably want to use an interrupt handler. Connect the hall effect sensor to one of the external interrupt pins (there are 5 to choose from on the Mega), and attach a handler to that pin. You can use either RISING or FALLING. Don't use CHANGE or LOW, though.

In the ISR, all you do is increment a counter (volatile). In loop(), you can use that counter and millis() and an interval to calculate speed. There are any number of posts, with code, showing how to calculate RPM that should give you clues.

MarkT

Do you have details of the sensor - some generate clean logic pulses with a single transition are switching (the sensor has
some hysteresis and avoids slow changing output or contact bounce).

Less well behaved sensors may need signal conditioning (hardware and/or software) in order to get a correct count.

In particular hall effect sensors can be analog or digital (logic output), and the latter are usually fine (they have enough
hysteresis to give clean pulses).

Sometimes noise can be picked up from the nearby electrical equipment to inject false noise spikes into your sensor
cable - this is particularly an issue in the "automotive environment" - signal conditioning can help here, you try to
filter out the noise and leave the pulses-of-interest intact.
[ I won't respond to messages, use the forum please ]

Nick Gammon

http://www.gammon.com.au/forum/?id=11504
http://www.gammon.com.au/electronics

superedd

Hi All, Thanks again for your help, I am still unsuccessful in counting pulses, can anyone show an example code

Thanks

Superedd

Nick Gammon

The link I gave above had a paragraph near the start "Counter 1 - used to count pulses".

That had example code.
http://www.gammon.com.au/electronics

UKHeliBob


Hi All, Thanks again for your help, I am still unsuccessful in counting pulses, can anyone show an example code

Thanks

Superedd

Are you going to share the code that is unsuccessful in counting pulses ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up