Problem in programming a boxing machine

Welcome
How are you, my brothers?
I'm in the process of designing a project using Arduino, but I'm running into some problems

First, the project is a boxing game machine, as in the attached picture
I have finished the mechanical and exterior designs

The code has been written

The parts that were used to measure the force of the punch were the Arduino MEGA and the ultrasonic sensor
Because when the ball is punched, it is attached to a piece of metal. When the ball is touched, the metal piece rises towards the ultrasonic sensor

Within the code, the farthest and closest distances for the piece of metal that rises after joining it are specified, and according to this change, the number appears on the screen, which is the force of the punch.
As follows

Firstly, when it is not working, the coin must be 14cm away from the sensor
Depending on the force of the punch, the rises

The maximum height is 3cm from the sensor

For every 1 cm the number 100 appears on the screen
in another meaning
14 cm screen 000
13 cm screen 000
12 cm screen 100
11 cm screen 200
10cm screen 300
9cm screen 400
8cm screen 500
7 cm screen 600
6cm screen 700
5cm screen 800
4cm screen 900
3cm screen 900

But the first problem I encountered was the following:

Sometimes the piece rises until it reaches a distance of 5 cm, and the number 100 appears instead of 800
Sometimes the piece rises until it reaches a distance of 11 cm, and the number 600 appears instead of 200

The second problem is:

Sometimes, when not working and without the piece rising, the distance is 14cm, and the display shows 100 instead of 000.

The third problem is the one that causes me a lot of pain in my head
she:
Inside the machine is a 24 volt DC motor that operates via a piston and ball release connector
When the contactor turns on the motor, the Arduino stops (stops receiving any signal) until the power supply is cut off and reconnected, noting that the motor, connector, and its power source are completely separate from the Arduino, sensor, and screen.

I hope you can help as soon as possible and I apologize for the long explanation

1 Like

Well it depends how fast your read during a "punch"...
➜ You should detect the punch and wait until the shortest distance has been measured to decide what to show

besides that, we can't help much because we miss the code and the exact circuit schematic

➜ please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).

PS:

so why 13 cm is 000 and not 100?

same at the other end, why is 3cm the same as 4cm?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.