Detecting collision with MPU6050

Hi. I'm currently working on a lightsaber and I got the movement detection to work but not the collision. How would I detect the crash?
I'm using an Arduino Nano IoT and I have a gy-521 board.
I looked on google for a long time.
Right now, my code detects if the MPU6050 goes to -1000 after it moves. And it doesn't work. I also tried going to 0.
I attached only the part with the MPU6050.

Testing.ino (866 Bytes)

Welcome to the forum

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to read, copy and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

I'm not sure if an accelerometer is the right tool for the job. How would the accelerometer know the sword is simply not moving, versus a hit?

If the swords make contact, just listen for the sound.

Microphone

-jim lee

SteveMann:
I'm not sure if an accelerometer is the right tool for the job. How would the accelerometer know the sword is simply not moving, versus a hit?

If the swords make contact, just listen for the sound.

It would move and then stop and thats how the mpu6050 would work for. And also I don't feel like buying more parts.

Have you collected accelerometer data sets of when the device is swinging through the air and when the device hits an object?

I would venture to write that once a few data sets are taken, it should be possible that by using a peak detection library to discriminate between regular movement over contact.

SteveMann:
I'm not sure if an accelerometer is the right tool for the job. How would the accelerometer know the sword is simply not moving, versus a hit?

If the swords make contact, just listen for the sound.

I might actually try this because apparently i have a sound sensor on hand

nonsensicalman:
I might actually try this because apparently i have a sound sensor on hand

Nvm it's just as annoying to work with

Idahowalker:
Have you collected accelerometer data sets of when the device is swinging through the air and when the device hits an object?

I would venture to write that once a few data sets are taken, it should be possible that by using a peak detection library to discriminate between regular movement over contact.

I suspect contact will mean a bounce, just like switch contacts bouncing.
Paul

step #1 is indeed capturing many samples of lightsaber just moving (no collision) and then with collision.

if you use a fast (ESP32 like) arduino, you might actually try machine learning and use "TensorFlow Lite Micro"

you could also use an Arduino Nano 33 BLE Sense which has the IMU (LSM9DS1) on board and the power to handle machine learning (TinyML) with a 32-bit ARM Cortex-M4 CPU running at 64 MHz (it even has a MP34DT05 based microphone that could provide supplemental data)

an introduction to AI / ML is here

J-M-L:
step #1 is indeed capturing many samples of lightsaber just moving (no collision) and then with collision.

if you use a fast (ESP32 like) arduino, you might actually try machine learning and use "TensorFlow Lite Micro"

you could also use an Arduino Nano 33 BLE Sense which has the IMU (LSM9DS1) on board and the power to handle machine learning (TinyML) with a 32-bit ARM Cortex-M4 CPU running at 64 MHz (it even has a MP34DT05 based microphone that could provide supplemental data)

an introduction to AI / ML is here

I guess that makes sense, but is there no way to just detect that it moves and them stops?

"Moves and then stops" means acceleration, which an accelerometer is designed to measure.

Acceleration, which is change in velocity per unit time, can be positive or negative.

The thing is how do you detect the hit versus just moving the saber back and forth in the air ?

Hit = large, short spike in acceleration.

Inexpensive consumer grade MEMS accelerometers were developed to deploy air bags in automobiles during collisions.

Airbags are generally triggered by negative forces of more than 20 Gs (hitting something hard at more than 25km/h that stops the car).

The best way is to Give it a try - I think it’s going to be difficult to not have false positive with just a spike, you'll have the compare the spike from a hit with the spike from just regular movement (moving back and forth the saber)

J-M-L:
Airbags are generally triggered by negative forces of more than 20 Gs (hitting something hard at more than 25km/h that stops the car).

The best way is to Give it a try - I think it’s going to be difficult to not have false positive with just a spike, you'll have the compare the spike from a hit with the spike from just regular movement (moving back and forth the saber)

I suppose that makes sense. Would that just be an issue of sensitivity? Because with swings it would come to a stop slower that a sudden crash.

nonsensicalman:
I suppose that makes sense. Would that just be an issue of sensitivity? Because with swings it would come to a stop slower that a sudden crash.

Nevermind. I think I get it now.

the accelerometer does not detect a "stop" per se, when you see no acceleration (besides gravity) it means you are at steady speed (including speed of 0, so no motion)

looking at patterns and spikes (ie sudden change above a given threshold) could give you some hints, but that needs to be tested. I'm just saying I'm unsure it's enough

Say you hold your lightsaber as an extension of your arm and move up and down and assume the sensor is at the tip of the lightsaber. The sensor is moving on an arc of circle ("rotating" around your shoulder)

  • say you start moving up --> you see acceleration on the vertical axis and one of the horizontal axis
  • you start moving down --> you'll see a change with negative acceleration
    depending on how fast you change direction, you'll see a spike

Now if you have a hit along the way, you'll see a some acceleration on some axis depending how you are being hit but it's difficult to quantify how the hit will be measured compared to just performing movements without a hit

You should be measuring the magnitude of the acceleration, which is independent of direction and always positive. This will be large for a hit or sudden stop. If ax, ay, az are the X, Y and Z components of the acceleration,

float acc_mag = sqrt( ax*ax + ay*ay + az*az);

Also, the sensor will be most responsive if it is in the tip of the light saber, which is usually moving fastest and undergoes the largest acceleration (deceleration) when stopped.

Don't forget the relationship between acceleration and force: acceleration = force/mass, which means that small forces can cause large accelerations for lightweight objects such as a light saber.

Time to build your thingy (or just tape the MPU-6050 AND the Arduino to the end of a wooden stick, no long leads allowed for I2C connections) and show us some measurement results!

Don't worry, the sensor is rated to survive 10000 g crashes.

1 Like

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