{"id":8612,"date":"2022-08-29T07:43:30","date_gmt":"2022-08-29T11:43:30","guid":{"rendered":"https:\/\/blogs.mathworks.com\/student-lounge\/?p=8612"},"modified":"2022-08-29T07:52:06","modified_gmt":"2022-08-29T11:52:06","slug":"hacking-your-own-personal-workout-trainer-with-matlab-and-arduino","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/student-lounge\/2022\/08\/29\/hacking-your-own-personal-workout-trainer-with-matlab-and-arduino\/","title":{"rendered":"Hacking your own personal workout trainer with MATLAB and Arduino"},"content":{"rendered":"<div class=\"rtcContent\">\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-style: italic;\">Joining us today is <\/span><a href=\"https:\/\/www.linkedin.com\/in\/anthony-sharonov-4752a3243\/\"><span style=\"font-style: italic;\">Anthony Sharonov<\/span><\/a><span style=\"font-style: italic;\">, Anthony recently won the Best Use of MATLAB award at <\/span><a href=\"https:\/\/hack3.co\/\"><span style=\"font-style: italic;\">Hack3<\/span><\/a><span style=\"font-style: italic;\">, the worlds largest hackathon for high school students! Read on to learn how Anthony&#8217;s hack can help you improve your workout form! Over to you, Anthony&#8230;<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 280px; height: 391px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_1.png\" alt=\"headshot.JPG\" width=\"280\" height=\"391\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Hello everyone! I am <a href=\"https:\/\/www.linkedin.com\/in\/anthony-sharonov-4752a3243\/\"><span style=\"text-decoration: underline;\">Anthony Sharonov<\/span><\/a> 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 &#8216;N Roses, Electric Light Orchestra, Ozzy Osbourne, and Steve Miller Band fan.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Inspiration<\/span>:<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Growing up on movies like <span style=\"font-style: italic;\">2001: A Space Odyssey<\/span>, <span style=\"font-style: italic;\">Gattaca<\/span>, and <span style=\"font-style: italic;\">Black Mirror<\/span> 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.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Breaking down the problem<\/span>:<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">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.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">How did I implement it?<\/span>:<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">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 &#8220;Challenges I ran into&#8221;) 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&#8217;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.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 404px; height: 303px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_2.png\" alt=\"hardwareTogether.jpg\" width=\"404\" height=\"303\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><span style=\"font-style: italic; text-decoration: underline;\">Dumbell mounted with the MPU6050 connected to an Arduino Uno<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 324px; height: 336px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_3.png\" alt=\"schematic.jpg\" width=\"324\" height=\"336\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><span style=\"font-style: italic; text-decoration: underline;\">Schematic for Hardware Connections<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">To begin, it is necessary to collect the MPU6050 data. I used the <a href=\"https:\/\/github.com\/ElectronicCats\/mpu6050\/blob\/master\/examples\/MPU6050_raw\/MPU6050_raw.ino\"><span style=\"text-decoration: underline;\">Electronic Cat&#8217;s library<\/span><\/a> 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 <a href=\"https:\/\/github.com\/TheAnton205\/BreakBE\"><span style=\"text-decoration: underline;\">github repository<\/span><\/a>):<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 0 10px 0;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 1px solid #bfbfbf; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">Serial.print(gx); Serial.print(<span style=\"color: #a709f5;\">&#8220;\\t&#8221;<\/span>);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">Serial.print(<span style=\"color: #a709f5;\">&#8220;, &#8220;<\/span>);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 1px solid #bfbfbf; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">Serial.print(gy); Serial.println(<span style=\"color: #a709f5;\">&#8220;\\t&#8221;<\/span>);<\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Once the device submits data into the serial monitor, we collect it in the MATLAB script:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 0 10px 0;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 1px solid #bfbfbf; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">s = serialport(<span style=\"color: #a709f5;\">&#8216;COM7&#8217;<\/span>,115200); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">fopen(s);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">a = fscanf(s);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">b = convertCharsToStrings(a);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">b = regexprep(b, <span style=\"color: #a709f5;\">&#8216;\\s+&#8217;<\/span>, <span style=\"color: #a709f5;\">&#8221;<\/span>); <span style=\"color: #008013;\">% remove spaces<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x = extractBefore(b,<span style=\"color: #a709f5;\">&#8216;,&#8217;<\/span>); <span style=\"color: #008013;\">% create string of x data before the comma, since raw data is in format (x,y)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">y = extractAfter(b,<span style=\"color: #a709f5;\">&#8216;,&#8217;<\/span>); <span style=\"color: #008013;\">% create string of y data after the comma, since raw data is in format (x,y)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x = str2double(x); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 1px solid #bfbfbf; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">y = str2double(y);<\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">After that, we plot the data as a scatter plot connected by lines with a horizontal line to indicate threshold<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 0 10px 0;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 1px solid #bfbfbf; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">scatter(datax,datay);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">line(datax,datay);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">yline(5,<span style=\"color: #a709f5;\">&#8216;-.r&#8217;<\/span>); <span style=\"color: #008013;\">% constant horizontal line to show threshold<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Stop and show bad form text when the y passes 5 (below)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">if <\/span>yinters &gt; 0<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> text((max(datax)-100),(max(datay)-0.5),<span style=\"color: #a709f5;\">&#8216;BAD FORM!!&#8217;<\/span>);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">return<\/span>;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% threshold detected<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">if <\/span>y &gt; 5<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> yinters = datay(datay==y);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> xinters = datax(datay==y);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> disp(yinters);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 1px solid #bfbfbf; border-right: 1px solid #bfbfbf; border-top: 0px none #212121; border-bottom: 1px solid #bfbfbf; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Results<\/span>:<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 510px; height: 287px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_4.gif\" alt=\"Goodform-GIF.gif\" width=\"510\" height=\"287\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><span style=\"font-style: italic; text-decoration: underline;\">Good form &#8211; Data points bounce around but remain under the y = 5 threshold denoted by the dotted line<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 510px; height: 287px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_5.gif\" alt=\"Badform-GIF.gif\" width=\"510\" height=\"287\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><span style=\"font-style: italic; text-decoration: underline;\">Bad form &#8211; Data points bounce around and then spike above the y = 5 threshold denoted by the dotted line<\/span><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Why did I use MATLAB?<\/span>:<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">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&#8217;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!<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Key Takeaways + Challenges I ran into:<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-weight: bold;\">Problem 1<\/span> &#8211; 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.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-weight: bold;\">Problem 2<\/span> &#8211; I originally wanted to use an ESP32, for wireless data transmission to the computer so I won&#8217;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.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">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\u2019s 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.<\/div>\n<\/div>\n<p><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a><div class=\"pull-right\"><div class=\"col-xs-12 containing-block\"><a href=\"#\" class=\"btn btn-sm btn_color_blue add_margin_20  hidden-xs try_live_editor_example\" data-liveeditorexample=\"{\n  &quot;repository&quot; : &quot;Blogs&quot;,\n  &quot;id&quot; : &quot;&quot;\n}\"><span class=\"icon-edit icon_16\"><\/span>Run in your browser<span style=\"color:grey\" class=\"series\"><\/span><\/a><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2022\/08\/Aug29_2.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>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&#8217;s hack&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/student-lounge\/2022\/08\/29\/hacking-your-own-personal-workout-trainer-with-matlab-and-arduino\/\">read more >><\/a><\/p>\n","protected":false},"author":183,"featured_media":8645,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[451,6],"tags":[348,453,626,88],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/8612"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/users\/183"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/comments?post=8612"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/8612\/revisions"}],"predecessor-version":[{"id":8882,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/8612\/revisions\/8882"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media\/8645"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media?parent=8612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/categories?post=8612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/tags?post=8612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}