Arduino 101 Step Counter
This is a simple step counter to keep track of steps a user makes since the program is initialized. It is made using the IMU sensors of the Arduino 101. This allows the step counter to have a clean, circuit-less, and clutter-less design!!!
A unique feature of the Arduino 101 that sets it apart from all other Arduino boards in the market is it's built-in IMU sensors, which includes a 3 axis accelerometer and gyroscope. In addition to hardware support, Intel (who made the Curie chip for the board) included software support with it's CurieIMU library. Thus, making programming and using the IMU on the board much simpler and easier than standard IMU's on the market.
All that is needed to get this going is to upload the code, connect a battery source, and strap it in and you are good to go!
BoM
- Arduino 101 [It must be a 101, not any other Arduino models]
- Strap (shoe string or velcro works great)
- Battery holder
- 4 AA batteries
Strapping the Arduino
- Insert the ends of the shoe string onto the screw holes of the Arduino. It will automatically lock into place when you pull on the string, since part of the aglet will be holding onto the board.
- Place the plastic end of the battery holder underneath the Arduino and wrap the excess string around it, to secure it, until there is only enough string to strap on your wrist like a bracelet.
- Test drive it on your wrist and see how well it fits, you may have to do some adjustments to find a good length for your size wrist.
Coding
The CurieIMU library has a built in calibrated and filtered value for detecting steps, so all we need to setup is the interrupt callback whenever a step is detected to count up by one. Also, the built-in LED on the Arduino's pin 13 is used to indicated whenever a step is detected by the Arduino 101 board.
Paste the following code to the ArduinoIDE and upload it to the Arduino 101 board through a standard printer cable (which came with the board). Once uploading is complete, unplug it.
#include "CurieIMU.h"<br>
const int ledPin = 13;
boolean stepEventsEnabeled = true; // whether you're polling or using events long lastStepCount = 0; // step count on previous polling check boolean blinkState = false; // state of the LED
void setup() { Serial.begin(9600); // initialize Serial communication while(!Serial) ; // wait for serial port to connect. // pinMode(13, OUTPUT); // intialize the sensor: CurieIMU.begin(); // turn on step detection mode: CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL); // enable step counting: CurieIMU.setStepCountEnabled(true);
if (stepEventsEnabeled) { // attach the eventCallback function as the // step event handler: CurieIMU.attachInterrupt(eventCallback); CurieIMU.interrupts(CURIE_IMU_STEP); // turn on step detection
Serial.println("IMU initialisation complete, waiting for events..."); } }
void loop() { /* Instead of using step detection event notifications, we can check the step count periodically */ if (!stepEventsEnabeled) { updateStepCount(); } digitalWrite(13, blinkState); blinkState = !blinkState; delay(1000); }
static void updateStepCount() { // get the step count: int stepCount = CurieIMU.getStepCount();
// if the step count has changed, print it: if (stepCount != lastStepCount) { Serial.print("Step count: "); Serial.println(stepCount); // save the current count for comparison next check: lastStepCount = stepCount; } }
static void eventCallback(void) { if (CurieIMU.stepsDetected()) updateStepCount(); }
[Credits to Intel Corporation]
Run Forrest, Run!
- Strap the Arduino onto your wrist and plug in the barrel jack connector from the battery holder to the Arduino board to power it up. That's it, done!
Now, let's get some exercise. Run Forrest, Run!!! You'll be surprised how much (or how little) you walk on a daily basis!
[Alternatively, you can always keep the Arduino in a plastic bag in your pocket, if you want a less 'nerdy' style, but that's boring!]