Sensor Fusion Explained: How to Build a High-Accuracy Fitness Rep Counter

Published: (January 16, 2026 at 08:40 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

The Problem with Single‑Sensor Tracking

Fitness apps often miscount repetitions, especially for complex movements. Accelerometers in phones are noisy, and gyroscopes drift over time, leading to “phantom” reps or missed sets.

Why One Sensor Isn’t Enough

Accelerometer

  • Measures proper acceleration (including gravity)
  • Stable over long periods
  • Highly sensitive to vibrations and sudden shakes

Gyroscope

  • Measures rotational speed
  • Excellent for short‑term precision
  • Suffers from drift, causing orientation errors over time

Sensor Fusion with a Complementary Filter

By combining the accelerometer’s long‑term stability with the gyroscope’s short‑term accuracy, we obtain a reliable orientation signal.

Formula

FusedAngle = α * (GyroAngle) + (1 - α) * (AccelAngle)
  • Typical α (alpha) = 0.98 → trust the gyroscope 98 % of the time, using the accelerometer to correct drift.

Comparison of Sensors and Fusion

FeatureAccelerometerGyroscopeFused Result
Short‑term AccuracyLow (Noisy)HighHigh
Long‑term StabilityHighLow (Drift)High
Vibration ResistanceLowHighBalanced

Counting Reps with a State Machine

Instead of counting every signal peak, a finite‑state machine tracks the phases of an exercise (e.g., a bicep curl):

StateDescription
IDLEUser is at rest.
GOING_UPAngle crosses an entry threshold (e.g., 30°).
GOING_DOWNUser reaches the peak and begins the return movement.
REPETITIONReturn completes → increment count and reset to IDLE.

This approach filters out jitter and mid‑rep pauses, preventing false counts.

Adapting the Framework to Other Exercises

  • Kettlebell Swings – Track torso pitch angle.
  • Squats – Use vertical movement and thigh orientation.

The same fusion and state‑machine logic can be tuned for various motions.

Conclusion

Real‑time, accurate health feedback depends on reliable sensor data. Mastering sensor fusion lets developers create fitness tools users can trust for daily progress.

For a full Python implementation and step‑by‑step guide, see WellAlly’s comprehensive rep‑counter tutorial.

Back to Blog

Related posts

Read more »

Rapg: TUI-based Secret Manager

We've all been there. You join a new project, and the first thing you hear is: > 'Check the pinned message in Slack for the .env file.' Or you have several .env...

Technology is an Enabler, not a Saviour

Why clarity of thinking matters more than the tools you use Technology is often treated as a magic switch—flip it on, and everything improves. New software, pl...