Go Down

Topic: Hall Effect Wheel Speed, next step (Read 4381 times) previous topic - next topic


Please note: Currently trying to set up a hall effect sensor for the wheel speed of a car. Eventually we will have discs with teeth to produce a good signal but currently just using a lump of metal and mr arm to generate the signal. Using UNO R3

So what I have so far is a hall effect sensor that outputs an analogue signal and I have managed to read this and convert it to a 1 or 0 stored in a variable "hallval". The led part is just so I can see it working.

Code: [Select]
int hallPin = A0;
int ledPin = 13;
int val;
int hallval;

void setup()
pinMode(hallPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);

void loop()
  val = analogRead(hallPin);
  if (val <= 75) digitalWrite(ledPin, HIGH);
  else if (val > 75) digitalWrite(ledPin, LOW);
  if (val <= 75) hallval = 1;
  else if (val > 75) hallval = 0;

What I need to do, or think I need to do is now measure the time it takes to switch "hallval" from 1 to the next "1" in order to calculate the speed.

So I have two questions, given that this is the sensor I have right now and cannot buy new ones.. yet.

1) Is what I have done so far good enough / does anyone know an easier way to achieve what I require?

2) How can I measure the time from 1 to the next 1? are there any functions you can suggest the might help me.


You have to use interrupts, there are a number of ways. Make sure your hall sensor can switch fast enough too


German but you can use google translate and code is still the same

This code also depends on whether you have a latch sensor or not.



what I would do is: connect the signal of your hall effect sensor to one of the interrupts of the arduino. Make a interrupt routine that increments a variable every time the routine is called. In the main loop subtract the value of the variable 1 second before from the current value of the variable. Then you have the number of pulses per second. Now you can calculate RPM or the time for one revolution.

My blog about arduino and Linux themes:


Thanks for the replies, I will look into the interupt function and update on progress.


Note that hall effect sensors come in different 'flavors'. Yours appears to be one that outputs a analog voltage relative to the magnetic field strength being sensed? Others come as simple digital switches that out either a logic high or low depending on if the magnetic field being sensed is above or below a specific value. A digital hall sensor would be better to use as a speed detector as you can easily interface it as a interrupt and use timers to keep track of the last change of signal to the next change of signal and then calculate the speed based on the delta time passed.

Now what I do not understand is how a hall effect will work with just metal gear teeth? A hall effect senses the strength (and in some cases the polarity) of a external magnetic field. Unless the gear is magnetized I don't see where there is a magnetic field to be sensed in your application? There are speed sensors that are designed to just sense gear teeth, called variable reluctance sensors that work on a different principle as the magnetic field is generated internal inside the sensor and the rotating teeth effect the magnetic field and is sensed by the internal circuitry of the speed probe. Perhaps a link to the sensor you are using will verify if it's best suitable for your application?



sorry quick reply but this is the datasheet, we have used this on a previous car for some testing although we believe it is too slow for the higher speeds



sorry quick reply but this is the datasheet, we have used this on a previous car for some testing although we believe it is too slow for the higher speeds


Interesting sensor. It's not a pure simple hall effect sensor as it has an internal magnetic field generator that 'biases' the sensor such that rotating teeth will effect the field. It's also outputs a pure digital signal so you should not be reading it with a analog input pin using a analogRead() statement, but rather read it as a digital input signal using digitalRead() commands or better yet learn how to use the user interrupt functions on the arduino using digital pins 2 or 3 (on a Uno) board.

As far as maximum speed capabilities you will have to work out the minimum time between teeth to see that you are not exceeding a maximum switching speed of the sensor. The key spec seems to be:

Fast operating speed - over 100 kHz

This will of course be related to the number of teeth on the gear wheel and the maximum RPMs of the wheel. Less teeth would allow higher maximum RPM.



Read this
then watch this


Go Up