Arduino/Genuino 101 CurieIMU Step Count Tutorial

This tutorial demonstrates how to make use the 101's on-board accelerometer to act as a pedometer by detecting when a step motion has been made by the board. A function from the CurieImu library is used to detect steps and each iteration of the loop compares the current step count with the previous step count, printing an update when it has been incremented.

Hardware Required

The CurieImu library uses the IMU (accelerometer + gyroscope) built into the Genuino/Arduino 101.

Instructions

  1. Set up the Arduino software (IDE) as described in Getting Started with Arduino 101.
  2. Connect the Arduino/Genuino 101 to your computer.
  3. Launch the Arduino Software (IDE) and select Arduino/Genuino 101 from the Tools > Board menu.
  4. Upload the sketch and open the serial monitor with the baud rate set to 9600 (in the drop-down menu in the bottom right of the console).
  5. Watch the updates to the monitor as you move your 101 board in step-like motions. Since the steps are detected from a significant change in angular velocity, the ankle is an ideal place to strap the 101 board, allowing it to clearly sense each motion of the leg.

The Circuit

image developed using Fritzing.

How it Works

An Interial Monitoring Device (IMU) is composed by an accelerometer and a gyroscope, which measure orientation and angular velocity. The IMU is capable of precisely identify the orientation and the movement of the object to which it is attached after an initial calibration procedure. This example does not need to know the orientation or rotational speed of the board, it only needs the angular velocity, meaning that just the accelerometer of the IMU is used. In this example, the accelerometer detects when there is a significant change in the X, Y, and Z axes' velocity, relative to their resting state and this is interpreted as a step.

The sketch uses the accelerometer and the CurieImu library to detect steps. In setup(), the IMU is initialised and stepDetectionMode is set as the 'normal' mode. This can be changed to sensitive mode or robust mode (consult section 2.7 of the datasheet for more information).

Each iteration of loop() calls the updateStepCount() function, which is a function inside the CurieImu library which detects a siginificant change of the accelerometer's values and increments a counter accordingly. If the value returned by the function differs from lastStepCount, an update is printed to the serial monitor to tell the user how many steps have been counted.

Note that, as stated in the code, by design, the step counter does not immediately update on every step detected. This is because of the algorithm used in step detection which contributes to higher accuracy and reporting latency. Although the step counter will not be updated in hard real-time, it does not take longer than a few seconds before the count is up-to-date. More information can be found in the BMI160 datasheet.

Code

/*
 * Copyright (c) 2015 Intel Corporation.  All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */


/*
 * This sketch example demonstrates how the BMI160 accelerometer on the
 * Intel(R) Curie(TM) module can be used as a Step Counter (pedometer)
 */


#include "CurieImu.h"
int lastStepCount = 0;

void setup() {
  Serial.begin(9600);

  CurieImu.initialize(); // initialise the IMU
  CurieImu.setStepDetectionMode(BMI160_STEP_MODE_NORMAL); // set step detection mode to normal
  CurieImu.setStepCountEnabled(true); // enable step count

  Serial.println("IMU initialisation complete, waiting for events...");
}

void loop() {
  /* we can now check the step count periodically */
  updateStepCount();
  delay(1000);
}

void updateStepCount()
{
  int stepCount = CurieImu.getStepCount(); // set stepCount to read stepCount from function
  if (stepCount != lastStepCount) { // if stepCount has changed
    Serial.print("Step count: "); Serial.println(stepCount);
    lastStepCount = stepCount;
  }
}

See Also

Further information on Genuino/Arduino 101
Getting Started
Arduino 101 CurieIMU Orientation Visualiser Tutorial
Arduino 101 CurieBLE Heart Rate Monitor Tutorial