I bought a manual treadmill recently. The purchase coincides nicely with my continued weight-loss and my plans to experiment with virtual reality when I finally receive my Oculus dev kit. It also happens to be a perfect fit for the IKEA standing desk that I’ve been using for several months.
This particular model of treadmill is a very simple machine. As you might expect, the base is just a board with a couple of rollers and a belt. The front roller includes two small solid iron flywheels and, importantly, a built-in sensor. The sensor connects to a display on the front of the support railings. The display shows the usual time/distance/calorie stats but, since I want to fit the treadmill under my desk, I’ve detached the railings entirely. Removing the railings means that I lose the display but who needs a silly little circuit board when I can just combine the sensor with the full power of my desktop PC :) Luckily, pulling this off is easier than I anticipated.
As it turns out, the sensor is a simple switch that is triggered when a magnet, embedded into one of the flywheels, passes by. This makes it very easy to connect to my Arduino and, with a little bit of code, I am able to turn the periodic switching into a speed reading. The following Arduino code increments a counter every time the switch is triggered and then sends that counter value to the computer over the USB serial port every 200 milliseconds.
Now that I have data from the treadmill streaming into my PC, the fun begins. I use a small Python script to read the treadmill data from the serial port and, borrowing a bit of code (literally one line) from my previous project, I simulate a mouse scroll wheel event on the PC. I’ve written additional code around this core that allows me to visualize and control the rate of scrolling but the basic code is only 30 lines long (including comments!).
So now I have a great source of motivation to keep myself active; Want to keep reading that engrossing article about how Obama hired radical techies to win the election or about how Google’s autonomous car is worth trillions? Better keep walking then! I can also honestly say that I have never been so exhausted after only a few hours of testing and debugging code :)
Update: Throttling the Internet
In response to an idea from reddit I’ve applied the treadmill setup to throttle my Internet connection. The implementation is made trivial thanks to the Throxy Python library. I’ve hacked-in a few lines that change the download throttle dynamically as content is being downloaded in to the browser. I simply run the modified Throxy code and configure Firefox to use the proxy. The faster I walk or run, the faster the content downloads. You can see in the video below that it works for web pages, images and videos as well.