Stationary bike speedometer with Arduino and reed switch

The first step in actually building my Bike Mountain Project was to acquire a stationary bike and figure out how to build a speedometer into it.

Conveniently, there’s an ancient exercise bike that sits in the ITP pcomp lab — supposedly it belonged to Red in the 70s. When I found it, the bike was highly encrusted with the residue of years of student projects, the most recent of which seemed to have been for power generation. I spent an afternoon sweeping these remnants away. Here it is before (left) and after (right):

Bike Mountain big Bike left side
Cleaned up stationary bike

I also managed to reattach the handlebars:

70s stationary bike with handlebars reattached

Once I had the bike rideable again, I started working on detecting the motion of its wheel. The basic approach (suggested by Dan-o) is to attach a magnet to the wheel and then detect when it passes by a fixed point. There are a couple of sensors for detecting the proximity of magnets, principally the reed switch and the hall effect sensor. The reed switch is the simpler of the two and a fellow student happened to have one on the floor so I started off working with one of those.

Reed switches contain two pieces of metal that touch each other when in the presence of a magnetic field; when the metal makes contact, it completes a switch, allowing you to detect whether the magnet is nearby. Here’s a picture of a reed switch hooked up to the Arduino:

Reed switch circuit

And here’s a video of the reed switch in action, detecting a stack of magnets (watch for the built-in LED to light up when the magnet comes nearby):

Once I had the reed switch working and the bike cleaned up, I started work on putting the two together. I attached two of the magnets to the rim of the bike’s wheel with some double stick tape and then lined up the arduino and circuit to place the reed switch as close as possible to the spot the magnets passed by.

Arduino detecting magnet with reed switch

Once I had the circuit placed so that it was detecting the magnets properly, I tweaked my Arduino program so that it would calculate the bike’s RPMs based on how frequently it saw the magnet go by (see the code at the bottom of this post). There are a number of things I could do to make this code more robust (like adding edge detection rather than a simple time margin to prevent multiple detections on a single pass and building the average out of more than just two consecutive samples), but for now this is good enough to get started — especially since I ordered some hall effect sensors that provide analog values and are more sensitive to the presence of the magnet. If I end up swapping in the hall effect sensor for the reed switch, the code will have to change somewhat but the basic algorithm will remain the same.

Finally, here’s a video of the whole thing in action, showing the magnet swinging by, the Arduino’s LED lighting up to demonstrate detection, and then the output in the Arduino serial terminal showing the running RPM calculation.

The next steps going forward will be to translate this RPM number into distance traveled by measuring the circumference of the bike’s wheel. Then, that number can be used to calculate Miles Per Hour and hence control the movement of a stepper motor which will move the bike up the mountain.

Also, I want to possibly do something to improve the movement of the bike’s wheel. Right now, it has a free wheel on the front which means that once you get up to speed the bike becomes far too easy to pedal. A bike expert friend here suggested taking the wheel into a bike shop and asking them to add a fixed gear to it in order to make the bike more of a challenge to pedal.

This entry was posted in Opinion. Bookmark the permalink.

9 Responses to Stationary bike speedometer with Arduino and reed switch

  1. Jem says:

    Old exercise bikes usually slow down that wheel with a friction device, often a big-handled screw you can turn to increase tension. That can make it very hard to pedal.

  2. pretty innovative project man, great diy…

  3. Josh says:

    Wanted to say thanks for posting this. I had the same idea, came across your design, and managed to work it into a system to require certain RPMs to maintain video playback. Had a lot of fun with the project. If you’d like to see my results, see here: http://idkfa.com/ec/the-bike/

  4. Andromorfo says:

    hey man thanks for the info, after reading this i did something similar
    http://randomize.idomyweb.com/index.php?p=53

    i´m looking forward to make a computer game or interfacing the bike with some existing game, like GTA SA or something similar.

    P.D.-Sorry for the bad english LOL

  5. sadex says:

    Could someone show the the program of this project?

  6. tieqah says:

    can you give me a program for my reference,please?

  7. alma says:

    Hi

    I was wondering if you could share the code?

    Thanx

  8. You can use the sample code for the button that’s included with arduino just change the analog port variable to your reed switch port.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>