Arduino with an Accelerometer

I have a school project where I am making a small device where I attach an Arduino with an Accelerometer to the underneath of a 12"x 12" piece of 1/4 inch metal. I then want to let classmates take a hammer and hit the top of the metal. I hope to capture the amount of gravities (G’s) produced by the hammer swing. My question is after capturing the G’s what can I convert it too that makes sense, like energy or foot pounds or something that shows who hit it the hardest.

Thanks

Why don’t G’s make sense (F=ma)?

athnetix:
… like energy or foot pounds or something that shows who hit it the hardest.

Thanks

A foot-pound is a measure of energy.

http://en.wikipedia.org/wiki/Foot-pound_%28energy%29

To measure the energy instead of just the force, you also need to measure (or estimate) the displacement of your plate (how far did it move).

To measure the Force (F=ma)), what would I need to do, I have the G’s and I have the mass of the hammer. I can capture the G’s every x msec or microsec, will that give me the acceleration (how fast the hammer was going?).

Thanks for all your help…

You have the acceleration the plate undergoes, afterall you’re measuring it. If you know the mass of the plate, you can calculate the force that must have been applied to it. And from that force you could, in theory, find the hammer’s speed just as it hit the plate. The tricky part is that how you suspend the plate makes a lot of difference. Let’s go from the simplest to the hardest case to illustrate this.

If the plate where sitting on a very slippery surface and you hit it sideways (perpendicular to gravity) then you could neglect friction and drag due to air and you could know the force from just the plate’s mass and the measured acceleration. That’s just F = mA. I might be worried that you could sample the acceleration quickly enough to get a true measurement but that’s another point for later discussion.

If you had the same situation as the above but added a spring between the plate and some immovable object, such that the spring would compress when the plate was hit … now you have 2 forces involved, the impulsive force of the hammer blow and the spring’s force. But by knowing the spring constant you could, in theory, figure it all out again. Now turn the plate and spring so they face “up”. And so when you swing the hammer down and hit the top of the plate you have 3 forces that matter; the hammer, the spring and gravity. Again, in theory, you could work it all out.

Now we come to what I think is your case. You have the plate on some 2x4’s resting on the ground. There is no explicit spring. But in reality the wood frame and the flexing of the plate when you hit it are the equivalent of the spring above. The problem I see is that I doubt there’s any way to know this “springs” constant. And you have a condition where the collision is no longer what’s called “elastic”. So the only course I see, if you want to figure out how how fast the hammer was going, is to calibrate the measured acceleration vs known hammer speeds. That is, hit the plate with a wide range of known hammer speeds and see what acceleration happens. Come up with a set of data points that will allow you to mathematically estimate any hammer speed from any measured acceleration. Now you have to know, somehow, how fast the hammer is going during your calibrated hits. There are many ways to do this but one way would be to drop your hammer from various heights above the plate.

During the drop(s) the force acting on the hammer, causing it to fall, is gravity. You know how much force that is. You can reasonably neglect air resistance for the drops you’ll be doing, so gravity is the only force involved. Since you know gravity and the hammers mass, A = F/m. And you can get speed from the acceleration and measured time (to fall). Ideally you could drop the hammer from a high enough place that the hammer speed and measured force is larger than the fastest swing and largest force someone can do during your demonstration. If not, you’ll have to do that thing known as extrapolation.

So do you really want to know how fast the hammer was going ? :mrgreen:

You could try first with the following rule: For a given setup, the person who creates the maximum G’s, wins.

What accelerometer will you be using? If you haven’t tried the experiment, it would be difficult to estimate whether the accelerometer will even record the actual maximum acceleration of the plate without saturating.

The accelerometer I am using is the Single Axis Accelerometer Breakout Board - ADXL193 +/-250g from SparkFun. The setup I was thinking was to have it flat , in a horizontal position to the earth.

Question: when I sample the Accelerometer now, just testing the setup, I see a maximun G count. Is that the G count I should use, or should I accumulate the G’s vs time (at 10 microsec intervals) between samples? If so what do I have at that point, acceleration?

athnetix:
Question: when I sample the Accelerometer now, just testing the setup, I see a maximun G count. Is that the G count I should use, or should I accumulate the G’s vs time (at 10 microsec intervals) between samples? If so what do I have at that point, acceleration?

Every sample is a sample of acceleration. If you want to detect the peak acceleration you need to sample the sensor very quickly. Alas you can not sample as quickly as every 10 usec, at least not with an Arduino. Sticking with the Arduino's analogRead() function the best you could hope for is perhaps a sample every 120-130 usec. And that's about as good as you need because the ADXL 193 has a built in low pass filter of 400 Hz. That means before your Arduino even gets a chance to "see" any short duration peaks, the sensor has smoothed them down a bit.

The question for you is whether you want to “just” detect a peak value and send that single sample to the PC for display or whether you want to send a continuous stream of samples to the PC … or perhaps something inbetween. I ask because the Arduino will take some time to send a sample of data to the PC. That means even more time taken from sample to sample.

For example you might have the Arduino sampling the sensor and “printing” the result so you can see it. That might look like:

void loop(){
  Accel = analogRead(A0);
  Serial.println(Accel);
}

Depending on the baud rate you’re using, that println all by itself can be taking several msecs !

Or you could use a switch/button and do something like this:

void loop(){
  Accel = analogRead(A0);
  if(Accel  > Accel_old){
    Accel_old = Accel;
  }
  if(buttonPin == LOW){
    Serial.print("Largest acceleration detected since last button press = ");
    Serial.println(Accel);
  }
}

The above only saves 1 sample, the largest and only sends it to the PC when you ask for it (by pushing a button). This will take less time for the Arduino to do (until you press the button) so it will sample faster.

There are other, more complicated, ways to save more of the data than just 1 sample. Perhaps up to 500-600 samples if you wanted to. You could get a relatively high speed consecutive sequence of samples every so often or just when the Arduino detects some fairly large acceleration.

I am troubled that you see what you think is a maximum G count. What do you mean by that, exactly ? Just sitting there the sensor should read about 1G due to gravity. If you’re seeing 250Gs before you even hit it, then somethings wrong somewhere. If you’re seeing 250Gs when you hit it, then you’ve got the problem that jremington was worried about above.

Also sounds like you do not understand the Units involved.

Acceleration is in units of distance per time squared (for example meters/seconds^2)

A ‘G’ is the Unit of acceleration due to Earth’s gravity at sea level which is 9.8m/s^2.

So when your accelerometer outputs a value of 2 Gs this is an acceleration of 2 * G = 2 * 9.8m/s^2 = 19.6m/s^2.

If you want the “Force” then multiple the acceleration by the Mass of the object measured (plate). So for a plate of 2 kilograms and measurement of 2 G’s acceleration, the Force = ma = 2kg * 2G * 9.8m/s^2 = 39.2 Newtons.

I think you should take a closer look at the data sheet. First of all, the sensitive direction of that particular accelerometer is in the plane of the package, parallel to the direction perpendicular to the notched end of the package. From your first post, it doesn’t seem that you planned to mount it properly, in order to measure acceleration of the plate.

Second, if you are powering the accelerometer with 5.0 V, you expect an output of 2.5 V if there is no acceleration and a change in output voltage of 0.008 V/g with acceleration. From the datasheet (for the 120g version):

Here’s how I sample the accelerometer, I set a threshold, let say 15 g’s needed to be reached first, I keep sampling until 15 g’s have been reached, I then sample at set intervals, every 10 microseconds until I reach 0 Gs, saving each sample.

Once 15G’s has been reached I start the loop below:

starttime=micros(); //save start time

startloop:

sample and test to see if <=0 G’s if so break

save sample

delayMicroseconds(10); // pauses for 10 microseconds

loop

endtime=micros()-starttime; //calculate total time

so I have the total time in microseconds and G’s from start to finish.

This is what it actually looks like from start to finish in G’s once I do my math and convert to G’s from one test I ran:

20,34,49,51,44,33,25,17,17,17,15,13,10,9,7,6,5,4,3,3,1,1,1,1

As you can see 51 G’s was the max. I’m pretty sure I understand all this, what I was trying to understand is how should the weight of the hammer be applied if any, and if I can calculate the speed of the blow. I have all the G’s and time so I know I could calculate speed based on acceleration, but what is this the acceleration of?

I may try setting it up as like a Gong would be, where it would be perpendicular to the earth, this might insure the accelerometer is in the correct plane.

You are measuring the acceleration of the accelerometer. If it is firmly attached to the plate, then you are also measuring the acceleration of the plate. You can get the instantaneous force (in Newtons) on the plate from the G values by multiplying the plate mass(in kg)9.8G.

You can’t easily work out the speed of the hammer, because it probably bounces, but you can estimate the total momentum transfer by integrating the force with respect to time.

athnetix:
I have all the G’s and time so I know I could calculate speed based on acceleration, but what is this the acceleration of?

It's the acceleration of the sensor. :mrgreen: It moves, perhaps so little you can't see it, because your plate and whatever is holding it, both compress and deform. Perhaps they come back to their original shapes, perhaps not quite.

(click to open and run the gif)

Yes I think that was it… the metal plate compresses so little I couldn’t really tell what or where the G’s were coming from, now if I were to add all the accelerations vs times to determine speed and came up with 100 mph or some other unrealistic number…I would start pulling my hair out!

Many thanks to all that explained it.

100 mph as the peak velocity is not unreasonable.

What acceleration values are you getting?

Here is an actual reading of the accelerometer:

G’s=20,34,49,51,44,33,25,17,17,17,15,13,10,9,7,6,5,4,3,3,1,1,1,1

This took a total of 5543 microseconds – approx. 241 microsec per sample. I have a delayMicroseconds(10) between samples.

51 g’s was the maximum sample.

What would be the MPH of the 51 g’s?

What would be the MPH of the 51 g’s?

The peak acceleration is 51 * 9.8m/s^2 = 500 m/s^2

The velocity = Vi + a * t

But since a (acceleration) is not constant you must either intergrate the accereration over the time or just take each acceleration value at a time. So it would go like this.

at t0 = 0, Vi = 0

at t1 = 0.000241, a = 20 *9.8, v(t1) = 0 + 0.000241 * 20 * 8.8 = 0.047 m/s

now vi = 0.047 m/s, a = 34, so v(t2) = 0.047 m/s + 34 * 9.8 *.000241 = 0.127 m/s

and continue for each measurement

v(t2) = 0.127 m/s + 49 * 9.8 * 0.000241s = 0.243 m/s

v(t3) = 0.358 m/s

v(t4) = 0.479 m/s

v(t5) = 0.483 m/s

etc… you can continue the calculations then convert the maximum velocity to MPH.

(I calc’ed a peak velocity of 0.911 m/s at t24)

Hint: an spreadsheet is handy to do the calculations and conversions.

And here’s is a plot of that data (and more !) from Excel.

(click on to open and enlarge)

I would expect the plate to ring and so produce both + and - G’s. Alas I think the bandwidth of the accelerometer is too low to show this.

Thanks… the plot and the explanation looks great, I should be able to apply this now!

Athnetix:

Would you be willing to share your code for how you collected the acceleration data? I am struggling with doing more than just printing the values on an LCD. I want to be able to graph the information just as you all did below.

Thanks!