Student Lounge

Sharing technical and real-life examples of how students can use MATLAB and Simulink in their everyday projects #studentsuccess

Hacking your own personal workout trainer with MATLAB and Arduino

Joining us today is Anthony Sharonov, Anthony recently won the Best Use of MATLAB award at Hack3, the worlds largest hackathon for high school students! Read on to learn how Anthony’s hack can help you improve your workout form! Over to you, Anthony…
Hello everyone! I am Anthony Sharonov and I was born in Philadelphia after my parents immigrated into the United States. From there we moved to Connecticut where I first started to get interested in engineering. My middle school had a class that allowed me to explore my interests, where we made projects for science fairs. I now spend most of my days either tinkering around with electronics, playing tennis and online games, or just hanging out with my friends. I am a rock fan too, more specifically a Guns ‘N Roses, Electric Light Orchestra, Ozzy Osbourne, and Steve Miller Band fan.


Growing up on movies like 2001: A Space Odyssey, Gattaca, and Black Mirror episodes, I wanted to create something that I would see in these movies. Now, of course I would not be able to create a flying machine or something, I wanted to make something you could find in a cutscene. An often cutscene in these movies involve the protagonists training or working out. From there, I began to think about things I would see in the future for gyms.

Breaking down the problem:

With the pandemic, many people had to start working from home. This caused a boom in at-home workouts, as those people were uncomfortable/unable to access a public gym. This caused so many new and inexperienced people with their dumbbells. I was one of those people, and I had developed a bad habit of incorrect form, to which I only corrected when returning to a public gym. So, I decided to create BreakBE to help fix this common problem. This could be seen in Sci-Fi movies, with futuristic devices helping people work out.

How did I implement it?:

BreakBE is a device that uses an Arduino UNO and an accelerometer (MPU6050) to track the acceleration of a dumbbell during a bicep curl. The raw data is then sent to a MATLAB script to be cleaned and plotted. Accelerometers are able to detect only relative position (see “Challenges I ran into”) in both the x and y directions. When a person does a bicep curl correctly, acceleration in both the x and y directions are rather small and thus the positions won’t change much. Bad form, however, is when a person uses momentum to lift a weight. In order to create this momentum, this person must accelerate heavily in the y-direction. So, the MATLAB script plots the (x,y) from the accelerometer and stops recording when the position from the y-direction surpasses a threshold.
Dumbell mounted with the MPU6050 connected to an Arduino Uno
Schematic for Hardware Connections
To begin, it is necessary to collect the MPU6050 data. I used the Electronic Cat’s library example which allowed me to collect the raw data from the sensor and submit it through the serial monitor as seen in the mpu.ino (Arduino) file (full program can be found in my github repository):
Serial.print(gx); Serial.print(“\t”);
Serial.print(“, “);
Serial.print(gy); Serial.println(“\t”);
Once the device submits data into the serial monitor, we collect it in the MATLAB script:
s = serialport(‘COM7’,115200);
a = fscanf(s);
b = convertCharsToStrings(a);
b = regexprep(b, ‘\s+’, ); % remove spaces
x = extractBefore(b,‘,’); % create string of x data before the comma, since raw data is in format (x,y)
y = extractAfter(b,‘,’); % create string of y data after the comma, since raw data is in format (x,y)
x = str2double(x);
y = str2double(y);
After that, we plot the data as a scatter plot connected by lines with a horizontal line to indicate threshold
yline(5,‘-.r’); % constant horizontal line to show threshold
% Stop and show bad form text when the y passes 5 (below)
if yinters > 0
text((max(datax)-100),(max(datay)-0.5),‘BAD FORM!!’);
% threshold detected
if y > 5
yinters = datay(datay==y);
xinters = datax(datay==y);


Good form – Data points bounce around but remain under the y = 5 threshold denoted by the dotted line
Bad form – Data points bounce around and then spike above the y = 5 threshold denoted by the dotted line

Why did I use MATLAB?:

I used MATLAB for the first time two years ago for a research project. I found that MATLAB was amazing for simulating physical structures for that project, manipulating arrays and matrices with ease. The online version made it easy for me to work on different computers without the hassle of moving files around. The code itself is pretty compact, which I personally really like. For this project, I wanted to take advantage of MATLAB’s well made plotting software. If I have an idea of what I want my plot to look like, I am able to make it. The documentation is so readable as compared to other languages, so plotting was even easier!

Key Takeaways + Challenges I ran into:

Problem 1 – I originally completely miss understood how the MPU6050 works. Originally, I thought that it was able to record position, as in if I held the device in one spot, then it could constantly give the position of the device relative to the starting point. However, this does not work. The (x,y) data from the device gives the position relative to the acceleration. If I hold it still, then move it, it will give me the (x,y) from that starting point. But once it becomes still again, the data goes back to (0,0). So, I had to improvise and detect when the acceleration gets too large in the y-direction.
Problem 2 – I originally wanted to use an ESP32, for wireless data transmission to the computer so I won’t be limited by the distance of my wires. However, my ESP32 was broken, outputting a voltage of only 0.8V which could not power the MPU6050.
Overall, this project was fun to make for a weekend hackathon. Many things can be improved, such as making it wireless. Additionally, it would be nice to develop a formula to determine a user’s threshold to determine bad form. I got y = 5 from just testing over and over, but there is definitely a way to determine it based off of height/arm length. Lastly, it would have been nice to have better user interface as well as more workouts, not just bicep curls.

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.