Project tutorial
Healthy Arduino

Healthy Arduino © TAPR-OHL

DIY real-time footsteps counter using an Arduino to show the number of steps taken per day on your smartphone.

  • 2,828 views
  • 2 comments
  • 17 respects

Components and supplies

Ardgen 101
Arduino 101 & Genuino 101
×1
1434509556 android phone color
Android device
×1
Tens70
9V battery (generic)
×1

Apps and online services

About this project

Sometime ago read an Internet article about number of steps per day for healthy life.

according to it we should take 10000 steps per day for healthy life.

so i am making this easy build project with Arduino 101.

once you power on the arduino and put it inside your pocket or tie it on your arm ,with help of Interial Monitoring Device (IMU) which 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

App inventor based app on your android mobile will keep track of number of steps by user and show it on screen.

Code

HealthyArduino.apkJava
apk file to install app on your smartphone
No preview (download only).
HealthyArduino.aiaJava
In case you want to modify android app , simply import this file to app inventor 2 and edit
No preview (download only).
StepCount1.inoC/C++
Arduino skectch file. dirctly upload to your arduino 101
/*
   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"

/* To get an interrupt notification for every step detected,
    set stepEventsEnabeled to true. Otherwise, the main loop will
    poll for the current step count.

   By design, the step counter does not immediately update on every step detected.
   Please refer to Section 2.7 of the BMI160 IMU SensorData Sheet
   for more information on this feature.
*/
/////////////////////
#include <CurieBLE.h>
BLEPeripheral blePeripheral;//BLE Peripheral Device (Arduino Device)
BLEService demo111("19b10010-e8f2-537e-4f6c-d104768a1214"); // BLE demo111 Service

// BLE demo111 buttons Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic buttons("19b10011-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite);
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensors("19b10012-e8f2-537e-4f6c-d104768a1214", BLERead | BLENotify);
//DHT 22 library and things
//#include "DHT.h"
//#define DHTPIN 7
//#define DHTTYPE DHT22
//DHT dht(DHTPIN, DHTTYPE);

long previousMillis = 0;  // last time the sensor was checked, in ms
const int green = 13; // pin to use for the green light
const int red = 11;// pin to use for the red light
boolean a = LOW, b = LOW; //Control variables

/////////////////////
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);
  //dht.begin();//sensor begin
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  // set advertised local name and service UUID:
  blePeripheral.setLocalName("Demo111");
  blePeripheral.setAdvertisedServiceUuid(demo111.uuid());
  // add service and characteristic:
  blePeripheral.addAttribute(demo111);//service 
  blePeripheral.addAttribute(buttons);// add the buttons characteristic
  blePeripheral.addAttribute(sensors); // add the sensor characteristic
  // set the initial value for the characeristic:
  buttons.setValue(1);
  // begin advertising BLE Light service:
  blePeripheral.begin();
  Serial.println("Demo111 service begin!");
  // 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);
  /////////////////
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();
  digitalWrite(green, LOW);
  digitalWrite(red, LOW);
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the leds:
      if (buttons.written()) {
        if (buttons.value() == '1' && a == LOW) { // 1 in ASCII

          digitalWrite(green, HIGH);         // will turn the LED on
          a = HIGH;
        } else if (buttons.value() == '1' && a == HIGH)  {  //when 1 was read again (second time)          

          digitalWrite(green, LOW);          // will turn the LED off
          a = LOW;
        }

        if (buttons.value() == '2' && b == LOW) { // 2 in ASCII

          digitalWrite(red, HIGH);         // will turn the LED on
          b = HIGH;
        } else if (buttons.value() == '2' && b == HIGH)  { //when 2 was read again (second time)  

          digitalWrite(red, LOW);          // will turn the LED off
          b = LOW;
        }
      }

      long currentMillis = millis();
      // if 10s have passed, check the sensor:
      if (currentMillis - previousMillis >= 10000) {
        previousMillis = currentMillis;
        updateSensor();
      }
      //finish
    }
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
  else
  {
    digitalWrite(green, LOW);
    digitalWrite(red, LOW);

  }
  ////////////////
}

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();
}

void updateSensor() {
  //int temp=dht.readTemperature();//read temperature 
  sensors.setValue(CurieIMU.getStepCount());//send temperature value
  Serial.println(CurieIMU.getStepCount());//if you want check temperature i serial monitor
}

Schematics

Circuit
In this project no extra wiring needed only connect power source to arduino power jack according to pic.
Figure 16   arduino connected to 9 volt battery 2eoty3tab0

Comments

Similar projects you might like

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 10,804 views
  • 26 comments
  • 51 respects

The Hackster.io Kids [Week-1] Report

by Sanyaade Adekoya

  • 1,220 views
  • 2 comments
  • 12 respects

Arduino 101 Home BLE System

Project tutorial by Alexis Santiago Allende

  • 2,424 views
  • 0 comments
  • 11 respects

Arduino 101 BLE RGB Lamp

Project tutorial by Gustavo Reynaga

  • 1,899 views
  • 2 comments
  • 10 respects

Arduino Pokéball

Project tutorial by MarJoh

  • 30,031 views
  • 9 comments
  • 65 respects

The "Mars Rover" Emulator

Project tutorial by MJRoBot

  • 10,161 views
  • 3 comments
  • 49 respects
Add projectSign up / Login