Speedometer - Hall Effect Sensor Suitable?

I'm trying to make a speedometer car for my model railroad. At the moment, my plan is to have a 2mm Neodymium magnet attached to the rear of a freight car wheel, with a KY-003 hall effect sensor mounted to detect when it goes off. This will be connected to an Arduino Pro Nano on an interrupt pin, which will perform the calculations, update an LED display and log the speed and time to an SD card.

Thing is, I've used this sensor before, and its output is analogue, not digital. As such, I'm not sure if this sensor would work for this project. Could this work, or am I better off with a different sensor?

Also, the diameter of the wheel in question is approximately 11mm - just under half an inch.

I've used this sensor before, and its output is analogue, not digital.

If you read it with an analog input on the Arduino you can effectively turn it into a digital signal by choosing to count the pulse only when the input becomes greater than a trigger value.

It might work. If you position the sensor correctly, the analog output may be read ok a digital signal. It does not matter if the output is HIGH for half the revolution, you can still use that to measure the rpm.

If they doesn't work, you can try using an analog Arduino pin. The ADC may be fast enough, especially if you reduce the resolution. You won't be able to use interrupts in that case, but I don't think you need those anyway.

If neither of those work, use a comparator chip and a trimpot to set the trigger level. Might be cheaper to get a sensor with a digital output.

The magnet will pick up metall stuff so You will need to clean it now and then before it looks like a christmas tree. Optical sensors collect dust but could be an alternative.

I've already tried an optical sensor, with no luck. I think the wheel moves a bit too fast for it.

Would the comparator and trimpot work with an interrupt pin? The idea is that the hall effect sensor triggers an interrupt, and that's what does the speed calculations, updating the display, etc.

Tbdanny: I've already tried an optical sensor, with no luck. I think the wheel moves a bit too fast for it.

What optical sensor did you try? Most optical sensors are very fast.

Tbdanny: Would the comparator and trimpot work with an interrupt pin? The idea is that the hall effect sensor triggers an interrupt, and that's what does the speed calculations, updating the display, etc.

Yes it would work with an interrupt. But you don't yet understand what interrupts are for. They are certainly not for performing calculations or updating displays. And as I said earlier, you don't need an interrupt for your project at all.

Thing is, I've used this sensor before, and its output is analogue, not digital. As such, I'm not sure if this sensor would work for this project. Could this work, or am I better off with a different sensor?

Not with the data sheet information I see. The KY003 uses a 3144 hall sensor which is digital with open collector output.

https://www.elecrow.com/download/A3141-2-3-4-Datasheet.pdf

PaulRB: What optical sensor did you try? Most optical sensors are very fast.Yes it would work with an interrupt. But you don't yet understand what interrupts are for. They are certainly not for performing calculations or updating displays. And as I said earlier, you don't need an interrupt for your project at all.

I tried a QRE1113. I think part of the problem was that it was a bit too far away from the wheel. As for calculations, I want it to perform the calculation and do the update when it detects one revolution of the wheel. It seems to me that using an interrupt would be more accurate than checking the sensor every millisecond or so and hoping it doesn't miss a revolution.

It seems to me that using an interrupt would be more accurate than checking the sensor every millisecond or so and hoping it doesn't miss a revolution.

Using an interrupt is OK as long as the isr is appropriate(that is quick and not using anything that relys on interrupts being enabled). Incrementing the count of revolutions or getting the start/end time of a revolution are both reasonable things to do following an interrupt.

See http://www.gammon.com.au/interrupts

Thank-you. I figured that would be the more accurate way to go.

I've also switched to a bigger optical sensor with more range, and that seems to work.

Hi. I made a speedo for my car using a Hall Effect sensor and nano with a seven segment LED display. Works well and has been in constant service for more than 6 months.

I calculated that at 100 kph the wheel rotates at about one rev in 60ms. I don't recall how I determined the time it takes the Nano to execute one loop of the sketch but was well under 60ms, so in theory it shud not miss a rotation.

It gives a reliable and accurate reading from 0 to 110 kph.

My wheel diameter is 1.9m. Your rail car wheel is tiny. You don't need to detect the precise instant the signal goes hi, just that it has made the transition from lo to hi (or it may be lo to hi, can't recall).

I initially used interrupt as I thought that was the "clever" way. Creates issues with timing functions that I didn't understand. No doubt they are solvable but I tried polling the pin and found this easy. Interrupts are for dealing with an irregular unpredictable event, when the code's main purpose is doing something else. The wheel clicks are exactly the opposite and my code has nothing else to do.

John.

My wheel diameter is 1.9m.

Really? Did you mean circumference?

But thanks for confirming to the OP that interrupts are not necessarily the best way to go.

oops...

:blush:

Quote

My wheel diameter is 1.9m.

Really? Did you mean circumference?

I'm in the USA... how large is 1.9m ?

in my calculations, if the circumference was 1.9m then the wheel would be about 24 inches dia ?

HALL sensors come in 3 basic functions.

#1 is an analog output based on the strength of the magnetic field.

#2 has a Hi/LO output that changes state if the magnetic field is in range, reverts when not in range

#3 is a switch the goes HI when one polarity is within range and requires the other polarity to go Lo, requires both poles to work

I always test before soldering.

dave-in-nj: I'm in the USA... how large is 1.9m ?

1.9m is the same wherever you are!

dave-in-nj: in my calculations, if the circumference was 1.9m then the wheel would be about 24 inches dia ?

Correct.

Yeah, a CIRCUMFERENCE of 1.9 metre. The wheel is about 24" diameter.

I accept the car's speedo as accurate so I tweaked the circumference value in the sketch to give a readout that matches the car speedo at, say, 50kph. This could even be done automatically by commanding the sketch to adjust the circumference value to produce a speed of 50, ie, a sort of self-calibration.

Mis-wiring the sensor makes it go VERY hot.

John.

I had to re-read the whole thread. Tbdanny, the OP has a model that is 11 mm dia. NissanCedric, has a similar project with a different size wheel. 1.9m circumference.

and PaulRB, you might guess that here in the USA, we are only now converting to the metric system and things like 1.9 and 1,9 are confusing. Also, we in the USA are so unbelievably arrogant that the rest of the world does not think like us, it is comical. 99% of countries on the planet use the metric system. Only one country landed a man on the Moon......

On the flip side, Russian researches figure things out with their brains, we have to use computers and then do not question if the data input was correct. I was at a product release for a product that was cutting edge and as one of the few that actaully understood the enginnering, I asked the company's lead engineer how he figured it out..... a 1913 Russian engineer book translated in the 1920's

dave-in-nj: PaulRB, you might guess that here in the USA, we are only now converting to the metric system

In the UK, we started converting to metric before I started school nearly half a century ago, and we are still not there. We buy fuel for our cars in litres and then measure the consumption in miles per gallon. And our gallons are different to yours...

Tbdanny: I've already tried an optical sensor, with no luck. I think the wheel moves a bit too fast for it.

11mm dia wheel has appx 34.56mm circumference. Your train does not move 1000x that in a second does it? Or even half as far?

My guess is that you used an LDR which is VERY slow or did not illuminate what it would sense very well.

With an IR led illuminating and phototransistor IR detector (looks like a black led, has 2 leads) you can detect dark/light very quickly yet still don't make a little dark spot if there's only one, make a wider arc and yes, poll the pin to detect change of state since you may read the spot many times before it passes if your code is fast. You should be able to poll the pin 50+ times a millisecond.

A magnet in an iron or steel wheel... you still detect that? The whole wheel should be magnetized.

There are many types of Hall effect sensors. The cheap ones with digital output are called Hall Switches, Linear Hall Sensors are more expensive and have Analog output to measure field strength.

An Arduino pin in digital mode switches to HIGH at about 2.8V and to LOW at about 1V. If the analog Hall sensor goes from 0 to 3V or more, the pin will make that output digital.

If the tracks have regular spaced ties, do they reflect light better than what's in between?