Introduction: Using an Arduino Neural Network to Count Gym Reps!
Ever been at the gym, doing bicep curls like a chad—1… 2… 3…—and then suddenly… “Wait, was that 8 or 9?” Distracted by the music, your phone, or just the sheer awesomeness of yourself in the mirror, you lose count. Annoying, right?
What if someone else could do the counting for you, so you can focus on nailing your form and looking like the fitness God? Thats why I made an Arduino AI Gym Assistant!
Now, I know what you're thinking: “Why not just hire a personal trainer or stay focused?” Sure, that’s an option… but where’s the fun in that? Instead, I decided to over-engineer a simple problem by building an Arduino-based smartwatch powered by TinyML. (Because, why not?)
For the uninitiated, TinyML lets you run machine learning models on tiny, low-power devices, like an Arduino. Inspired by the book TinyML by Pete Warden, I realized I could teach a model to recognize my workout reps, count them, and even announce the numbers using an Android app.
Sure, it sounds like a long way around solving the distraction problem. But trust me—it's a lot easier than trying to focus, and way cooler! So, if you're ready to turn your workout into a tech-infused adventure, let's dive in.
Step 1: Hardware Design and Considerations
When designing this smartwatch, I had one major goal: make it gym-friendly, wearable, and as hassle-free as possible. Basically, I wanted something that wouldn't make me look like I was wearing a science project on my wrist while lifting weights!
To get started, I chose the Arduino Nano 33 BLE Sense. Why? It's compact, has a built-in accelerometer for movement tracking, and even comes with a microphone—features that made it perfect for my initial prototype. For instance, in one experiment, I even counted reps by detecting breaths (yes, my watch was listening to me work out).
For the watch’s body, I went with a 3D-printed case to house the components and paired it with an elastic strap secured by Velcro. This setup kept it snug and comfortable during workouts without looking like a medieval contraption.
The key consideration here was balancing size and functionality. It had to be lightweight enough for gym use but durable enough to handle the occasional dumbbell drop (oops). The Arduino Nano BLE Sense ticked all the boxes for processing power, while the accelerometer ensured accurate tracking without needing an external sensor.
If you want to make one yourself, don’t worry—I’ve kept things simple and portable. You’ll just need a 3D printer, a bit of soldering, and maybe some patience while attaching that strap.
Step 2: Manufacturing and PCB Design
Once I had the design figured out, it was time to build this smartwatch. My top priorities? Keep it compact, functional, and durable enough to survive the gym—because let’s be honest, it’s going to take a beating.
First things first, I needed a custom PCB to neatly organize all the components. I used JLCPCB for manufacturing because they’ve been super reliable for my past projects, and they offer quality boards at affordable prices. (Get JLCPCB 6 layer PCBs for just $5! Register to get $80 Coupons: https://jlcpcb.com/?from=shyamravi)
Download the PCB schematic and files from: https://github.com/theTechnowright/TinyML-AI-Gym-Assistant/tree/main/Gym_rep_counter
Once the PCB arrived, it was time to get my hands dirty with some soldering. I carefully placed all the components on the board and soldered them in place. It’s a bit of a delicate job, but there’s something oddly satisfying about watching your project take shape piece by piece.
Next up, I needed a case to house all these components. Enter my trusty 3D printer! I designed a compact and snug case to fit the PCB and battery while leaving enough room for ventilation (and to avoid overheating). Once printed, I secured everything inside the case.
For the straps, I wanted something simple and adjustable, so I went with elastic bands and Velcro. This combo keeps the watch comfortable on your wrist during workouts, no matter how intense things get.
And that’s it! With a bit of soldering, some 3D printing, and a sprinkle of patience, my smartwatch was ready to hit the gym. Building it was half the fun, and knowing it’s a one-of-a-kind gadget you made yourself? Totally worth it.
Step 3: Training the ML Model
Now, this part was where the real work (and sweat) kicked in—literally. To teach my smartwatch how to count reps, I needed data. And not just any data, but actual workout data. That meant hitting the gym, doing exercises, and recording every single movement. Who knew working out could double as a coding task?
I decided to focus on three exercises: bicep curls, chest presses, and tricep pulldowns. These were simple enough to start with and gave me a good variety of movement patterns for training the model.
To collect the data, I connected my watch to my laptop via USB and ran an Arduino script that recorded data from the accelerometer. The script sent the readings to the serial monitor, which I then saved as a CSV file using a Python script. (Don’t worry, I’ve linked all the code below for you to use!)
This process created time-series data—essentially a snapshot of how the accelerometer responded during each rep. To get good results, I had to perform multiple sets of each exercise, making sure to include variations like different speeds and slight form changes. Trust me, the gym-goers were very curious about what I was doing with wires coming out of my smartwatch!
The key here was diversity. More varied and accurate data means a smarter model that can handle different movement styles. So yes, while it was a bit tedious, it also felt good knowing I was turning my workout into something way cooler than just lifting weights.
And there you have it—data collection done! A little sweat, some Python magic, and a lot of reps later, I had all the data I needed to train my model.
Step 4: Training the ML Model
With all the data collected, it was time to teach my smartwatch how to count reps like a pro. For this, I turned to Edge Impulse, a fantastic platform that simplifies training machine learning models for edge devices.
Prepping the Data
The first step was feeding the data into Edge Impulse. The accelerometer data had three axes—X, Y, and Z—representing the watch's movement. Before training, I used the platform's spectral features tool to extract meaningful patterns from the raw data. Think of it like turning messy workout scribbles into neat notes that the model could actually understand.
Designing the Neural Network
Once the data was ready, it was time to build the brain of the operation: the neural network. Let me break down the key layers:
- Input Layer: This is where the model receives the processed features from the accelerometer data. It's like giving the model a map of your workout movements.
- Dense Layers:Dense layers are the heart of any neural network. Think of them as tiny teams of neurons working together to learn patterns from the data. Each neuron connects to every input, and by adjusting their "weights," they get better at spotting which movements correspond to which exercise.
- Output Layer: Finally, the output layer is where all the magic comes together. It uses a softmax function to assign probabilities to each exercise. For example, it might say, "I'm 90% sure this is a bicep curl." The prediction with the highest probability gets selected. Initially, I used two dense layers, which were enough to get decent accuracy, but I wanted to push further.
- Dropout Layer: To improve performance, I added a dropout layer after the dense layers. This layer randomly disables some neurons during training, forcing the network to rely on different combinations of neurons each time. It's like training your brain to solve puzzles using different strategies—this helps prevent overfitting (where the model gets too good at memorizing data but fails at new challenges).
Testing and Fine-Tuning
At first, my model had an accuracy of 94.9% with two dense layers. Not bad, but I knew I could do better. After adding the dropout layer, the accuracy jumped to 96.2%. Then, by adding another dense layer, I managed to hit 97.4%!
The extra dense layer helped the model capture more complex patterns, while the dropout layer made it more robust to new data. Sure, it couldn’t count like Einstein, but it was reliable enough for the gym—and that's all I needed!
Training the model was a mix of trial, error, and small victories. Watching the accuracy improve with each tweak felt like leveling up in a video game. And the best part? It was ready to move on to the deployment stage, where it would finally come to life on the watch.
Step 5: Deploying the ML Model
Once the model was trained and tested, it was time to bring it to life on the Arduino Nano 33 BLE Sense. This is where the magic happens—turning lines of code and data into a functional, wearable gym buddy.
Exporting the Model
Edge Impulse makes deployment super easy. Once the model was ready, I exported it as an Arduino library. This handy file contains everything needed to run the model directly on the Arduino, from the neural network architecture to the preprocessing steps.
Uploading the Code to Arduino
To get the model running, I loaded the exported library into the Arduino IDE (Integrated Development Environment). After importing it, I wrote an Arduino sketch that:
- Reads accelerometer data from the Nano 33 BLE Sense.
- Processes this data using the model.
- Converts predictions into workout counts.
- Sends the counts via Bluetooth Low Energy (BLE) to an Android app I designed (more on that in a moment).
The threshold logic was a key addition here. The model outputs probabilities for each exercise, and I needed a way to decide when it was "confident enough" to count a rep. I set a confidence threshold of 60%, meaning if the model was at least 60% sure of an exercise, it would register a count.
Bluetooth Integration
To make the smartwatch interactive, I used the Arduino’s BLE capabilities to send real-time updates to my Android app. BLE is perfect for this—it’s energy-efficient, which means the watch’s battery lasts longer (because who wants to charge their watch every day?).
App Integration
The Android app, built using MIT App Inventor, acted as the voice of the smartwatch. It received rep counts via BLE, stored the data, and even read the counts out loud using text-to-speech. Fun fact: getting the BLE libraries to cooperate with App Inventor was an adventure in frustration, but after some trial and error, I got it working.
Uploading the Code
Finally, I uploaded the sketch to the Arduino Nano 33 BLE Sense. This step is as straightforward as plugging the Arduino into your laptop, hitting the Upload button in the Arduino IDE, and letting it do its thing. Once the upload was complete, the smartwatch was ready to hit the gym.
Step 6: Testing the Model and App!
With the model deployed, it was time for the moment of truth—testing it in the real world. So, I grabbed my smartwatch, hit the gym, and put it to work.
Initial Tests
At first, I tried out the three exercises the model was trained on: bicep curls, chest presses, and tricep pulldowns. The watch correctly identified the movements most of the time and started counting reps. Watching it work was like seeing a tiny fitness coach strapped to my wrist!
You can watch my youtube for the testing of the watch.
Accuracy Tweaks
Initially, the model had an accuracy of 94.9% with just two dense layers. While this was decent, it sometimes missed a rep or misclassified a movement. To improve, I went back to the drawing board:
- Adding a dropout layer boosted accuracy to 96.2% by preventing overfitting.
- Adding another dense layer brought it to 97.4%, helping the model capture even more subtle patterns in the data.
While 100% accuracy wasn’t possible (some days I move like a robot, others like a wiggly noodle), the performance was good enough for reliable rep counting during most workouts.
Real-World Performance
The Android app also performed well, with minimal delay between the watch sending the count and the app announcing it aloud. It was oddly satisfying to hear the app call out, “1… 2… 3…” during a workout. It gave me that extra boost to keep going.
Challenges and Observations
Of course, there were a few hiccups:
- Sudden jerky movements or interruptions sometimes threw off the count.
- The model is personalized—it works best for my specific movements. For others, it might need retraining with their data.
But overall, the system was consistent and felt like having a personal trainer who never loses count (or their patience).
Step 7: Conclusion
Building this smartwatch was a mix of technical problem-solving and creative tinkering, and it solved my biggest gym frustration: losing count during sets. Sure, it was a lot of work to solve a “simple” problem, but where’s the fun in taking the easy route?
The final result is a smartwatch that not only tracks my reps but also motivates me with real-time feedback. And let’s face it—it’s way cooler than just trying to stay focused or counting until muscle failure.
Future Improvements
There’s still plenty of room to grow. Here’s what I’m dreaming up for the next version:
- Support for more exercises by collecting more diverse training data.
- Improved accuracy with larger datasets and tweaks to the neural network.
- Enhanced app UI, including features to track weekly progress and workout history.
- Generalizing the model so it works for different body types and movement styles.
For now, though, this little gadget has earned its place in my gym bag. Whether you’re a fellow maker or just someone who’s tired of losing count, I hope this inspires you to tinker and create something awesome.
Until next time, happy hacking—and lifting!