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 »

𝗗𝗲𝘀𝗶𝗴𝗻𝗲𝗱 𝗮 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻‑𝗥𝗲𝗮𝗱𝘆 𝗠𝘂𝗹𝘁𝗶‑𝗥𝗲𝗴𝗶𝗼𝗻 𝗔𝗪𝗦 𝗔𝗿𝗰𝗵𝗶𝘁𝗲𝗰𝘁𝘂𝗿𝗲 𝗘𝗞𝗦 | 𝗖𝗜/𝗖𝗗 | 𝗖𝗮𝗻𝗮𝗿𝘆 𝗗𝗲𝗽𝗹𝗼𝘆𝗺𝗲𝗻𝘁𝘀 | 𝗗𝗥 𝗙𝗮𝗶𝗹𝗼𝘃𝗲𝗿

!Architecture Diagramhttps://dev-to-uploads.s3.amazonaws.com/uploads/articles/p20jqk5gukphtqbsnftb.gif I designed a production‑grade multi‑region AWS architectu...