DIY Pedometer Using Arduino and Accelerometer

by Utsource in Circuits > Arduino

246 Views, 0 Favorites, 0 Comments

DIY Pedometer Using Arduino and Accelerometer

Pedometer-using-Arduino-Working.jpg
Hi guys in this instructables we will make a pedometer with Arduino and that pedometer will count the steps with the help of Accelerometer sensor which will work as pedometer sensor. And the steps will be displayed using 1602 Lcd Display with SPI to I2C module.

Things You Need

1577387646679.jpg
ADXL335-Accelerometer.jpg
images(108).jpg
1577387976044.jpg

for this instructables we will need following things :

Arduino Nano

ADXL 335 Accelerometer

1602 LCD

LCD I2C Module

Power Source

Schmatics

20191227_005113.jpg
Connections are pretty straight forward so,
Please connect everything According to the shown schmatics.

Code

20191121_193959.jpg
Please copy the following code and upload it to the arduino Board :

#include "LiquidCrystal_I2C.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int xpin = A1;
const int ypin = A2;
const int zpin = A3;
byte p[8] = {
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F
};
float threshold = 6;
float xval[100] = {0};
float yval[100] = {0};
float zval[100] = {0};
float xavg, yavg, zavg;
int steps, flag = 0;
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.clear();
calibrate();
}
void loop()
{
for (int w = 0; w < 16; w++) {
lcd.write(byte(0));
delay(500);
}
int acc = 0;
float totvect[100] = {0};
float totave[100] = {0};
float xaccl[100] = {0};
float yaccl[100] = {0};
float zaccl[100] = {0};
for (int a = 0; a < 100; a++)
{
xaccl[a] = float(analogRead(xpin) - 345);
delay(1);
yaccl[a] = float(analogRead(ypin) - 346);
delay(1);
zaccl[a] = float(analogRead(zpin) - 416);
delay(1);
totvect[a] = sqrt(((xaccl[a] - xavg) * (xaccl[a] - xavg)) + ((yaccl[a] - yavg) * (yaccl[a] - yavg)) + ((zval[a] - zavg) * (zval[a] - zavg)));
totave[a] = (totvect[a] + totvect[a - 1]) / 2 ;
Serial.println("totave[a]");
Serial.println(totave[a]);
delay(100);
if (totave[a] > threshold && flag == 0)
{
steps = steps + 1;
flag = 1;
}
else if (totave[a] > threshold && flag == 1)
{
// Don't Count
}
if (totave[a] < threshold && flag == 1)
{
flag = 0;
}
if (steps < 0) {
steps = 0;
}
Serial.println('\n');
Serial.print("steps: ");
Serial.println(steps);
lcd.print("Steps: ");
lcd.print(steps);
delay(1000);
lcd.clear();
}
delay(1000);
}
void calibrate()
{
float sum = 0;
float sum1 = 0;
float sum2 = 0;
for (int i = 0; i < 100; i++) {
xval[i] = float(analogRead(xpin) - 345);
sum = xval[i] + sum;
}
delay(100);
xavg = sum / 100.0;
Serial.println(xavg);
for (int j = 0; j < 100; j++)
{
yval[j] = float(analogRead(ypin) - 346);
sum1 = yval[j] + sum1;
}
yavg = sum1 / 100.0;
Serial.println(yavg);
delay(100);
for (int q = 0; q < 100; q++)
{
zval[q] = float(analogRead(zpin) - 416);
sum2 = zval[q] + sum2;
}
zavg = sum2 / 100.0;
delay(100);
Serial.println(zavg);
}

Testing the Pedometer

Pedometer-using-Arduino-Working.jpg
After Connecting everything together & Uploading the code then connect the power source and try to walk with it and it will show the steps on the LCD display.
So have fun making your own DIY Pedometer.