Friday, May 24, 2024
HomeMatlabHacking your individual private exercise coach with MATLAB and Arduino » Scholar...

Hacking your individual private exercise coach with MATLAB and Arduino » Scholar Lounge

Becoming a member of us immediately is Anthony Sharonov, Anthony lately received the Greatest Use of MATLAB award at Hack3, the worlds largest hackathon for highschool college students! Learn on to learn the way Anthony’s hack will help you enhance your exercise kind! Over to you, Anthony…
Whats up everybody! I’m Anthony Sharonov and I used to be born in Philadelphia after my mother and father immigrated into the US. From there we moved to Connecticut the place I first began to get desirous about engineering. My center faculty had a category that allowed me to discover my pursuits, the place we made tasks for science festivals. I now spend most of my days both tinkering round with electronics, taking part in tennis and on-line video games, or simply hanging out with my buddies. I’m a rock fan too, extra particularly a Weapons ‘N Roses, Electrical Gentle Orchestra, Ozzy Osbourne, and Steve Miller Band fan.


Rising up on films like 2001: A Area Odyssey, Gattaca, and Black Mirror episodes, I wished to create one thing that I’d see in these films. Now, after all I’d not have the ability to create a flying machine or one thing, I wished to make one thing you might discover in a cutscene. An typically cutscene in these films contain the protagonists coaching or figuring out. From there, I started to consider issues I’d see sooner or later for gyms.

Breaking down the issue:

With the pandemic, many individuals needed to begin working from house. This triggered a growth in at-home exercises, as these folks had been uncomfortable/unable to entry a public fitness center. This triggered so many new and inexperienced folks with their dumbbells. I used to be a kind of folks, and I had developed a foul behavior of incorrect kind, to which I solely corrected when returning to a public fitness center. So, I made a decision to create BreakBE to assist repair this frequent downside. This could possibly be seen in Sci-Fi films, with futuristic units serving to folks work out.

How did I implement it?:

BreakBE is a tool that makes use of an Arduino UNO and an accelerometer (MPU6050) to trace the acceleration of a dumbbell throughout a bicep curl. The uncooked knowledge is then despatched to a MATLAB script to be cleaned and plotted. Accelerometers are in a position to detect solely relative place (see “Challenges I bumped into”) in each the x and y instructions. When an individual does a bicep curl appropriately, acceleration in each the x and y instructions are fairly small and thus the positions received’t change a lot. Dangerous kind, nonetheless, is when an individual makes use of momentum to carry a weight. So as to create this momentum, this particular person should speed up closely within the y-direction. So, the MATLAB script plots the (x,y) from the accelerometer and stops recording when the place from the y-direction surpasses a threshold.

Dumbell mounted with the MPU6050 related to an Arduino Uno


Schematic for {Hardware} Connections

To start, it’s needed to gather the MPU6050 knowledge. I used the Digital Cat’s library instance which allowed me to gather the uncooked knowledge from the sensor and submit it by means of the serial monitor as seen within the mpu.ino (Arduino) file (full program may be present in my github repository):

Serial.print(gx); Serial.print(“t”);

Serial.print(gy); Serial.println(“t”);

As soon as the gadget submits knowledge into the serial monitor, we acquire it within the MATLAB script:

s = serialport(‘COM7’,115200);

b = convertCharsToStrings(a);

b = regexprep(b, ‘s+’, ); % take away areas

x = extractBefore(b,‘,’); % create string of x knowledge earlier than the comma, since uncooked knowledge is in format (x,y)

y = extractAfter(b,‘,’); % create string of y knowledge after the comma, since uncooked knowledge is in format (x,y)

After that, we plot the info as a scatter plot related by strains with a horizontal line to point threshold

yline(5,‘-.r’); % fixed horizontal line to indicate threshold

% Cease and present dangerous kind textual content when the y passes 5 (beneath)

textual content((max(datax)-100),(max(datay)-0.5),‘BAD FORM!!’);

yinters = datay(datay==y);

xinters = datax(datay==y);



Good kind – Information factors bounce round however stay beneath the y = 5 threshold denoted by the dotted line


Dangerous kind – Information factors bounce round after which spike above the y = 5 threshold denoted by the dotted line

Why did I take advantage of MATLAB?:

I used MATLAB for the primary time two years in the past for a analysis undertaking. I discovered that MATLAB was superb for simulating bodily buildings for that undertaking, manipulating arrays and matrices with ease. The web model made it straightforward for me to work on completely different computer systems with out the effort of transferring recordsdata round. The code itself is fairly compact, which I personally actually like. For this undertaking, I wished to reap the benefits of MATLAB’s effectively made plotting software program. If I’ve an thought of what I need my plot to appear like, I’m able to make it. The documentation is so readable as in comparison with different languages, so plotting was even simpler!

Key Takeaways + Challenges I bumped into:

Downside 1 – I initially utterly miss understood how the MPU6050 works. Initially, I assumed that it was in a position to report place, as in if I held the gadget in a single spot, then it might continuously give the place of the gadget relative to the start line. Nevertheless, this doesn’t work. The (x,y) knowledge from the gadget offers the place relative to the acceleration. If I maintain it nonetheless, then transfer it, it’ll give me the (x,y) from that place to begin. However as soon as it turns into nonetheless once more, the info goes again to (0,0). So, I needed to improvise and detect when the acceleration will get too massive within the y-direction.

Downside 2 – I initially wished to make use of an ESP32, for wi-fi knowledge transmission to the pc so I received’t be restricted by the gap of my wires. Nevertheless, my ESP32 was damaged, outputting a voltage of solely 0.8V which couldn’t energy the MPU6050.

Total, this undertaking was enjoyable to make for a weekend hackathon. Many issues may be improved, corresponding to making it wi-fi. Moreover, it might be good to develop a formulation to find out a person’s threshold to find out dangerous kind. I received y = 5 from simply testing again and again, however there may be undoubtedly a option to decide it primarily based off of peak/arm size. Lastly, it might have been good to have higher person interface in addition to extra exercises, not simply bicep curls.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments