Overview

Punching is not only a great form of exercise, but it is also a great relief of stress. As Penn students, many of us can become overwhelmed by our workload, and look for avenues of release. For our final project, by building a portable, easy to replicate punching machine, we provide an opportunity not only for individuals to compete against themselves as they seek to increase their high score while releasing stress, but we also allow for socialization as students will be able to compare their highest scores achieved with one another on the leaderboard.

For our punching machine, we used an accelerometer placed inside the punching bag to determine the acceleration and thus force generated by each punch, and we converted this measurement into a corresponding score that is displayed on an LCD screen. The modules will communicate over wifi. Our solution was successful and we are very happy with how our solution ended up working.

How We Built It

We began by thinking about whether or not we would use a force sensitive resistor or an accelerometer to detect the force of the punches, and decided to order both so we could test them out. However, once the punching bag arrived, it became clear that the accelerometer would be a much more logical option, because the bag was made out of a dense foam, and attaching the force sensitive resistor would’ve been incredibly difficult. Next, we began by ensuring that the accelerometer could correctly send readings to the punching bag NodeMCU, and once we determined that was doable, we began designing the housing unit of the accelerometer NodeMCU inside the punching bag.

We really wanted to ensure that we would not need any wires coming out of the punching bag, so our next step was to ensure that the NodeMCU inside the punching bag could communicate successfully with the NodeMCU on the outside, which would communicate with our Arduino. Getting the NodeMCU to NodeMCU communication was a big step for us, because after this, most of our work just had to be done on the arduino, which we were more familiar with.

We split up figuring out the I2C code for communication between the NodeMCU and Arduino, and getting the LCD display screen to work as our game intended (which included all of our desired game flow). This section was definitely the most difficult part of implementing our game, but once these sections were done, our game was complete!

Here's a link to our GitHub: link

Final Result

Our final solution consists of an accelerometer connected to a NodeMCU via a breadboard inside of the punching bag. This breadboard is powered by an adaptable charger, because while we had intended on using the power supply and a 9V battery, we realized that was not enough power for the NodeMCU to function properly. The NodeMCU inside the punching bag gets readings from the accelerometer, and sends the acceleration readings wirelessly to another NodeMCU, which is connected to an arduino, which is connected to an LCD display screen. The NodeMCU and Arduino communicate using I2C protocol, because the SPI pins are taken as the LCD display screen communicates with the Arduino over SPI. Once the second NodeMCU transfers the readings over to the Arduino, we do most of our work there.

First of all, the Arduino converts the accelerometer reading into our score: we scaled the score by dividing accelerometer readings by 7, to ensure our output score will be a 3 digit number. We also have a few clever functionalities here. For example, the punch will only register if the reading is above a certain threshold, so that we know this was an actual punch and new scores won’t just get printed out while the punching bag is sitting idle. Furthermore, we also make sure to take just the first reading, and this is important as there are many different acceleration readings generated as the punching bag swings back and forth after a punch.

Once we figure out the score, the rest of the code mostly deals with our LCD display. Our LCD display screen features a Score section at the top of the screen, which prints out the most recent score. Below that, we have the high score section, which features the top 4 highest scores, and the corresponding names of the players that made that high score. Below that we have a name display, which displays the name of the player currently playing the game, or it is awaiting a user to input their name to begin playing the game. Below that, we have a keyboard, and by default when the game first begins, a red box in the keyboard indicates that we are able to input a 3 character name using a joystick to begin playing (take in joystick inputs via ADC, where the joystick can be moved in the x and y direction, and a press indicates the selection of a character). We decided to limit the player names to 3 characters as it made for a more aesthetic display on our screen (and many older arcade games take this same approach). Once a player enters 3 letters, the game goes into punch mode, where it awaits user punches. At any point, a user can press a button we wired, which then allows the user to enter a new name (so for when the next player starts playing), and the following punches would then be counted under the new users name.

In Conclusion

We really enjoyed working on this project, and we’re really proud of how our punching machine turned out. We spent a lot of time on the project, and we definitely learnt a lot of things through the different challenges we faced, but we are really proud of how we were able to problem solve and work our way through all of them. For example, we had originally planned on using SPI communication between the nodeMCU outside of the punching bag and the arduino, however we realized that the SPI pins were being used by the LCD screen, so we had to use I2C instead. Figuring out how to write the code for the I2C communication was one of the biggest challenges of the project. Another big engineering challenge we faced was figuring out the specific game play logic, and then implementing it in code. For example, we decided that it made sense for a player to enter their name before they punched, and that they could punch as many times as they wanted without having to re-enter their name. We had to deal with quite a few bugs in this arena, as sometimes a player high score would be entered into multiple score lines on the high score chart. However we are very proud as we were able to have a relatively bug free game working by the time of the demo, and we were very proud as we saw many members of the class eagerly testing our game out, and competing to see who would get the highest score!

Something that could’ve been done differently, and something that we would definitely do next time is to purchase a different punching bag. The punching bag we got consisted of a uniform dense foam material, instead of what we expected, which would be a rubber/leather cover that could be opened up by a zipper, and there would be softer foam inside the zipper. Our punching bag meant that we could only use the accelerometer, as there would be no way of attaching a force sensitive resistor, which leads to the least ideal part of our game: sometimes the scores can be a little glitchy, because a softer punch, if landed correctly, can result in a larger acceleration reading from the accelerometer. This would likely be mitigated if we could use a force sensitive resistor or some other kind of pressure sensor. Another thing that would ideally have been done differently would be to use a larger LCD display screen, where the player and audience could directly be able to see a score after a punch, but obviously, this would have taken us above our budget of $200.

If we had more time, we would also like to have been able to allow for high score storage, which would mean that from session to session, the high score would be stored, and not wiped every time we reflashed code from the arduino. We thought about ways we could implement this, such as having an external hard drive storage, or being able to read pixels from the screen and then storing them in variables in code. However, we simply did not have enough time to do this.

Last but not least, we figured out the ideal way to power the breadboard inside of the punching bag a little bit late, as we had been trying to resolve issues with it for a long time, and so the punching bag housing unit could’ve been made to look a lot better, and that is definitely something we would do next time/if we ever would present this punching machine again.

Built With

  • atmega328p
  • avr
  • c
  • esp8266
  • nodemcu
Share this project:

Updates