Group 7: Track Your Action

Introduction

For our group project we began to discuss our different options and the endless possibilities with Arduino. We wanted to create something that would be of use to the person in their daily life.

So we began to narrow down our options into creating a device that tracks a user’s activity. We looked around at different apps out there such as ‘Pacer’ that tells a user how many steps they take but doesn’t necessarily break down the timings. Therefore, our aim for our project was to create a device that tells the user on a visual interface their level of activity and how long they were walking, standing or sitting for during the day.

Brainstorm

fullsizerender-2

Research

When we had decided our aim for the project we then did some research specifically into the design and functionality of the device. We looked at the current market to see what lacked and how we could produce something that would satisfy the user. Therefore, we concentrated on making the arduino be able to detect the timings of activeness throughout the day onto the serial monitor. We also made sure the design of the visual interface was appealing to the user, since the user would check this daily several times in order to see their progress. Before we went into making the design we looked at several different designs from current apps that are already out there and took the positive factors and discarded what we thought didn’t work. We realised making it minimal and very clear to read was the most important point as the user will just want a simplistic design that is quick and easy to read since they want instant gratification.

 

Project Plan 

We began by meeting often throughout the week to discuss ideas, design the device, and work on the code together. We all were delegated particular tasks at each stage, and met each other when we seeked help.

Please See Below for:  November & December gantt chart.

gantt-chart

gantt-chart-2

 

 

Task List

  • Began Discussing Ideas
  • Brainstorming Methods & Techniques
  • Created Design Interface
  • Ordered Components
  • Soldering Components
  • Began Pseudo Code
  • Gathered Components Together
  • Made Test Code
  • Ran Code & Tested Device
  • Fixed Any Errors

 

Design

artboard-6  artboard-8  artboard-7

This was the design we had worked on to go on the LCD screen and we focused on 3 elements whilst keeping the screen clean and minimal as possible. We had an: activity bar, information and an icon. The activity bar was at the bottom and measured if the user was highly active, inactive or mediocre. The information would tell the user how long they had been in their current action since their last state. The image would further reinforce their state of action to help the user visualise their movement or lack of movement.

 

Shortcoming

 

Maker Manual

Components:  

  • LSM303DLHC Accelerometer                       
  • Force Sensor
  • 3x 10k Ohm Resistors
  • Wire
  • Breadboard
  • Arduino UNO Board

wearable_bb

Libraries you need:

Adafruit LSM303DLHC

 

 

Integrated Code (no screen)-

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
float X1;
float X2;
float DvalX;
int walk = 0;
int stand = 0;
int walkingtime = 0;
const int FSR_PIN = A0;
int sitTimeAll = 0;
int sitTimeNow = 0;
int leavingTime = 0;

/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(“Accelerometer Test”); Serial.println(“”);

/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL345 … check your connections */
Serial.println(“Ooops, no LSM303 detected … Check your wiring!”);
while(1);
}
pinMode(FSR_PIN, INPUT);

}

void loop() {
// put your main code here, to run repeatedly:
int fsrADC = analogRead(FSR_PIN);
if(fsrADC !=0){
sittingdetect(fsrADC);
}else if(fsrADC == 0 && leavingTime !=0){
sittingdetect(fsrADC);
}else{
detectXaxis();
Serial.println(“Walking Time:”);Serial.print(walkingtime);Serial.println(“s”);
Serial.println();
}

}

void detectXaxis(){
sensors_event_t event;
accel.getEvent(&event);

X1 = event.acceleration.x;
delay(300);
accel.getEvent(&event);
X2 = event.acceleration.x;
DvalX = X1 – X2;
Serial.println(DvalX);

if(DvalX >= 1.30 || DvalX <= -1.30){
if(stand > 0){
stand–;
}

if(walk >= 0 && walk < 5){
walk++;
}

if(walk < 5 && stand > 0){
Serial.println(“standing”);
Serial.println();
delay(700);
}else if(walk > 0 || stand == 0){
walkingtime++;
Serial.println(“Walking”);
Serial.println();
delay(700);
}
}

if(DvalX <= 1.30 && DvalX >= -1.30){
if(walk > 0){
walk–;
}

if(stand >= 0 && stand < 5){
stand++;
}

if(stand < 5 && walk > 0){
walkingtime++;
Serial.println(“walking”);
Serial.println();
delay(700);
}else if(stand > 0 || walk == 0){
Serial.println(“Standing”);
Serial.println();
delay(700);
}
}
/*Serial.println(DvalX);
Serial.println();
delay(700);*/
}

void sittingdetect(int sitting)
{
if(sitting >=800){
sitTimeAll++;
sitTimeNow++;
leavingTime = 10;
Serial.println(“Sitting”);
Serial.print(“Sitting Time:”);Serial.print(sitTimeNow);Serial.print(” s”);
Serial.println();
if(sitTimeNow >=10){
Serial.print(“Please stand up and move your body.”);
Serial.println();
}
Serial.println();
delay(2000);
}

if(sitting <=800){
leavingTime–;
if(leavingTime > 0){
Serial.println(“Leaving”);
Serial.println();
delay(1000);
}

if(leavingTime <= 0){
Serial.println(“Standing”);
Serial.println();
sitTimeNow = 0;
delay(1000);
}
/*Serial.println(“Standing”);
Serial.println(leavingTime);
Serial.println();
delay(1000);*/
}
}

 

 

 

Integrated Code (with TFT screen)-

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <SPI.h>
#include <SD.h>
#include <TFT.h>
#define sd_cs 4
#define lcd_cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(lcd_cs, dc, rst);
PImage stage1;
PImage stage2;
PImage stage3;
PImage stage4;
PImage sitting;
PImage standing;
PImage walking1;
PImage walking2; 
float X1;
float X2;
float DvalX;
int walk = 0;
int stand = 0;
int walkingtime = 0;
const int FSR_PIN = A0;
int sitTimeAll = 0;
int sitTimeNow = 0;
int leavingTime = 0;
/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println(“Accelerometer Test”); Serial.println(“”);
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 … check your connections */
    Serial.println(“Ooops, no LSM303 detected … Check your wiring!”);
    while(1);
  }
  pinMode(FSR_PIN, INPUT);
  
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
 
  TFTscreen.println();
  TFTscreen.println(F(“Arduino TFT Bitmap Example”));
  TFTscreen.println(F(“Open serial monitor”));
  TFTscreen.println(F(“to run the sketch”));
  Serial.begin(9600);
  while (!Serial) {
  }
  // clear the GLCD screen before starting
  TFTscreen.background(0, 0, 0);
  // try to access the SD card. If that fails (e.g.
  // no card present), the setup process will stop.
  Serial.print(F(“Initializing SD card…”));
  if (!SD.begin(sd_cs)) {
    Serial.println(F(“failed!”));
    return;
  }
  Serial.println(F(“OK!”));
  // initialize and clear the GLCD screen
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.setTextSize(2);
  // now that the SD card can be access, try to load the
  // image file.
  standing = TFTscreen.loadImage(“standing.bmp”);
  walking1 = TFTscreen.loadImage(“walking1.bmp”);
  walking2 = TFTscreen.loadImage(“walking2.bmp”);
  sitting = TFTscreen.loadImage(“sitting.bmp”);
}
void loop() {
  // put your main code here, to run repeatedly:
  int fsrADC = analogRead(FSR_PIN);
  if(fsrADC !=0){
    sittingdetect(fsrADC);
  }else if(fsrADC == 0 && leavingTime !=0){
    sittingdetect(fsrADC);
  }else{
    detectXaxis();
  }
  displayTimerRead (walkingtime);
}
void detectXaxis(){
  sensors_event_t event;
  accel.getEvent(&event);
  X1 = event.acceleration.x;
  delay(300);
  accel.getEvent(&event);
  X2 = event.acceleration.x;
  DvalX = X1 – X2;
  //Serial.println(DvalX);
  if(DvalX >= 1.30 || DvalX <= -1.30){
    if(stand > 0){
      stand–;
    }
    if(walk >= 0 && walk < 5){
      walk++;
    }
    if(walk < 5 && stand > 0){
      //Serial.println(“standing”);
      //Serial.println();
      displayStandingIcon();
      delay(700);
    }else if(walk > 0 || stand == 0){
      walkingtime++;
      //Serial.println(“Walking”);
      //Serial.println();
      displayWalkingIcon(700);
    }
  }
  if(DvalX <= 1.30 && DvalX >= -1.30){
    if(walk > 0){
      walk–;
    }
    if(stand >= 0 && stand < 5){
      stand++;
    }
    if(stand < 5 && walk > 0){
      walkingtime++;
      //Serial.println(“walking”);
      //Serial.println();
      displayWalkingIcon(700);
    }else if(stand > 0 || walk == 0){
      //Serial.println(“Standing”);
      //Serial.println();
      displayStandingIcon();
      delay(700);
    }
  }
  /*Serial.println(DvalX);
  Serial.println();
  delay(700);*/
}
void sittingdetect(int sitting){
  if(sitting >=800){
    sitTimeAll++;
    sitTimeNow++;
    leavingTime = 7;
    displaySittingIcon();
    //Serial.println(“Sitting”);
    //Serial.print(“Sitting Time:”);Serial.print(sitTimeNow);Serial.print(” s”);
    //Serial.println();
    if(sitTimeNow >=10){
      //Serial.print(“Please stand up and move your body.”);
      //Serial.println();
    }
    //Serial.println();
    delay(1000);
  }
  if(sitting <=800){
    leavingTime–;
    if(leavingTime > 0){
      //Serial.println(“Leaving”);
      //Serial.println();
      delay(1000);
    }
    if(leavingTime <= 0){
      //Serial.println(“Standing”);
      //Serial.println();
      sitTimeNow = 0;
      delay(1000);
    }
    /*Serial.println(“Standing”);
    Serial.println(leavingTime);
    Serial.println();
    delay(1000);*/
  }
}
void displayStandingIcon() {
    TFTscreen.image(standing, 0, 0);
    char standingText[] = {“Standing”};
    TFTscreen.stroke(255, 255, 255);
    TFTscreen.text(standingText, 60, 20);
  }
  
void displayWalkingIcon(int i) {
    
    //Serial.println(“drawing image”);
    
    TFTscreen.image(walking1, 0, 0);
    delay(i/2);
    TFTscreen.image(walking2, 0, 0);
    delay(i/2);
    
    char walkingText[] = {“Walking”};
    TFTscreen.stroke(255, 255, 255);
    TFTscreen.text(walkingText, 70, 20);
  }
  
void displaySittingIcon() {
    TFTscreen.image(sitting, 0, 0);
    char sittingText[] = {“Sitting”};
    TFTscreen.stroke(255, 255, 255);
    TFTscreen.text(sittingText, 70, 20);
  }
  
void displayTimerRead (int i) {
  
  int timerVal = i;
  String timerString = String(timerVal);
  char timerPrintOut = timerVal + “0”;
  timerString.toCharArray(timerPrintOut, 3);
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.text(timerPrintOut, 100, 0);
  TFTscreen.text(“s”, 140, 0);
  }

 

 

 

 

 

Code For Moving Detection

 

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
float X1;
float X2;
float DvalX;
int walk = 0;
int stand = 0;
int walkingtime = 0;
/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println(“Accelerometer Test”); Serial.println(“”);
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 … check your connections */
    Serial.println(“Ooops, no LSM303 detected … Check your wiring!”);
    while(1);
  }
}
void loop() {
  // put your main code here, to run repeatedly:
  detectXaxis();
  Serial.println(walkingtime);
  Serial.println();
}
void detectXaxis(){
  sensors_event_t event;
  accel.getEvent(&event);
  X1 = event.acceleration.x;
  delay(300);
  accel.getEvent(&event);
  X2 = event.acceleration.x;
  DvalX = X1 – X2;
  Serial.println(DvalX);
  if(DvalX >= 1.30 || DvalX <= -1.30){
    if(stand > 0){
      stand–;
    }
    if(walk >= 0 && walk < 5){
      walk++;
    }
    if(walk < 5 && stand > 0){
      Serial.println(“standing”);
      Serial.println();
      delay(700);
    }else if(walk > 0 || stand == 0){
      walkingtime++;
      Serial.println(“Walking”);
      Serial.println();
      delay(700);
    }
  }
  if(DvalX <= 1.30 && DvalX >= -1.30){
    if(walk > 0){
      walk–;
    }
    if(stand >= 0 && stand < 5){
      stand++;
    }
    if(stand < 5 && walk > 0){
      walkingtime++;
      Serial.println(“walking”);
      Serial.println();
      delay(700);
    }else if(stand > 0 || walk == 0){
      Serial.println(“Standing”);
      Serial.println();
      delay(700);
    }
  }
  /*Serial.println(DvalX);
  Serial.println();
  delay(700);*/
}
Code For Sitting Detection
const int FSR_PIN = A0;
int sitTimeAll = 0;
int sitTimeNow = 0;
int leavingTime = 0;void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(FSR_PIN, INPUT);
}void loop() {
// put your main code here, to run repeatedly:
int fsrADC = analogRead(FSR_PIN);
sittingdetect(fsrADC);
}void sittingdetect(int sitting)
{
if(sitting >=800){
sitTimeAll++;
sitTimeNow++;
leavingTime = 10;
Serial.println(“Sitting”);
Serial.print(“Sitting Time:”);Serial.print(sitTimeNow);Serial.print(” s”);
Serial.println();
if(sitTimeNow >=10){
Serial.print(“Please stand up and move your body.”);
Serial.println();
}
Serial.println();
delay(1000);
}if(sitting <=800){
leavingTime–;
if(leavingTime > 0){
Serial.println(“Leaving”);
Serial.println();
delay(1000);
}

if(leavingTime <= 0){
Serial.println(“Standing”);
Serial.println();
sitTimeNow = 0;
delay(1000);
}
/*Serial.println(“Standing”);
Serial.println(leavingTime);
Serial.println();
delay(1000);*/
}
}

Leave a Reply