Go Down

Topic: hall effect sensor as a rpm mesauerment device (Read 21210 times) previous topic - next topic


hello.  i had a quick question about hall effect sensors and arduino sample rates.  i want to use a hall effect sensor to measure the rpm and acceleration of a wheel.  the wheel will accelerate to 6000 rpm, or 100 rev a sec in about 6 seconds or so.  my question is about the speed of the digital input.  

first, will there be a race condition, and inaccuracy from the sensor and the clock pulses not syncing up.

and two, if anyone has a recommendation for a decent hall effect sensor.

i was also considering a optical sensor, but the set up the hall effect and magnet set up would work better i think.

thanks for the help,




Fans run at 3000rpms and this seems to work fine. ;)
I'm not sure how the fans get the hall effect sensor to output +5v pulses so you may want to look at an hall effect sensor that has the circuitry to do that for you.


100 times per second? Thats nothing. :)
16Mhz / 100hz gives quite a few instructions between revolutions.

You'd probably be able to accurately detect the RPM and output it on a LCD without any problems.


how would you poll the sensor so theres is a constant sample rate, would it be by using an interupt, i feel that the code delay times would fluctuate based on the data that is acquired and the different times it will take to pass it along the serial conenction.


You get a couple of hundred instructions between each pulse so depending on your application its fine.

Alternatively just make it drive a interrupt and use it to increment a counter.
Probably simplest that way.


just to see if i have the concept down correctly.  what i want to do i measuer the acceleration of a wheel.  it will be spinning at 100 hrz at the top speed.  i tihnk the best way to do this is to have the hall effect sensor singal the interpt on the aurdino every time it goes high.  each time it is trigered i want to export a time stamp to the pc and log it, and then graph the trend of the acceleration based on the diference between a time stamp and its previous time stamp.

does hat make sense, or is there a better way to do data logging with the arduino.



Thats one way.

Another way which is better if your doing other things on the chip at the same time:
1) When a interrupt fires, revolutions++;
2) Every X ms (however fine you want it) get the number of revolutions and reset the variable to 0
3) Compare the previous number to the current number. The change is acceleration while the number is absolute speed.


on a side note, i wrote some code to count how many times a button is pressed, and to only measuer the state changes.

here is that.

int ledPin = 12;                // LED connected to digital pin 13
int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int cnt =0;      // var for counting the presses
int tog =0;       //bit used to toggle and keep track of when the button is pressd or not

void setup()                    // run once, when the sketch starts
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output
 pinMode(inPin, INPUT);    // declare pushbutton as input
 Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps


void loop()                     // run over and over again
 val = digitalRead(inPin);  // read input value
 if (val == HIGH) {         // check if the input is HIGH (button released)
   digitalWrite(ledPin, LOW);  // turn LED OFF
   if (tog ==0){
   while ( tog == 1) {
     Serial.print(cnt, DEC);
     Serial.print(tog, DEC);
     tog = 2;
   digitalWrite(ledPin, HIGH);  // turn LED ON
   tog =0;

can i just replace the push button with the hall effect sensor?


also, is that a good way to do this function.  i dot really know much about code format.


The code should work. If you learn how to do that with an interrupt the chip could be doing other things until the interrupt is triggered.  That would be important only if you were running something time sensitive like a scanned LED matrix or had to monitor some other sensors.


im not exactly sure how you would use the interupt for this situation.  i have two ideas from what you have mentioned.

1) use the interupt as the data in from the hall effect sensor.  when the interupt is triggered send the current time out via the serial link ot the comp to log and process this data and then graph it.
2)run code to count all of the positive state transistions the hall effect sensor has, when setting up a timer to trigger the interupt at a constant time, and do the math based on how many revs per interupt period.

if you have another way please specify.

thanks for the info/help i really apreicate it.


When using a interrupt you have to make the interrupt function as small as possible.
You cannot use stuff like Serial in it. If its too big then strange things happen. :)

Its best to make the hall effect sensor fire the interrupt and just have a variable storing how many times it fires.
Thats only a single instruction and will work the best.


cool thank you.  right now im just using a push button, but i got some sensors in the mail.

ill posy on how it turns out


Jan 03, 2008, 06:33 pm Last Edit: Jan 03, 2008, 07:05 pm by firestarter Reason: 1

I'm just getting started with the arduino and figured i'd give the pushbutton example a try.  When i connect up everything as shown on this page http://www.arduino.cc/en/Tutorial/Pushbutton the LED gives me a flashing light instead of an on/off behavior... i'm stuck?  Is it supposed to give me a flashing LED? or a state-like behavior which would make sense.




The led should follow the state of the button. Perhaps the input is floating, check to make sure that the switch is connected to pin 7. If you have a voltmeter, check that the voltage is 5 volts on pin 7 when the switch is not pressed and 0 volts when pressed.

Also, are you sure your sketch has been sent to the board, as I recall on mine. the default sketch just flashes the led.

Go Up