These days everyone is keen when it comes to health. So we present a simple and cheap pedometer device, which available for any person to wear during running exercise or daily activities. The benefit of using such a device is mostly the improvement in motivation to increase physical activity.
How I build it:I used (H0BR40) Hexabitz IMU and Digital Compass module to detect steps and four (H01R00) Hexabitz RGB LED module to present steps counts and two (H04R20) serial battery.
I connected modules like image below
The RGB LEDs will work like the following steps:
- When IMU module detect step at first it will send message to RGB LED 1 module to blink in red.
- When steps reach 50 steps the IMU module will send message to RGB LED 1 module to light in red.
- After that the IMU module will send message to RGB LED 2 module to blink in red every step between 50 and 100 steps.
- When steps reach 100 steps the IMU module will send message to RGB LED 2 module to light in red.
- The process will repeat for every RGB LED module till reach 300 steps, then it will repeat.
This way will help the user to know the number of steps.
Algorithm:This code implements a step counting algorithm using X, Y, Z accelerometer data.
As you can see the IMU module will control the whole process, so I didn't change RGB LEDs firmware.
Code:/*-----------------------------------------------------------*/
/* User Task */
void UserTask(void * argument)
{
float threshold = 2;
float xval;
float yval;
float zval;
float xavg;
float yavg;
float zavg;
int x=0;
float vector;
float vectorLastValue=0.0;
float average;
long steps=0;
int oneTimeTaskFlag=0;
BOS.trace=BOS_RESPONSE_NONE;
/* Infinite loop */
for(;;)
{
/*
Calibration:
By getting the average values for 100 sample of each accelerometer sensor axis.
This step run just for one time when powering the module.
*/
if(oneTimeTaskFlag==0)
{
float sum=0;
float sum1=0;
float sum2=0;
for (int i=0;i<100;i++)
{
SampleAccG(&xval, &yval, &zval);
sum=xval+sum;
sum1= yval+sum1;
sum2=zval+sum2;
}
xavg=sum/100.0;
yavg=sum1/100.0;
zavg=sum2/100.0;
oneTimeTaskFlag = 1;
}
/*
Getting x, y and z axis value and find how each axis is far from average value.
By calculate the total acceleration vector with respect to average value
vector=SQRT((x-xavg)^2+(y-yavg)^2+(z-zavg)^2)
*/
SampleAccG(&xval, &yval, &zval);
vector = sqrt(((xval-xavg)* (xval-xavg))+ ((yval- yavg)*(yval-yavg)) + ((zval-zavg)*(zval-zavg)));
Delay_ms(1);
//Find the average value between current vector and last vector.
average = (vector + vectorLastValue)/2;
vectorLastValue = vector;
if(average>threshold )
{
messageParams[0]=1;
messageParams[1]=200;
messageParams[2]=0;
messageParams[3]=0;
messageParams[4]=50;
//Make indicator LED blink every step
//Module 2
if((steps>=0) && (steps<49))
{
SendMessageToModule(2, 103, 5);
Delay_ms(50);
SendMessageToModule(2, 101, 0);
}
//Module 3
else if((steps>=51) && (steps<99))
{
SendMessageToModule(3, 103, 5);
Delay_ms(50);
SendMessageToModule(3, 101, 0);
}
//Module 4
else if((steps>=101) && (steps<149))
{
SendMessageToModule(4, 103, 5);
Delay_ms(50);
SendMessageToModule(4, 101, 0);
}
//Module 5
else if((steps>=151) && (steps<199))
{
SendMessageToModule(5, 103, 5);
Delay_ms(50);
SendMessageToModule(5, 101, 0);
}
steps=steps+1;
}
Delay_ms(2);
messageParams[0]=1;
messageParams[1]=200;
messageParams[2]=0;
messageParams[3]=0;
messageParams[4]=50;
//Turn on module x every 100 steps
switch (steps)
{
case 50:
SendMessageToModule(2, 103, 5);
break;
case 100:
SendMessageToModule(3, 103, 5);
break;
case 150:
SendMessageToModule(4, 103, 5);
break;
case 200:
SendMessageToModule(5, 103, 5);
break;
}
if(steps>= 201)
{
SendMessageToModule(BOS_BROADCAST, 101,0);
steps=0;
x=x+50;
if(x>155)
{
x=0;
}
}
}
}
/*-----------------------------------------------------------*/
Clone IMU H0BR40 module firmware from Hixabitz website. I edited firmware using Keil uVision. I opened “main.c” file and I put my code in “user task” section.
Final step:Solid all modules to suitable your bracelet design. I powered bracelet by 3.3V lithium battery.
Comments
Please log in or sign up to comment.