Description:
In this project we build a Pedometer using Arduino which detects and counts steps you take while walking or jogging. Steps are detected using ADXL345 Accelerometer sensor when there is tilt in the axis of the sensor. Steps can be seen on 0.96 inch OLED Display Module and everything is controlled using Arduino UNO.
Circuit Diagram:
Components:
SR. NO. | COMPONENT | PINOUT DIAGRAM | BUY |
---|---|---|---|
1 | Arduino UNO (Other Arduinos can be used too) | Arduino UNO Pinout Diagram⇗ | |
2 | 0.96 inch OLED Display Module | ||
3 | ADXL345 Accelerometer Module |
Arduino UNO
The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button. It is a widely used open-source platform that allows for easy programming and prototyping of electronic projects. In this project, the Arduino UNO serves as the brain of the device, receiving input from the ADXL345 accelerometer sensor, processing the data and then sending it to the OLED display to show the number of steps taken. The Arduino UNO also allows for easy customization and modification of the code to fit the needs of the user. Its small size and low power consumption make it an ideal choice for portable devices like pedometer.
0.96 Inch OLED Display Module
The 0.96 inch OLED display module is a small, low-power display that can be easily integrated into electronic projects. It features a high resolution of 128×64 pixels, and can display a wide range of colors. In this project, the OLED display module is used to display the number of steps taken by the user. The OLED display’s small size and low power consumption make it an ideal choice for portable devices such as pedometer. It’s bright and high-contrast display allows for easy reading even in bright lighting conditions. Additionally, OLED displays are highly durable and have a long lifespan, making them suitable for long-term use. With the Arduino UNO microcontroller board, the OLED display can be easily controlled to display the data received from the ADXL345 accelerometer sensor.
ADXL345 Accelerometer Sensor
The ADXL345 Accelerometer Sensor is a small, low-power, 3-axis accelerometer that can be used to detect motion and changes in orientation. It features a wide measurement range of up to ±16 g and a high resolution of 13-bit. In this project, the ADXL345 Accelerometer sensor is used to detect the movement of the user and count the number of steps taken. The sensor sends this data to the Arduino UNO microcontroller board which processes the data and sends it to the OLED display to show the number of steps taken. The ADXL345’s small size and low power consumption make it an ideal choice for portable devices such as pedometer. Additionally, it can be easily integrated into the project and can be customized to detect different types of movements. It can be used for many other applications like gaming, fitness tracking, and measuring vibration or impact. This sensor is a low-cost and efficient solution for measuring motion and orientation in a wide range of projects.
Steps and Info:
1. Get correct components as given. You can buy online or offline. I buy electronics components mostly from Amazon.
2. Start connecting the components. If you are new to connecting components in an electronic circuit, then use a Breadboard or you can straight up make connections using Jumper wires but it will create problem when there will be two or more connections needed at one pin (for example two or more different sensors 5V connection to Arduino’s 5V pin). But before soldering components on a PCB or printing a PCB for your circuit, better try using breadboard so that any errors and mistakes can be observed on breadboard and not after soldering. Or do connections in your way.
3. Now after building the circuit, download the Arduino IDE from https://www.arduino.cc/ website.
4. If you are new to Arduino IDE software, then watch this video we made specially for beginners about Arduino IDE.
5. If you know Arduino IDE then straight up copy the code we given and paste it into the Arduino IDE sketch.
6. Connect the Arduino to your Computer/device. Select a proper port, proper Arduino type and whatever other settings are. Here it is Arduino UNO. (If you don’t know what this all is then watch our video: ).
7. Compile the code and Upload it.
8. If any error occurs then try to troubleshoot it by finding/copy-pasting it into our Solve Errors page https://electronicsprojects.in/solve-errors/, or you can straight up paste the error on Internet and you know the rest. Also check if there are no spelling/syntax errors in the code. Compile the code again once to check if errors are fixed. I have given proper connections and code but still nothing is perfect.
9. Once code compiles and uploads smoothly, you can start testing the working of your circuit/project.
10. Take the circuit and starting tilting it, if there is output(steps) seen on the 0.96 inch OLED Display then put the circuit in pocket or stick it to your Arm or just keep in hand and start walking/jogging.
11. Keep the ADXL345 Accelerometer in proper position so that it will only tilt when you walk and that tilt will be registered as a step.
12. If it doesn’t work then check connections and code. Also you can talk with me and the community through discord. All the links to social is given at the right side of this page.
Program Code:
/* https://www.electronicsprojects.in Pedometer(Steps Counter) using Arduino, ADXL345 Accelerometer Sensor and 0.96” OLED Display */
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_MOSI 9
#define OLED_CLK 8
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 10
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
float xavg=0, yavg=0, zavg=0;
float xcur=0, ycur=0, zcur=0;
float xnxt=0, ynxt=0, znxt=0;
int steps = 0;
void setup() {
ssd1306_init();
adxl345_init();
read_av_acc();
}
void loop() {
for(int i = 0; i<50; i++){
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if(xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xcur = xcur + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if(yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
ycur = ycur + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if(zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
zcur = zcur + za;
}
xcur = xcur/50;
ycur = ycur/50;
zcur = zcur/50;
float acc = sqrt(((xcur - xavg) * (xcur - xavg)) +
((ycur - yavg) * (ycur - yavg)) +
((zcur - zavg) * (zcur - zavg)));
delay(250);
//Next Acceleration
for(int i = 0; i<50; i++){
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if(xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xnxt = xnxt + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if(yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
ynxt = ynxt + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if(zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
znxt = znxt + za;
}
xnxt = xnxt/50;
ynxt = ynxt/50;
znxt = znxt/50;
float acc2 = sqrt(((xnxt - xavg) * (xnxt - xavg)) +
((ynxt - yavg) * (ynxt - yavg)) +
((znxt - zavg) * (znxt - zavg)));
if (acc2-acc > 0.05)
{
steps = steps + 1;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("steps: ");
display.println(steps);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.print("Distance: ");
display.print(steps*0.3048);
display.println("M");
display.display();
delay(400);
}
void adxl345_init(){
Serial.begin(115200);
Wire.begin();
Wire.beginTransmission(0x53);
Wire.write(0x2C);
Wire.write(0x08);
Wire.endTransmission();
Wire.beginTransmission(0x53);
Wire.write(0x31);
Wire.write(0x08);
Wire.endTransmission();
Wire.beginTransmission(0x53);
Wire.write(0x2D);
Wire.write(0x08);
Wire.endTransmission();
}
void ssd1306_init(){
display.begin(SSD1306_SWITCHCAPVCC);
display.display();
delay(1000);
display.clearDisplay();
display.display();
delay(1000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("STEPS");
display.println("COUNTER");
display.display();
delay(1000);
}
float read_av_acc(){
for(int i = 0; i<50; i++){
Wire.beginTransmission(0x53);
Wire.write(0x32);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte x1 = Wire.read();
x1 = x1 & 0x03;
uint16_t x = (x1 << 8) + x0;
int16_t xf = x;
if(xf > 511)
{
xf = xf - 1024;
}
float xa = xf * 0.004;
xavg = xavg + xa;
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x35);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte y1 = Wire.read();
y1 = y1 & 0x03;
uint16_t y = (y1 << 8) + y0;
int16_t yf = y;
if(yf > 511)
{
yf = yf - 1024;
}
float ya = yf * 0.004;
yavg = yavg + ya;
Wire.beginTransmission(0x53);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z0 = Wire.read();
Wire.beginTransmission(0x53);
Wire.write(0x37);
Wire.endTransmission();
Wire.requestFrom(0x53, 1);
byte z1 = Wire.read();
z1 = z1 & 0x03;
uint16_t z = (z1 << 8) + z0;
int16_t zf = z;
if(zf > 511)
{
zf = zf - 1024;
}
float za = zf * 0.004;
zavg = zavg + za;
}
xavg = xavg/50;
yavg = yavg/50;
zavg = zavg/50;
}