DIY Pedometer with ESP32 & BMI160 – Steps Counter
DIY Pedometer with ESP32 BLE & BMI160 Accelerometer Gyroscope - Accurate Steps Counter on ESP32 OLED Display & Bluetooth App with C++ Code
- Suitable forB.Tech/Diploma ESP32/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview
In this project, we will build a
portable pedometer
using an
ESP32
microcontroller and the
BMI160 Accelerometer Gyroscope
Module from Bosch. In a previous article (
BMI160 Guide
), we discussed the BMI160 module’s features, capabilities, and applications—comparing it with the
MPU6050
along the way.
This project focuses on the practical application of the BMI160’s built‑in
step-counting algorithm
. Our design features an
OLED display
that provides real‑time feedback on your step count, while the unit is powered by a
3.7V Lithium‑ion battery
. The device also includes a boost converter, a slide switch for
power management
, and a push button that resets the
step counter
when pressed. Compact enough to fit in your pocket, this
pedometer
records your walking steps accurately.
In addition to displaying the step count on the OLED, the ESP32 uses
Bluetooth Low Energy (BLE)
to transmit data to your mobile device via the
nRF Connect
app.
Bill of Materials
To build an ESP32 Pedometer for steps counting, we need the following components.
S.N.
Components Name
Quantity
Purchase Link
1
ESP32 Board
1
Amazon
AliExpress
2
BMI160 Accelerometer Gyroscope
1
Amazon
AliExpress
3
0.96\" OLED Display
1
Amazon
AliExpress
Push Button Switch
1
Amazon
AliExpress
Resistor 1K
1
Amazon
AliExpress
3.7V Lithium-ion Battery
1
Amazon
AliExpress
Boost Converter Module
1
Amazon
AliExpress
Slide Switch
1
Amazon
AliExpress
Fig: Components for Pedometer
BMI160 3 Axis Accelerometer & Gyroscope
The
BMI160
is a high-performance, small, and ultra-low-power 16-bit Inertial Measurement Unit (IMU) that combines a 3-axis accelerometer and a 3-axis gyroscope in a single package.
Fig: Front & Back of BMI160
It is designed to deliver accurate and reliable motion sensing for a wide range of applications, such as augmented reality, indoor navigation, wearable devices, and gaming. The sensor offers advanced features like motion detection, step counting, and gesture recognition, making it versatile for modern technology needs.
The
BMI160
supports both
I2C
and
SPI
interfaces for communication, making it compatible with a variety of microcontrollers and processors. Refer to Bosch
BMI160 Datasheet
for more information.
Steps Counter Algorithm in BMI160 Module
The BMI160 has a dedicated, on‐chip step counter that sets it apart from many older sensors like the MPU6050. Here’s how and why it can calculate steps:
Dedicated Hardware Algorithm:
Unlike the MPU6050—which only provides raw accelerometer and gyroscope data and requires you to implement your own step detection algorithm—the BMI160 integrates a digital signal processing block specifically for step counting. This hardware module continuously filters and analyzes the acceleration data to detect step-like movements.
Threshold and Debounce Logic:
The sensor’s internal algorithm monitors the periodic changes in acceleration that occur during walking. It applies threshold detection (and adjustable sensitivity settings) to determine when a valid step occurs. It also incorporates debounce logic, ensuring that only distinct, well-separated peaks (steps) are counted.
Inbuilt Registers:
When a step is detected, the BMI160 automatically increments an internal step counter. This counter is stored in dedicated registers (typically found at addresses 0x78 and 0x79), which can be read directly via I²C or SPI.
Simplified Integration:
Because the step counting is handled internally, designers can quickly implement a pedometer by simply reading the step count register—no complex filtering or peak detection algorithms need to be implemented in your firmware.
Building a Pedometer using BMI160 & ESP32
First, let’s design the
ESP32 Pedometer
hardware that can
count steps
and display on the OLED screen.
Fig: ESP32 BMI160 Pedometer Hardware Design
In this schematic, the
ESP32
is the main board which supports Wi-Fi and Bluetooth. The
BMI160
sensor measures acceleration and gyroscope data. The
OLED display
shows the step count.
Both the
BMI160
and
OLED
connect to the same I2C pins on the ESP32. The BMI160’s interrupt pin goes to
GPIO 5
, and a
push button
on
GPIO 23
resets the steps.
Fig: ESP32 Pedometer Board (Top Side)
A
3.7 V lithium-ion battery
powers the system. A
boost converter
steps the battery voltage up to
5 V
, which goes to the
5 V pin
on the ESP32. You must set the boost converter to
5 V
before using it. By default, it may be at
12 V
Fig: ESP32 Pedometer Board (Bottom Side)
Everything is assembled on a
zero PCB board
. The ESP32, OLED, and BMI160 use
female header pins
for easy placement. A
slide switch
turns the circuit on or off.
Source Code/Program for ESP32 Pedometer (Steps Counter)
After doing the hardware assembly, we can write a
C++ Code
for ESP32 BMI160 Steps Counter.
This following code uses the BMI160’s
built-in step counting algorithm
, which filters and analyzes
accelerometer data
to detect
valid footstep
patterns. Each time the sensor identifies a step, it
increments
an internal counter. The code then reads that
counter value
and displays it on the OLED, as well as prints it to the Serial Monitor. A push button on pin 23
resets the count
, letting you start fresh at any time.
Add the following libraries to the Arduino library folder, before working on the coding and debugging part.
BMI160 Library:
https://github.com/hanyazou/BMI160-Arduino
Adafruit GFX Library:
https://github.com/adafruit/Adafruit-GFX-Library
Adafruit SSD1306 Library:
https://github.com/adafruit/Adafruit_SSD1306
Copy the following code and paste it to the editor window.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include `Wire.h`
#include `BMI160Gen.h`
#include `Adafruit_GFX.h`
#include `Adafruit_SSD1306.h`
// OLED display definitions for a 0.96\" (128x64) display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // No dedicated reset pin
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
// Sensor parameters:
const
int
BMI160_I2C_ADDRESS
=
0x68
;
// BMI160 I2C Address
const
int
INTERRUPT_PIN
=
5
;
// Digital pin used for sensor interrupt
// Reset button pin:
const
int
RESET_BUTTON_PIN
=
23
;
// Reset button connected to GP23
// Optional: Interrupt callback (for future embellishments)
void
stepInterrupt
(
)
{
// This callback is triggered on an interrupt (e.g., double-tap).
// The built-in step counter works independently.
}
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
{
}
// Wait for Serial Monitor
// Set the reset button pin with internal pulldown so that when not pressed, it is LOW.
pinMode
(
RESET_BUTTON_PIN
INPUT_PULLDOWN
)
;
// Initialize the OLED display
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
)
{
// Typical OLED I2C address is 0x3C
Serial
println
(
F
(
\"SSD1306 allocation failed\"
)
)
;
while
(
1
)
;
}
display
clearDisplay
(
)
;
display
display
(
)
;
// Initialize BMI160 sensor in I2C mode
if
(
!
BMI160
begin
(
BMI160GenClass
::
I2C_MODE
BMI160_I2C_ADDRESS
INTERRUPT_PIN
)
)
{
Serial
println
(
\"BMI160 initialization failed!\"
)
;
while
(
1
)
;
}
BMI160
attachInterrupt
(
stepInterrupt
)
;
// --- Auto-Calibration for Improved Accuracy ---
// (Ensure the sensor is stationary during calibration)
BMI160
autoCalibrateGyroOffset
(
)
;
BMI160
autoCalibrateXAccelOffset
(
0
)
;
// X-axis to 0g
BMI160
autoCalibrateYAccelOffset
(
0
)
;
// Y-axis to 0g
BMI160
autoCalibrateZAccelOffset
(
1
)
;
// Z-axis to +1g (gravity)
// Set accelerometer range to 2g (for higher sensitivity in step detection)
BMI160
setFullScaleA
In this project, we will build a
portable pedometer
using an
ESP32
microcontroller and the
BMI160 Accelerometer Gyroscope
Module from Bosch. In a previous article (
BMI160 Guide
), we discussed the BMI160 module’s features, capabilities, and applications—comparing it with the
MPU6050
along the way.
This project focuses on the practical application of the BMI160’s built‑in
step-counting algorithm
. Our design features an
OLED display
that provides real‑time feedback on your step count, while the unit is powered by a
3.7V Lithium‑ion battery
. The device also includes a boost converter, a slide switch for
power management
, and a push button that resets the
step counter
when pressed. Compact enough to fit in your pocket, this
pedometer
records your walking steps accurately.
In addition to displaying the step count on the OLED, the ESP32 uses
Bluetooth Low Energy (BLE)
to transmit data to your mobile device via the
nRF Connect
app.
Bill of Materials
To build an ESP32 Pedometer for steps counting, we need the following components.
S.N.
Components Name
Quantity
Purchase Link
1
ESP32 Board
1
Amazon
AliExpress
2
BMI160 Accelerometer Gyroscope
1
Amazon
AliExpress
3
0.96\" OLED Display
1
Amazon
AliExpress
Push Button Switch
1
Amazon
AliExpress
Resistor 1K
1
Amazon
AliExpress
3.7V Lithium-ion Battery
1
Amazon
AliExpress
Boost Converter Module
1
Amazon
AliExpress
Slide Switch
1
Amazon
AliExpress
Fig: Components for Pedometer
BMI160 3 Axis Accelerometer & Gyroscope
The
BMI160
is a high-performance, small, and ultra-low-power 16-bit Inertial Measurement Unit (IMU) that combines a 3-axis accelerometer and a 3-axis gyroscope in a single package.
Fig: Front & Back of BMI160
It is designed to deliver accurate and reliable motion sensing for a wide range of applications, such as augmented reality, indoor navigation, wearable devices, and gaming. The sensor offers advanced features like motion detection, step counting, and gesture recognition, making it versatile for modern technology needs.
The
BMI160
supports both
I2C
and
SPI
interfaces for communication, making it compatible with a variety of microcontrollers and processors. Refer to Bosch
BMI160 Datasheet
for more information.
Steps Counter Algorithm in BMI160 Module
The BMI160 has a dedicated, on‐chip step counter that sets it apart from many older sensors like the MPU6050. Here’s how and why it can calculate steps:
Dedicated Hardware Algorithm:
Unlike the MPU6050—which only provides raw accelerometer and gyroscope data and requires you to implement your own step detection algorithm—the BMI160 integrates a digital signal processing block specifically for step counting. This hardware module continuously filters and analyzes the acceleration data to detect step-like movements.
Threshold and Debounce Logic:
The sensor’s internal algorithm monitors the periodic changes in acceleration that occur during walking. It applies threshold detection (and adjustable sensitivity settings) to determine when a valid step occurs. It also incorporates debounce logic, ensuring that only distinct, well-separated peaks (steps) are counted.
Inbuilt Registers:
When a step is detected, the BMI160 automatically increments an internal step counter. This counter is stored in dedicated registers (typically found at addresses 0x78 and 0x79), which can be read directly via I²C or SPI.
Simplified Integration:
Because the step counting is handled internally, designers can quickly implement a pedometer by simply reading the step count register—no complex filtering or peak detection algorithms need to be implemented in your firmware.
Building a Pedometer using BMI160 & ESP32
First, let’s design the
ESP32 Pedometer
hardware that can
count steps
and display on the OLED screen.
Fig: ESP32 BMI160 Pedometer Hardware Design
In this schematic, the
ESP32
is the main board which supports Wi-Fi and Bluetooth. The
BMI160
sensor measures acceleration and gyroscope data. The
OLED display
shows the step count.
Both the
BMI160
and
OLED
connect to the same I2C pins on the ESP32. The BMI160’s interrupt pin goes to
GPIO 5
, and a
push button
on
GPIO 23
resets the steps.
Fig: ESP32 Pedometer Board (Top Side)
A
3.7 V lithium-ion battery
powers the system. A
boost converter
steps the battery voltage up to
5 V
, which goes to the
5 V pin
on the ESP32. You must set the boost converter to
5 V
before using it. By default, it may be at
12 V
Fig: ESP32 Pedometer Board (Bottom Side)
Everything is assembled on a
zero PCB board
. The ESP32, OLED, and BMI160 use
female header pins
for easy placement. A
slide switch
turns the circuit on or off.
Source Code/Program for ESP32 Pedometer (Steps Counter)
After doing the hardware assembly, we can write a
C++ Code
for ESP32 BMI160 Steps Counter.
This following code uses the BMI160’s
built-in step counting algorithm
, which filters and analyzes
accelerometer data
to detect
valid footstep
patterns. Each time the sensor identifies a step, it
increments
an internal counter. The code then reads that
counter value
and displays it on the OLED, as well as prints it to the Serial Monitor. A push button on pin 23
resets the count
, letting you start fresh at any time.
Add the following libraries to the Arduino library folder, before working on the coding and debugging part.
BMI160 Library:
https://github.com/hanyazou/BMI160-Arduino
Adafruit GFX Library:
https://github.com/adafruit/Adafruit-GFX-Library
Adafruit SSD1306 Library:
https://github.com/adafruit/Adafruit_SSD1306
Copy the following code and paste it to the editor window.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include `Wire.h`
#include `BMI160Gen.h`
#include `Adafruit_GFX.h`
#include `Adafruit_SSD1306.h`
// OLED display definitions for a 0.96\" (128x64) display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // No dedicated reset pin
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
// Sensor parameters:
const
int
BMI160_I2C_ADDRESS
=
0x68
;
// BMI160 I2C Address
const
int
INTERRUPT_PIN
=
5
;
// Digital pin used for sensor interrupt
// Reset button pin:
const
int
RESET_BUTTON_PIN
=
23
;
// Reset button connected to GP23
// Optional: Interrupt callback (for future embellishments)
void
stepInterrupt
(
)
{
// This callback is triggered on an interrupt (e.g., double-tap).
// The built-in step counter works independently.
}
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
{
}
// Wait for Serial Monitor
// Set the reset button pin with internal pulldown so that when not pressed, it is LOW.
pinMode
(
RESET_BUTTON_PIN
INPUT_PULLDOWN
)
;
// Initialize the OLED display
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
)
{
// Typical OLED I2C address is 0x3C
Serial
println
(
F
(
\"SSD1306 allocation failed\"
)
)
;
while
(
1
)
;
}
display
clearDisplay
(
)
;
display
display
(
)
;
// Initialize BMI160 sensor in I2C mode
if
(
!
BMI160
begin
(
BMI160GenClass
::
I2C_MODE
BMI160_I2C_ADDRESS
INTERRUPT_PIN
)
)
{
Serial
println
(
\"BMI160 initialization failed!\"
)
;
while
(
1
)
;
}
BMI160
attachInterrupt
(
stepInterrupt
)
;
// --- Auto-Calibration for Improved Accuracy ---
// (Ensure the sensor is stationary during calibration)
BMI160
autoCalibrateGyroOffset
(
)
;
BMI160
autoCalibrateXAccelOffset
(
0
)
;
// X-axis to 0g
BMI160
autoCalibrateYAccelOffset
(
0
)
;
// Y-axis to 0g
BMI160
autoCalibrateZAccelOffset
(
1
)
;
// Z-axis to +1g (gravity)
// Set accelerometer range to 2g (for higher sensitivity in step detection)
BMI160
setFullScaleA
Technologies used
Hardware components
- ESP32
- Arduino
- SSD1306
- OLED
- MPU6050
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.