hall effect sensor as a rpm mesauerment device

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,

anthony
anicolai@coe.neu.edu

http://www.arduino.cc/playground/Main/ReadingRPM

Fans run at 3000rpms and this seems to work fine. :wink:
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. :slight_smile:
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.

thanks

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){
tog++;}
else{
while ( tog == 1) {
cnt++;
Serial.print(cnt, DEC);
Serial.print("\t");
Serial.print(tog, DEC);
Serial.print("\t");
tog = 2;
}
}
}
else
{
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. :slight_smile:

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

Hi,

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.

Thanks,

matt

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.

Thanks for the quick response. I'm pretty sure the sketch is being sent. I have the NG board so i've been pressing reset then sending the sketch to it. I added Serial.println("this is high"); to the statement to see if it was going through the loop properly and it does not print out....am i missing something?

Thanks in advance,

-matt

Are you seeing any serial output? Have you tried the ASCIITable serial example to verify that download is working and you can see serial data from the arduino?

If that works then try adding code to the ASCIITable sketch to read your inPin and output something indicating the state. (Don't forget to set inPin to input).

If that doesn't work then recheck your switch, resistor and wiring. A voltmeter is a big help for projects that involve external components. It's worth getting if you don't have one.

Oh, this topic is interesting...

Hypothetically...

So you're listening to the RPM from a hall effect sensor, but you also want to ouput info to a serial LCD or save info to a USB thumb drive (serial) or send information via wireless (probably serial) to some other device (another arduino?) and you want to listen, or at least post for button inputs because you have a few user inputs... yeah how? How many things can you have interrupts for?

Could you make a simple device to take in the hall effect reading and output an analog signal based on that reading? say at like 1hz reading every second (really slow RPM) vout = 0v and your limit of 100hz vout=5v. You're going to have your "speedometer"

Then Arduino wouldn't really have to listen,but rather post for it. Assuming you don't have any really long loops, you'd probably pick up the vout at least every 100hz... It'd be like a rolling average, but it couldn't ever be too far behind, at least as far as mechanical things go... The problem with hall effect sensors is that they can't really read 0rpm, it has to be assumed.

That's still something I'm having trouble getting my head around as a mechanical guy playing with electrical stuff... 16Mhz is extremely fast for me, 16million operations every second? wow... hard to believe you couldn't pick up something running at 100hz, the issue of course is not if you can pick it up or not, but if you miss the signal, like the hall effect sensor trips when you're not posting for it so you only pick up say 99hz when it's really 100... how much of a difference does it make in the end?

In reality, if you wanted Arduino to collect a lot of data, just how limited are you?

Yeah I'm just sort of thinking out loud, this is something I see myself running into within the next year...

Post you code. There are several ways to kill a serial print response.

hi all,
this is my first post so go easy on me :wink:

regarding this sample code at the following link...
http://www.arduino.cc/playground/Main/ReadingRPM

can anybody tell me why the last line of the below function says "that each rotation, this interrupt function runs twice"
i am a noobe and it is not readily obvious

 void rpm_fun()
 {
   rpmcount++;
   //Each rotation, this interrupt function is run twice
 }

thanks
jeff