Projects / Step counter wristband

Step counter wristband

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP3239tilt 39°0.91

    Wire the I2C devices

    LIS3DH and OLED share D4 and D5.

  2. ESP32+

    Add the button and battery

    Button on D1, battery on the BAT pads.

  3. ESP32

    Print the movement

    Add a Serial.println(d) line and walk to see the size of the peaks.

  4. ESP32

    Set the threshold

    Choose a threshold at about half of a typical walking peak.

  5. ESP32

    Count 100 steps

    Walk 100 steps and compare. Raise the threshold if it counts too many, lower it if too few.

  6. ESP32

    Wear it

    Strap it on your wrist. The display sleeps after 5 seconds and wakes with the button.

In short

How do you build a step counter wristband?

An accelerometer counts steps with peak detection and shows them on a tiny OLED, charged over USB. You need Seeed XIAO ESP32C3, LIS3DH accelerometer, 0.91 inch OLED 128x32 (I2C), Li-Po battery 3.7 V 500 mAh, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LIS3DH VCC and GNDXIAO 3V3 and GNDSensor supply
LIS3DH SDA and SCLXIAO D4 and D5I2C, address 0x18
OLED VCC and GNDXIAO 3V3 and GNDDisplay supply
OLED SDA and SCLXIAO D4 and D5Shared bus, address 0x3C
ButtonXIAO D1 and GNDWake the display
LiPo batteryXIAO BAT+ and BAT- padsCharges over USB

Code

Arduino IDE with the ESP32 board package by Espressif, board "XIAO_ESP32C3". Install "Adafruit LIS3DH", "Adafruit Unified Sensor", "Adafruit SSD1306" and "Adafruit GFX Library". The threshold of 1.5 m/s² and the 300 ms minimum gap are starting points, so walk 100 steps and tune them to match your own count.

Runs on a virtual Seeed XIAO ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_LIS3DH lis;
Adafruit_SSD1306 oled(128, 32, &Wire, -1);
const byte BTN = D1;
const float STRIDE_M = 0.75;            // average step length
float baseline = 9.8;
float prev1 = 0, prev2 = 0;
unsigned long lastStep = 0, displayUntil = 5000;
unsigned long steps = 0;

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  Wire.begin();
  lis.begin(0x18);
  lis.setRange(LIS3DH_RANGE_4_G);
  lis.setDataRate(LIS3DH_DATARATE_50_HZ);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  sensors_event_t e; lis.getEvent(&e);
  float m = sqrt(e.acceleration.x * e.acceleration.x + e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z);
  baseline = baseline * 0.95 + m * 0.05;           // slow average removes gravity
  float d = m - baseline;                          // movement only
  bool peak = prev1 > prev2 && prev1 >= d && prev1 > 1.5;     // local maximum above threshold
  if (peak && millis() - lastStep > 300) { steps++; lastStep = millis(); }
  prev2 = prev1; prev1 = d;

  if (digitalRead(BTN) == LOW) displayUntil = millis() + 5000;
  oled.clearDisplay();
  if (millis() < displayUntil) {
    oled.setTextSize(2); oled.setCursor(0, 0); oled.print(steps); oled.print(" steps");
    oled.setTextSize(1); oled.setCursor(0, 22); oled.print(steps * STRIDE_M / 1000.0, 2); oled.print(" km");
  }
  oled.display();
  delay(20);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Walk 100 stepsCount within about 5 percent
Stand still and wave an armA few false steps at most
Press the buttonDisplay wakes for 5 seconds
Charge the batteryOver USB-C the XIAO's charge LED lights

If it does not work

Counts too many

Raise the threshold or the minimum gap.

Counts too few

Lower the threshold. A wrist swings less than a hip.

Display stays blank

Check the OLED address and wiring, and that it is the 128x32 type.

Battery drains fast

The display is on too long. Shorten displayUntil and add sleep.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the step counter wristband?

Seeed XIAO ESP32C3, LIS3DH accelerometer, 0.91 inch OLED 128x32 (I2C), Li-Po battery 3.7 V 500 mAh, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm).

How long does the step counter wristband take to build?

About 180 minutes for a intermediate maker, in 6 steps.

How do I know the step counter wristband works?

Walk 100 steps: Count within about 5 percent. Stand still and wave an arm: A few false steps at most. Press the button: Display wakes for 5 seconds.

Counts too many: what should I check?

Raise the threshold or the minimum gap.

Counts too few: what should I check?

Lower the threshold. A wrist swings less than a hip.

Display stays blank: what should I check?

Check the OLED address and wiring, and that it is the 128x32 type.

Battery drains fast: what should I check?

The display is on too long. Shorten displayUntil and add sleep.