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):
I also managed to reattach the handlebars:
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:
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.
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.