Skip to main content

Quick Tutorial with Pedometer


For a better start i'm gonna go through some points

  • Arduino uno(with connecting cable)
  • Accelerometer
  • Jumper Cables
  • Bouth & Pb(since i,m a chemistry student)

                                                              Ok here we go!

 I hope you all familiar with what above mention with the points. If not quickly follow me whatever the social media i mentioned in my blog i'm willing to help you.

First of all i would like to introduce Arduino Uno here. This is a simple picture of it.

as i mention in the picture arduino uno consists with digital pins & power pins.

Accelerometer is the sensor what we going to work with now.It will look like this.
    in this picture it's just a sensor with holes. to fill with that up you gonna need headers(male/female).


Probably now you need your bouth & Pb here to assemble these two things

Right after assembling place it on the dry place to acquire some cool on the board(PS- these sensors don't have any HEATSINKS inbuilt.

Now we need to go on with jumper cables to assemble with Accelerometer. Your jumper cable should like this.


If it's messy like this you need go with your own & find male to female cables.
Now we going to connect our sensor with jumper cables. FYI if your sensor has 8 headers to connect that doesn't mean you need to connect that all to get the correct readings.



In this case you only need to connect 5 headers in order to get the readings. For that you need to have 5 male to female jumper cables with different colors. As in the photo you need to connect it to sensor. if'not it will get crashed or fire up.
Then we need to connect it into Arduino Board. Rather than saying pin names to connect i know you all not familiar with these things so in case of that follow the color coordinates to continue with process. I you want follow the pin names I'll provide it.




Follow the color cordinates

                                                                 Here to go above



                                                               Ground pin is here(Grey)



                                         Purple  Black White Brown & Grey in on GRD side



                                                               View from the above



                                                                 Pin Connecting



You need to have Arduino Uno compiler installed on your computer.Apart from that select the com port with tools on arduino uno complier.

Right after the connecting our sensor and arduino into the computer. That will show up the red lights on the sensor and on the other hand Green light on the Arduino Board.




Ok! Guys here is the code to compile and save it on you computer(compiler)



//first calibrate on powering up the module
//a poscal function to calculate avg values of x , y , z and print them on serial
//turn on the LED on pin13 and turn it off after the calibration is completed
//in loop continually read the data and calculate total accerelation vector
//call stepdetect function
//print total number of steps on monitor
//if step occurs flash led 3 times
const int xpin=A2;
int ypin=A3;
int zpin=A4;
int powerpin=A0;
int gnd=A1;
float threshhold=80.0;
float xval[100]={0};
float yval[100]={0};
float zval[100]={0};
float xavg;
float yavg;
float zavg;

int steps,flag=0;
void setup()
{
Serial.begin(9600);
pinMode(powerpin,OUTPUT);
pinMode(gnd,OUTPUT);
digitalWrite(powerpin,HIGH);
digitalWrite(gnd,LOW);
pinMode(13,OUTPUT);
calibrate();
}
void loop()
{
  int acc=0;
  float totvect[100]={0};
  float totave[100]={0};
  //float sum1,sum2,sum3=0;
  float xaccl[100]={0};
  float yaccl[100]={0};
  float zaccl[100]={0};
  // float x,y,z;
for (int i=0;i<100;i++)
{
xaccl[i]=float(analogRead(xpin));
delay(1);
//delay(100);
//x=sum1/100.0;
//Serial.println(xavg);
yaccl[i]=float(analogRead(ypin));
delay(1);
//sum2=yaccl[i]+sum2;
//y=sum2/100.0;
//Serial.println(yavg);
//delay(100);
zaccl[i]=float(analogRead(zpin));
delay(1);
//sum3=zaccl[i]+sum3;
//z=sum3/100;
 totvect[i] = sqrt(((xaccl[i]-xavg)* (xaccl[i]-xavg))+ ((yaccl[i] - yavg)*(yaccl[i] - yavg)) + ((zval[i] - zavg)*(zval[i] - zavg)));
 totave[i] = (totvect[i] + totvect[i-1]) / 2 ;
 //acc=acc+totave[i];
 Serial.println(totave[i]);
 delay(200);
//cal steps
if (totave[i]>threshhold && flag==0)
{
  steps=steps+1;
  flag=1;
}
 else if (totave[i] > threshhold && flag==1)
{
//do nothing
}
  if (totave[i] <threshhold  && flag==1)
  {flag=0;}
  Serial.println('\n');
  Serial.print("steps=");
  Serial.println(steps);
}
//float tim=acc/100;
//Serial.println(tim);
 delay(1000);
// stepcal(totave);
}
/*void stepcal(float arr[100])
{
// int threshhold=80;
 float jack=0;
//delay(100)
//Serial.println(xavg);
for (int i=0;i<100;i++)
{
jack=jack+arr[i];
}
float m=jack/100;
//Serial.println(yavg);
//delay(100);
 //detect pushups or count  for number of dumbles
 //crossing the threshold and
 //cross 20 in down and 80 in up
 /*add one to counter and set a flag high to indicate it is above a threshhold value
if a flag is high and threshhold is crossed :do nothing }
if signal falls below threshhold set flag to -1 indicating it is blow threshhold

if (m>threshhold && flag==0)
{
  steps=steps+1;
  flag=1;
  Serial.println('\n');
  Serial.print("steps=");
  Serial.println(steps);
}
else if (m > threshhold && flag==1)
{
//do nothing
}
  if (m <threshhold  && flag==1)
  {flag=0;}
  Serial.println('\n');
  Serial.print("steps=");
  Serial.println(steps);
}  */

//calculate total accerelation vector
void calibrate()
{
  digitalWrite(13,HIGH);
  float sum=0;
  float sum1=0;
  float sum2=0;
for (int i=0;i<100;i++)
{
xval[i]=float(analogRead(xpin));
sum=xval[i]+sum;
}
delay(100);
xavg=sum/100.0;
Serial.println(xavg);
for (int j=0;j<100;j++)
{
xval[j]=float(analogRead(xpin));
sum1=xval[j]+sum1;
}
yavg=sum1/100.0;
Serial.println(yavg);
delay(100);
for (int i=0;i<100;i++)
{
zval[i]=float(analogRead(zpin));
sum2=zval[i]+sum2;
}
zavg=sum2/100.0;
delay(100);
Serial.println(zavg);
digitalWrite(13,LOW);
}



Right after the Execution of the code go for serail mointor and it will show the readings.



Make sure you have to Move your sensor in order to get the readings.






                                                          Because what it does
"IT'S COUNTING YOUR STEPS" .if you are too lazy you will stay on the Steps=1 FOREVER.




                                                                         -ThilanJR10-

Comments

Post a Comment

Popular posts from this blog

Data Compression- Run Length Encoding

Hello Again!! This article is beyond from the programming. FYI as a programmer you should have a knowledge about these things. If not you will ended up with a mess. It's RLE What is it?  Run Length Encoding is a very simple form of loosless data compression in which runs of data are stored as a single data value and count, rather than as the original run. Understood? I bet you wont !! Let me go it with my way right after this article you will a have sufficient knowledge about RLE for sure. Let's Dive in ! Let's try an encoding image drawn using three colors on a 5x5 grid. First we will use simple method We have assigned a letter to each of the colors, Y for Yellow, G for Green, and B for Blue. As a result of transforming the rows into Ys,Gs nad Bs one line at a time starting from the upper left, we were able to encode the figure into a line of 25 letters. Next, using run legth encoding on the image, let's try expressing it in less than 25 le...

Ruby on Rails Tutorial

Ruby on Rails Introduction  Hi all I,m here with a new article actually It's trending laguage for you all .Invented in Japan. That means it's very active language. Also it's  need some theory parts to understand these things very well so i will go through by explaining them simply. What is Ruby? Before we Ride on Rails , let us recapitulate a few points of ruby, which is the base of Rails. Ruby is the successful combination of Smalltalk's conceptual elegance python's ease of use and learning and perl's pragmatism Ruby is   A high level programming language. Interpreted like Perl, Python , Tcl/Tk. Object oriented like Smalltalk, Eiffel, Ada ,Java Why Ruby? Ruby originated in japan and now it is gaining popularity in US and Europe  as well. The following factors contribute towards  its popularity. Easy to learn Open source(very liberal license) rich libraries very easy to extend  Truly Object Oriented Less coding with f...