Calculating speed from millis()

Hi All,

I have an object that is 9in's in diameter (which is 228.6mm), I'm trying to calculate the speed (mph and kph) of the object for the duration of a laser trip, but I'm struggling with the maths.

The object is likely to trip the laser for between 0.5 or 1 sec, but every time I do the maths and that would be somewhere in the region of 600mph, which I know is wrong, can anyone help me with the math to calculate mph (or kph) of an object 9ins which will trip the laser for x milliseconds,

Thanks in advance,

Cheers

Carl

diameter in meters / time in seconds = m/s

(230mm = .23m, of course)

Then m/s x 3600 gives m/h

And divide by 1000 to give km/h

So bottom line, speed in km/h is diam x 3.6 / seconds.

EDIT.... always assuming the beam is a radius up from the surface so it actually measures a diameter....

Hi JimboZA,

Thanks for the answer, to make sure I've done this 100%;

.23 / 0.5 = 0.46 (.23m, 0.5secs)
0.46 x 3600 = 1656
1656 / 1000 = 1.656 kph

Thanks for the help

To simplify a little, if you give the length "l" in mm and the time "t" in ms, the speed "l/t" will come out in m/s anyway, because the millimeters cancel out the milliseconds. So all you need to do then is convert to kph by multiplying by 3600/1000 or 36/10. But to avoid integer maths loosing the decimal places, use ((l * 36) / t) / 10.0. This keeps the calculations in integers until that last divide, which is much faster than using floating point calculations from the start. Floating point calculations take a long time for an Arduino, as its all don e in software, there is no floating point hardware like in PC CPUs.

So your answer comes out as ((230 * 36) / 500) / 10.0 = 1.6 kph

But there is the assumption that the object (circle?) trips the laser for the max diameter - at height 4.5"
If the laser is tripped a lower or higher it is tripped shorter resulting in a higher speed.

example if the laser is tripped at height 6" (1/3 above the middle height) then the width that trips is
sin(arccos(1/3)) * max diameter = 0.94 * 9" = 8.5" (> 5% diff)

if the laser is tripped at height 7.5 (2/3 above)
sin(arccos(2/3)) * max dia = 0.74 * 9"= 6.7" (> 25% diff)

Yes, we can only take the OP's word for it that the length is 230mm at the point it blocks the laser beam.

PaulRB:
Yes, we can only take the OP's word for it that the length is 230mm at the point it blocks the laser beam.

The calculations shows that if the beam is broken + or - 1.5" (~3.75 cm) around the max diameter
the error margin is less than (9-8.5)/9 ==> Less 6%

That means there is only a small error if the laser is not aligned perfectly
(assumption) one should be able to align the laser within +- 0.5" ==> 1/6 diameter so the max error is about
sin(arccos(1/6)) * max diameter = 0.986 * 9" = 8.87" (max 1.4%)