If you have already burned a few calories cycling with the Android app from our earlier installments, lace up comfortable trainers and give this new use for the same project a try on a treadmill. With the existing hardware, we can detect movement along another axis, count steps and estimate calories burned, speed and the distance covered during a workout. The circuit that tracked a bicycle ride can now accompany a walk—and give us another excuse to experiment with electronics and look after our health.
Android development with App Inventor makes it possible to turn simple hardware like ours into practical projects. In the bicycle version, one axis of the MMA7260Q accelerometer counted pedal strokes. Here, we use another axis to detect the leg’s movement as we walk. This is not a scientific breakthrough, but it is a project we built ourselves and you can reproduce—very much in the hands-on spirit of NeoTeo.
Sports shoes and fitness products often track activity and provide useful measurements. Such tools are particularly valuable to athletes training indoors, where the free apps available through the Android store may not be an option. Commercial apps can store all sorts of statistics and even track weight over time. Our app is much simpler: it has a single screen and is calibrated around my weight, pace and stride. On the treadmill, my stride is a consistent 0.75 metres. I walk briskly rather than running or strolling, and the calculations use my weight as well.
You can adapt the project in App Inventor to suit your own body and exercise routine. Ideally, you could add a menu to change your weight as it decreases and set the distance between steps. That would let you adjust the app over time and share it with others, who could tailor it to their needs. We show you the approach; how far you take it is up to you.
The program’s structure is much like the one used for the bicycle project. At its centre is an event counter that runs at intervals of less than a second. It refreshes the real-time clock, counts steps taken by the leg carrying the accelerometer, and updates calculations as the workout progresses. For instance, Label24.Text displays the step count using a simple multiplication with two decimal places, after which the app calculates calories burned.
A formula commonly found on diet and fitness websites uses a constant that depends on the activity. Swimming and running uphill, for example, do not have the same effect on the body over the same length of time; brisk walking and running on a gym treadmill also require different constants.
One example formula, readily available online, is 0.029 × (2.2 times your weight) × the number of minutes spent walking purposefully. For running, the constant rises to 0.129 while the other factors stay the same. Since my age and fitness no longer allow me to run, but I can walk with plenty of effort, I chose a value close to 0.035.
You might pause for a few minutes and then start again. If the calculation simply used elapsed time, the timer would count the minutes spent chatting beside the treadmill as exercise. That would not do, so the calculation instead uses the speed shown in Label40 during activity. You can choose a constant suited to your usual workout, or add a menu for selecting the day’s activity. In this example, distance divided by the displayed speed gives the workout time. Multiplying 2.2 by my 86 kilograms and by the 0.035 constant for energetic walking produces the 6.66 shown at the end of the calculation.
The blue Pause button stops all readings and turns them grey. To resume, press and hold the same button using Pause.LongClick. Reset returns every value to zero so you can begin a fresh session—handy when, as often happens at the gym, a conversation delays the start. The real-time clock turns light blue when it detects the Bluetooth connection. The workout timer then stands out as a reminder of the effort you are putting into staying healthy.
The hardware is the same setup used for the bicycle app. We amplify the accelerometer’s movement pulses and feed them to a PIC 18F25K20, which sends a byte to the App Inventor app over Bluetooth. The change, as the video shows, is that we use a different accelerometer axis. After reviewing the previous article, you will see that the hardware needs no other changes apart from adding an amplifier stage like the one used for the first axis.
For this preparation stage—yes, preparation; the project is not finished yet—we use the same LM358 amplifier connected to the new axis. The PIC software is unchanged from the bicycle project: it receives the pulse data and transmits it over Bluetooth. The app is available below for you to download and upload to your App Inventor workspace. The procedure is the same as before: upload the file without unzipping it, make any changes you like, then download the app to your phone. Enjoy!
App Inventor project file: Download
APK application file: Download