Passos de caminhada e calculadora de distância baseados em Arduino

Arduino based walking steps and distance calculator

A very common feature in fitness apps for Android and iOS is to calculate the number of steps the user takes and the distance they cover. These applications calculate the number of steps taken by the user using GPS location and manipulating geospatial data or monitoring the device's acceleration vector using an accelerometer sensor.

In this project, we have designed a similar walking step calculator on Arduino platform. The method used in this project is to monitor the device's acceleration vector. To do this, the ADXL345 accelerometer interfaces with the Arduino. The number of steps taken by the user and the distance covered by the user are displayed on an OLED screen. The logic used in this project can be easily replicated in a smartwatch application. You can easily port the code logic to any other language as it simply reads data from the accelerometer sensor and manipulates this data to detect the user's movement.

Required components

  1. Arduino UNO x1
  2. ADXL345 Accelerometer Sensor x1
  3. SSD1306 x1 OLED screen
  4. Connecting wires/jumper wires

Circuit Connections
For the design of this project, the ADXL345 accelerometer sensor and the SSD1306 OLED are interfaced with the Arduino. To do this, connect its GND and VCC pins to the Arduino's ground and 3.3V output pins. Then connect the SDA and SCL pins of the accelerometer sensor to the SDA and SCL pins on the I2C port of the Arduino.

In this project, a 7-pin SSD1306 OLED module is connected to Arduino UNO. The module is connected to the Arduino as follows.

Arduino based pedometer circuit diagram

Arduino based pedometer circuit diagram

Arduino Sketch

How it works
When the device is turned on, the SSD1306 OLED display is initialized and the “EEWORLDONLINE” logo and device name “Step Counter” flash on the screen. The initial number of steps is displayed as 0 and the distance traveled is also displayed as 0. Now all the user needs to do is keep the device with them.

The device continuously monitors its acceleration vector with the help of the ADXL345 accelerometer sensor. When the user walks, there is a change in the acceleration vector. When the user takes a step forward, the immediate change in the acceleration vector becomes negative. As the user steps with the other foot while balancing on the previous foot, the immediate change in the acceleration vector becomes positive.

Average acceleration values ​​are calculated when the device is turned on and initial messages appear on the screen. Average values ​​are also derived from the average of 50 consecutive ADXL345 accelerometer readings. These average values ​​for the device's acceleration on the x, y and z axes serve as a reference point.

After the initial setup is complete, the device recalculates the acceleration on the x, y and z axes 50 consecutive times and derives an average from these values. The device acceleration vector is calculated by taking the square root of the difference of current acceleration values ​​compared to reference values.

After a delay of 250 milliseconds, the device recalculates the acceleration on the x, y and z axes for 50 consecutive times and derives the average of these values. The device acceleration vector is recalculated at a 250 ms interval by taking the square root of the difference of the current acceleration values ​​compared to the reference values. The difference between the acceleration vector now and the acceleration vector 250 ms before is calculated, and if the difference is greater than 0.05, one step is increased. The distance walked value is calculated by multiplying the number of steps by one foot or 0.3048 meters, assuming that an average step is one foot long.

The number of steps and distance covered are updated on the OLED screen, with a 400 ms delay. The process of calculating the difference between two consecutive acceleration vectors of the device within a 250 ms interval is continued to monitor the user's movement.

It should be noted that the 250 ms delay between the calculation of two consecutive average acceleration vectors and the 0.05 difference is achieved after careful calibration of the device.

Check out this link to learn more about how the ADXL345 accelerometer communicates with Arduino via the I2C protocol.

To learn more about interfacing the SSD1306 OLED with Arduino, check out this link.

You should note that the Arduino reset button acts as a device reset button and resets the number of steps and distance traveled.

The code
The code starts by importing wire.h for I2C communication with the ADXL345 accelerometer sensor and SPI.h for communication with the SSD1306 OLED display. Adafruit libraries for working with OLED display are imported and the necessary constants for OLED interface and parameters defined. An object view is initialized for the SSD1306 class. The EEWORLDONLINE logo bitmap is stored in the Arduino PROGMEM and converted into an array object. Variables for storing the average, current, and immediately following acceleration values ​​are declared. A variable to store the number of steps is declared.

In the setup function, three different functions are called. ssd1306_init is called to initialize the SSD1306 OLED display and display initial messages on it. adxl345_init is called to initialize the acceleration sensor. The read_av_acc function is called to calculate reference acceleration values ​​when the device is at rest.

In the loop function, the acceleration vector is calculated twice in an interval of 250 ms, and if the difference between two values ​​is greater than 0.05, one step is increased. The number of steps and distance covered are updated on the OLED display.

Result

Arduino based pedometer using ADXL345 and SSD1306

Arduino based pedometer using ADXL345 and SSD1306

Demo video

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.