I have a problem with the measurement of the speed of my stationary bike.

enter image description here (also here)


  1. radius of flywheel is 13cm
  2. second wheel is 12cm (0.12m)
  3. the sensor is simply a reed switch

I'm trying to calculate the speed using this formula :

$$\text{angular velocity} = \text{rotation per second (Hz)}\cdot 2\cdot \pi$$

$$\text{speed} = \text{angular velocity}\cdot{0.12}m/s$$

$$\text{speed} =\text{speed} \cdot 3.6 km/h$$

Are my formulas correct? I'm not using a flywheel in this calculation. I'm using an Arduino Mega with Interrupts. The result isn't quite good (output: pastebin.com/V2mtGzmn).

How to do it more acurrately?

The code is here.

  • 1
    \$\begingroup\$ The bike's speed is zero; it's stationary. But really, what about the results is not good? How are you measuring time? \$\endgroup\$ – Samuel Nov 25 '14 at 0:29
  • \$\begingroup\$ With the interrupt - is 1 sec because of 1Hz; I'm comparing the results with the original computer (on the bike) and "speed" is different. On my Arduino is about 5 km/s less... \$\endgroup\$ – user59000 Nov 25 '14 at 0:37
  • \$\begingroup\$ You're measuring the time between the interrupts from the reed switch, presumably these come in different increments than once per second (1Hz), how are you measuring that time? A timer/counter? Converting it to seconds? You're using floating points for doing math? Come on man, help us help you. \$\endgroup\$ – Samuel Nov 25 '14 at 0:45
  • \$\begingroup\$ Of course. Sorry about that. Maybe just look at my code pastebin.com/iq3yR6vN (with comments). Edit: and I'm not using the flywheel - should I ? If yes that how I can use it in this code... ? \$\endgroup\$ – user59000 Nov 25 '14 at 0:54
  • \$\begingroup\$ Can't say for sure what your issue is, how do you know the bike computer isn't the incorrect measure? Also, worth noting, instead of three floating point multiplications you can simply multiply once (Hz*2.9376) = (Hz * (2*pi*0.12*3.6)). It may reduce rounding errors. \$\endgroup\$ – Samuel Nov 25 '14 at 1:06

Your system seems to be working as you've designed it. You're counting in increments of one Hz. So your results make perfect sense.

For your system:

1 Hz = 2.94 km/h

2 Hz = 5.88 km/h

3 hz = 8.82 km/h


If you want more precision, count the milliseconds between each revolution. Your measured revolutions per second (that you're incorrectly calling "angular velocity") value will be 1/(measured seconds), which is in Hertz. Use that value in place of "angular velocity" and you'll likely get the results you're expecting rather than what you've currently designed for.

  • \$\begingroup\$ You mean 1/(measured milliseconds) but Hertz = 1/s. So it will be 1/(measured milliseconds/1000) ? And the rest of code seems to be like: speed = 1/(measured milliseconds/1000.0) * 0.12; speed = speed * 3.6; right? \$\endgroup\$ – user59000 Nov 25 '14 at 3:51
  • \$\begingroup\$ But, for example 1/5000ms * 0.0029376 = 0.00000059 hmm? \$\endgroup\$ – user59000 Nov 25 '14 at 4:07
  • \$\begingroup\$ Yes, fair enough, 1/(measured milliseconds/1000). Or 1/(measured milliseconds) * 2937.6 = speed [km/h] \$\endgroup\$ – Samuel Nov 25 '14 at 16:25
  • \$\begingroup\$ And, Samuel - this is 2712,96 not 2937,6 . \$\endgroup\$ – user59000 Nov 26 '14 at 18:34
  • \$\begingroup\$ Hey, @Samuel - it's still not working well. With this code pastebin.com/17pHZ6wY results are lowest than I was expected - in the console speed is 22, in my program 5 (km/h)... What I'm doing wrong ? If I calculate this with r = 0.06 (half of r - on this distanse reedswtich is mounted) result is e.g. 1,771 when on console 17,7 km/h \$\endgroup\$ – user59000 Dec 10 '14 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy