 # Finding X

Hello, I'm working with a motorbike speedometer and it works with hall effect sensor and a magnet in the front wheel. The meter measures time it takes between signals and gives a speed from 0 to 200 km/h.

I'm trying to use this in thing in my sim rig and I have arduino hooked up the signal output. I can generate a signal easily with delay and digitalwrite commands. For example if I make signal with 900ms delay, I get speed of 2km/h. If I take 450ms delay, i get 4km/h in the meter.

My problem is finding the formula that allows arduino to convert speed input from the game to the delay it need to have between signals.

For example, if I have speed of 100km/h whats the delay that I need to use to give me accurate reading on the meter? I tested that its 22ms but how do I get the arduino to calculate that for me?

`v = ω * r` where v = the linear velocity in meters per second, ω is the angular velocity in radians per second, and r is the radius of the wheel in meters. `ω = 2π / T` where T is the period, the time it takes for the wheel to complete one revolution (360° or 2π rad). `v = v* / 3.6` where v* is the linear velocity in kilometer per hour. Combining all this:

``````T/2 = 3.6 * π * r / v*
``````

Where T/2 is half the period of your square wave, i.e. the delay between two digitalWrites.

Pieter

Do you feed your signal to the game and the game tells you speed?

For example if I make signal with 900ms delay, I get speed of 2km/h. If I take 450ms delay, i get 4km/h in the meter... if I have speed of 100km/h whats the delay that I need to use to give me accurate reading on the meter? I tested that its 22ms

Your first two examples are consistent with each other. But the third does not quite match.

For the first two examples, the formula for the delay would be 1800/speed. But for the third example it would be 2200/speed.

I suspect the other parts of your code are affecting the result. At low speeds, this effect is tiny and does not matter. But at high speeds it is affecting the result enough to need different calculation.

Post your code (use code tags!!!) and we can show you how to change the code so that one formula works for all speeds.

The formula 2200/speed is "more correct" than 1800/speed. A delay of 900 milliseconds would give a speed of 2200/900 = 2.4444km/hr which the speedometer presumably truncates to 2km/hr making it look as though the formula should be 1800. If you can find out what delay causes 200km/hr that would be the best value to use but you may have to use delays in microseconds to get the right value (assuming that the relationship is linear).

Pete

Doesn't the tone() function do what you need?

Allan