Using ADXL345 3-axis accelerometer/Arduino Nano to count bounces of a pogo stick

I am working on a project for school, and I need to make a bounce counter for a pogo stick that my Capstone team (mechanical engineering) is designing for someone that is going to attempt to break the consecutive bounce record of around 300,000 bounces. I want to use an accelerometer to keep track of the changes in acceleration direction and send the number (divided by 2) to a heads up display of some sort on the pogo stick so the user doesn’t have to worry about counting while he is concentrating.

I am fairly new at programming electronics. However, I am familiar with using Matlab, and have interfaced with various optical sensors using LabVIEW. However, I want to make this system stand-alone, so I bought an Arduino Nano board so I could program the board and just fix it permanently to pogo stick to do it’s job. Some of you may tell me to just use a pedometer, but we have tried this and it does not work. I have thought about using phone apps as well, but I really want this to be part of the pogo stick itself.

Unfortunately, I don’t really have a lot of time to sit down and learn everything there is to know. I am pretty good at looking at other peoples code and deciphering what it does and then using little bits from various places to make code of my own. So, I did some research on some coding for pedometers and the like, but I couldn’t find anything I could really go off of so far.

So, if anyone finds this interesting enough to help, I would greatly appreciate it. Whether it’s personal help with code, or just posting a link to some other programs that may help me, I would greatly appreciate anything. Like I said before, I have other classes and not a lot of time to learn. Thanks!

ANOTHER CUT & PASTER HUH ?

I want to use an accelerometer to keep track of the changes in acceleration direction and send the number (divided by 2) to a heads up display of some sort on the pogo stick so the user doesn’t have to worry about counting while he is concentrating.

Are you asking for help with this ?

I want to use an accelerometer to keep track of the changes in acceleration direction and send the number (divided by 2)

or this ?

a heads up display of some sort on the pogo stick

Or both ?
Read the datasheet.

ADXL345.pdf (649 KB)

Both. Mostly just the code to count the bounces. I can figure out how to send a value to a display, but any help is appreciated. There are always easier ways of doing things.

Are you in this universe ? Have you heard of GOOGLE ?
http://bildr.org/2011/03/adxl345-arduino/

I saw that already. It really doesn’t help me much with what I am trying to do with my accelerometer. I was looking for examples like pedometers to see how they keep track of steps, but haven’t found anything that was really helpful. I think you have been neglecting the fact that I have never touched an Arduino before.

You might be biting off more than you can chew but if you are going to go ahead I can tell from personal experience that whst you need to base your code on is dramatic difference between the measurement levels when you compare the down to up change to the up to down change. One has high g force and the other doesn't , not to mention the fact that once the acceleration in the up direction
stops completely (amplitude=0) at the apex, you know that bounce is completed. If you try to use Acceleration to detect the completion of ghe bounce instead of Deceleration , it will be MUCH more difficult.

I see what you are saying. The acceleration while impacting the ground will be highest. This will happen once a cycle. So do you think setting a threshold in which every time ground contact is made, the acceleration goes over a certain value, and then counting the number of times the threshold is exceeded would be a good idea?

Of course it would take some fine tuning with the actual device to set the threshold correctly.

Exactly wrong. Reread my last post. Think Only about upward motion. When does it reduce to zero?

Well, I haven't hooked this accelerometer up yet to see what it is sensing when, nor have I toyed with one before, but from what I read, If we drop the accelerometer in a gravitational field, it reads zero, no matter what its orientation. It is accelerating downward and yet reading zero, so it clearly isn't sensing acceleration due to gravity. Or, in the terms cited above, it is correctly sensing that the deviation from freefall is zero. So we put the accelerometer on a tabletop. It will sense an acceleration of 1.0G straight up. Since freefall would be 1.0G straight down, the accelerometer is again correctly sensing the deviation from freefall, which is an upward acceleration vector of 1.0G, due to the normal force exerted by the tabletop.

So, from this I gather that at the apex of a jump the accelerometer should read 1G if this is the 0 you are talking about. So count the number of times the 1G value is attained? However, I feel like this will cause a problem while the pogo stick is idle. Maybe sensing variations from the 1G caused by small movements and then counting those subtle movements as bounces.

I am having trouble just getting the example code uploaded to the board to see how it works.

I was trying to follow the procedure of the link you posted, but no luck so far.

I think you are missing something obvious. If you only purchase 1 accelerometer and you mount it on a vehicle (even a pogo stick)
, then if you want to use that acceleromter to measure motion, then your vehicle motion is restricted to 3-axis:
1 (x-axis is an imaginary line extending in BOTH directions ; up & down)
Amplitude : = POSITIVE in ONE direction/NEGATIVE in the other. so if I say UP and you mounted it upside down
(there are markings on it and info in the datasheet to identify correct orientation to make signal polarity correct) then if
I say when POSITIVE signal goes to zero at the APEX of upward motion , but the data will indicate that the apex occurs
when the NEGATIVE signal goes to zero (or vice versa).
2 *y-axis : an imaginary line extending left and right indefinately
3 z-axis: an imaginary line extending forward and backward indefinately.

Which axis applied to UP/DOWN depends on you mounting it per datasheet diagram.
Any way you cut the cake, the data doesn’t lie. If you have a huge spike in one direction and a gradually diminishing signal in the other, the huge spike can ONLY be the impact with the GROUND. When the pogo stick hits the ground , the acceleration suddenly stops and the device measures the g-force of the impact. (the same as hitting it with a hammer on the “ground side”

This statement you made:

If we drop the accelerometer in a gravitational field, it reads zero, no matter what its orientation. It is accelerating downward and yet reading zero, so it clearly isn’t sensing acceleration due to gravity. Or, in the terms cited above, it is correctly sensing that the deviation from freefall is zero

is completely irrelevant because you are not using it to measure downward acceleration. You are using it to measure crash impact of the pogo stick with the earth (DECELERATION, NOT ACELERATION) and to measure ACCELERATION AND DECELATION DUE TO
SPRING FORCE CAUSING IT TO MOVE UP and then decelerate due to gravity to ZERO. We don’t care about any data while it’s falling so the your comment above is in reference to the garbage data we ignore. We only care about :
1 IMPACT WITH GROUND (DECELERATION)
2 ACELERATION IN UP DIRECTION
3 DECELERATION in the UP DIRECTION , tapering down (decelerating ) to ZERO.
4 ZERO ACELERATION at APEX . THIS COMPLETES ONE CYCLE BECAUSE IT IS ONLY POINT WITH NO DETECTABLE G-FORCE and it only occurs once per cycle. When the pogo stick goes into free fall , there’s no g-force (as you pointed out), which is why we ignore that phase.
Do you see a pattern here ? (one you can use ?)

It's the coding and just gettIng the sensor to interfacethat I am struggling with mostly

You need to learn how to use the forum. Read the sticky post "How to use this forum"
If you have a problem getting a circuit to work you need to upload a photo of your circuit with enough detail to see every connection at both ends. If you have a problem with your code you need to post your code using the CODE tags "#" button. Until you do those two things, nobody can help you. If you haven't written any code because you DON'T HAVE AN ALGORITHM (To Paul: I'm not shouting, I'm just raising my voice. There's no way to control the greyscale for the bold) then you need to state that you need help writing the algorithm.
Until you do that you're just wasting everyone's time.

I was just try to follow the tutorial here:
http://bildr.org/2011/03/adxl345-arduino/

I tried uploading the code they were using but was getting tons of errors. I don't know where to start with that.

You should be able to figure out how it's wired up through these pictures.




I don't know how to go about writing an algorithm. I was just trying to get a tutorial to work so I could play around with it and try to figure it out.

I figured out why it wouldn’t compile.
You don’t need IDE 1.0 , You just need 1.0+ (higher than 1.0) so 1.05 is fine.
On the Bildr page there is a button on the left labeled “download”.
Click that to download the zip file. (delete any files you had previously installed for this library first)
Install it in the My documents\Arduino\Libraries folder.
Rename the folder to ADXL345 (get rid of the arduino v6 part)
Close all instances of the IDE.
Reopen IDE and click Sketch\add file and select the ADXL345_Example.ino
It should compile with IDE 1.05

These are the errors I get when I click the upload button:

ADXL345_Example:10: error: 'ADXL345' does not name a type
ADXL345_Example.ino: In function 'void setup()':
ADXL345_Example:14: error: 'adxl' was not declared in this scope
ADXL345_Example:48: error: 'ADXL345_INT_SINGLE_TAP_BIT' was not declared in this scope
ADXL345_Example:48: error: 'ADXL345_INT1_PIN' was not declared in this scope
ADXL345_Example:49: error: 'ADXL345_INT_DOUBLE_TAP_BIT' was not declared in this scope
ADXL345_Example:50: error: 'ADXL345_INT_FREE_FALL_BIT' was not declared in this scope
ADXL345_Example:51: error: 'ADXL345_INT_ACTIVITY_BIT' was not declared in this scope
ADXL345_Example:52: error: 'ADXL345_INT_INACTIVITY_BIT' was not declared in this scope
ADXL345_Example.ino: In function 'void loop()':
ADXL345_Example:66: error: 'adxl' was not declared in this scope
ADXL345_Example:82: error: 'ADXL345_FREE_FALL' was not declared in this scope
ADXL345_Example:88: error: 'ADXL345_INACTIVITY' was not declared in this scope
ADXL345_Example:94: error: 'ADXL345_ACTIVITY' was not declared in this scope
ADXL345_Example:100: error: 'ADXL345_DOUBLE_TAP' was not declared in this scope
ADXL345_Example:106: error: 'ADXL345_SINGLE_TAP' was not declared in this scope

Kind of confused about the IDE part. I believe I downloaded 1.0.5. On the top of the IDE it says 1.0.5-r2

I downloaded the zip file and put it in the folder you specified

The library zip file creates TWO FOLDERS NAMED ADXL3145.
THE EXAMPLE IS IN THIS FOLDER . THIS IS WRONG.
THE FILES IN THE SECOND FOLDER MUST BE MOVED (from the folder named ADXL345) TO THE FOLDER YOU RENAMED
and then the empty folder named ADXL345 SHOULD BE DELETED. THEN CLOSE ALL INSTANCES OF THE IDE and reopen it.

THE FIRST ONE IS THE ONE WITH THE NAME: “ADXL345(Arduino)[V6]” (THIS IS THE ONE YOU RENAME)

Check the files to make sure that your file tree is as follows:
Library folder : name: ADXL345
FOLDER CONTENTS:
file : ADXL345.cpp
file: ADXL345.H
file: License.txt (don’t know if this is important)
file: Read_Me.txt (this one not critical)
subdirectory folder : Example You have to create this folder in the folder you renamed and move the file named ADXL_Example.ino into the folder you just created named Example.
The file tree when correct should be as follows.

contents: file: ADXL_Example.ino (file date 2/19/2012 timestamp:6:44pm filesize 4kb)
see attached screenshot of library folder contents.
Make sure there are NOT TWO folders named ADXL345.
Make sure that the example is in the subdirectory below the library file.
Take some screenshots of the filetree . are the dates and times the same as in my screenshot ?
Did you open it using sketch\add file ?
I got lots of errors until I discovered the download button on the left .

Check my last post. I modified it. read carefully.

Worked this time. Thanks. I think I have a little bit of a hard time following you but I am trying my best. Going to see if I can figure out some things now.

I found the serial display to monitor the activity/inactivity and it seems to be working. The code makes sense so far.

Worked this time. Thanks.

And this means what ? (you were able to compile without errors ?)