# Do accelerometers know when they are moving straight up or straight down?

I need a sensor that I can only place on top of an object, to count the number of times the object moves up and down.

Would placing an accelerometer on top of the object accomplish this or can it track the transition between moving up and down?

If not what type of sensor(s) would accomplish this?

---------------- EDIT: -------------------------

Ideally I would like a sensor I can set on top of the box outlined below and count the times it goes up and down. It has multiple guide rails that prevent it from twisting. I plan on using an arduino as a microcontroller that does the math, just need a sensor capable of sensing the up/down motion. All suggestions welcome. thanks.

   +    +
+    +
+    +
------------
|   box    |
| moves up |
| and down |
------------
+    +
+    +

• An accelerometer will measure when there are changes to the velocity of an object. If an object was moving at a steady rate the accelerometer would show zero output. The faster the change in speed the larger the measurement the accelerometer will show during that time. – Michael Karas Feb 9 '15 at 15:57
• So based on my above comment an accelerometer can be used to measure when an object starts to move from a rest position or when it changes direction. The device itself is just a sensor and does not have any "know". You have to connect up some other circuit or microcontroller that will note the outputs of the accelerometer and count the changes to "know" when the object is changing position. – Michael Karas Feb 9 '15 at 16:01
• I think to suggest a better way would require knowing more about the application. There are an uncountable number of ways to measure motion and position - the one that works best depends entirely on what is moving, how it is moving, where it is (and what's around it), what sources of power are available or convenient, how accurate the solution must be, how much noise must it reject, how reliable it needs to be, etc. If you can supply more detail about the application you'll probably get better answers. – J... Feb 9 '15 at 17:48
• Just out of curiosity, what makes the box move up and down? (I mean, why can you not detect the movement indirectly by looking at the controls?) – copper.hat Feb 10 '15 at 3:42
• @MichaelKaras - Sorry, but your characterization of an accelerometer is wrong. An accelerometer held stationary in a 1 g gravitational field will (if the sensitive axis is vertical) report that it is accelerating vertically at ~9.8 m/sec^2. This, as a matter of fact, is the first postulate of General Relativity. – WhatRoughBeast Feb 10 '15 at 18:37

I think an accelerometer and arduino is a great way to count the number of times the box moves up and down. It's a compact, reliable, non-contact way of detecting movement.

It could work for movement as gentle as the rise and fall of your chest, when breathing, lying down, and certainly anything faster than that.

You might get away with a simple threshold detector with some hysteresis - count one when the acceleration exceeds +x, then set the threshold to -x, until it crosses -x, then set threshold to +x.

If the acceleration is more gentle, or there is background vibration which you don't want to count (even though it is actually movement up and down), then the signal might be lost in the noise.
Then you will have to implement a simple digital filter on the arduino, that in effect "searches" for movement at a particular rate. This could be a simple as just adding up the last 100 acceleration samples (at 100 Hz) and putting the average through the threshold detector, or you could design a more elaborate filter.

If you're planning to use an accelerometer for anything, try it out first with your smartphone.

Look on your app store for an accelerometer monitor app, something that records the sensor to a file, and do some experiments. If it makes a CSV file, you can open it in excel and plot graphs etc.

The accelerometer in your phone is quite basic and noisy, but is a good substitute for any other sub-$100 accelerometer, and might give you a rough idea of what a$1000 one could do.

Here's an example of what I've done with the phone's sensor.

In general, no. Imagine throwing a ball straight up (and ignore wind resistance): once it's moving, the only force on it is gravity, which produces a constant acceleration. There's no way to know from the acceleration alone, when the ball has reached its highest height and started back down – the acceleration is the same throughout its path until it hits the ground.

If you know that the object is starting at rest and you measure its acceleration you can figure out its velocity by integrating acceleration over time. If it slows down you'll see a negative acceleration, and the integral will go to zero when it stops. Then when it starts moving again you'll see a change in acceleration and you can start integrating all over again. However, this depends strongly on the accuracy of the measurements and the calculations. If either one is off by a little bit the error will gradually increase until you no longer know what's really happening.

• Not just accuracy - an actual IMU has to know its rotational orientation at all times in order to apply the acceleration measurements. – Chris Stratton Feb 9 '15 at 16:57
• @ChrisStratton - I didn't say this, but I was assuming straight-line motion. Is your comment still correct in that unrealistically constrained situation? – Pete Becker Feb 9 '15 at 18:54
• Simply at 9.8 m/s to the observed acceleration. – Loren Pechtel Feb 10 '15 at 4:21
• @LorenPechtel: That's necessary anyway, but doesn't fix the integration issue. Imagine a box going up, slowing down to almost a standstill, and accelerating again. Now imagine a second box which slows down slightly more, so it momentarily goes down, before going up again. The difference can be minimal, but the up/down counter must differ. If your integration is slightly off, you won't notice the difference. – MSalters Feb 10 '15 at 9:18
• Wouldn't an accelerometer measure zero for an object in freefall? It's really more of a G-force measurement isn't it? – Octopus Feb 10 '15 at 21:05

Firstly it's important to understand how an accelerometer behaves in a gravitational field, such as we experience here on earth. An accelerometer does not measure acceleration, in the sense that it does not measure the change in velocity alone. It measures change in velocity plus gravity - which means that you need to take the measurement of gravity out if you plan to attempt what you outline.

Also, the gravity will be measured as an upwards acceleration - which is somewhat counter-intuitive but makes sense if you imagine an accelerometer as being built something like this:

simulate this circuit – Schematic created using CircuitLab

I've abused the schematic editor to show a ball bearing suspended in a tube by two perfectly damped springs. Imagine that the accelerometer makes its measurement by telling you how far from the resting position the ball bearing currently is. Now imagine turning this device on its end, and you can see how the ball bearing sags down under gravity, and how this is indistinguishable from acceleration. I think relativity has something to say on this topic, but anyway.

So - if you have a vertical accelerometer, and you remove the effect of gravity, and the movements of your device are sufficiently larger than the noise floor of your accelerometer, and moreover the movements are sufficiently smooth to not confuse your algorithm - then it might be possible. There's a answer above that mentions freefall, which would be a problem, but I'm assuming from your description that your device will not be in freefall for any length of time. This is a guess though.

If you really do want to use an accelerometer your best approach to a problem like this is to record the accelerometer's output somehow (I prefer to output it over SPI and record it using a USB logic analyser) and write down exactly what you do (or even video it, if you're really keen). Then you can play around with algorithms offline, without the overhead of constantly wondering if your Arduino is really doing what you think it is.

As others have mentioned, other types of sensor may be more appropriate. We'd need more detail about exactly why you're attempting what you're attempting to comment I think.

• This isn't just an accelerometer quirk - an object that's sitting in a uniform gravitational field is indistinguishable from one being uniformly accelerated. In a sense, the accelerometer is right when it says an object sitting on the ground is accelerating; we just don't think it is because we're accelerating at the same rate. – cpast Feb 10 '15 at 19:27
• Yes - I realise that. The accelerometer is as right as it's possible to be - but it's fairly counter-intuitive that a motionless vertical accelerometer in a gravitational field measures an upwards acceleration. – Dave Branton Feb 11 '15 at 20:20
• I think this is a better explanation: Imagine a man on a scale in a lift. The scale displays the force it applies to the man (divided by g). First, it displays the real weight, but when the lift starts moving upwards, it displays a higher weight. And even the man feels himself being heavier. Also a accelerometer just measures the force it applies to a small mass. – sweber Feb 13 '15 at 8:22

If the object moves up and down on fixed guides, I think the easiest way to count its movements would be to use a limit switch that would be closed when the object is at rest, and open when away from its rest position.

Careful, a reversal of acceleration doesn't mean the box turned around. The box starts up--you see upward acceleration. It's now moving up at a steady pace--you see no acceleration. It slows to half speed--you see downward acceleration. It continues at half speed--you see no acceleration. It speeds back up--you see upward acceleration. It stops, you see downward acceleration.

You saw up, down, up, down but the box really only moved up. You will have to integrate over time and have enough accuracy in your accelerometer to figure out what way you really are going--watch you for cumulative error, it could make this problem very hard!

Have you investigated using a laser range finder to measure where the box is?

• Indeed you need to integrate twice over time - once to get velocity, and once to get distance - which is going to be rife with cumulative error. – abligh Feb 10 '15 at 18:52

Accelerometers are measuring accelerations. If the movement is performed with acceleration, it will be detected, given the accelerometer is sensitive enough on this axis. The direction of the acceleration will be indicated by the sign of the read values. Please note, that when measuring accelerations on the vertical axis, the measurement will be biased by the gravitation acceleration constant g.

• "If the movement is performed with acceleration" The object is initially at rest. It couldn't possibly enter a state of motion without accelerating. – David Richerby Feb 10 '15 at 9:14
• Yes, but the question is in which stages the motion has to be detected. – Eugene Sh. Feb 10 '15 at 13:25

If you don't want physical contact (such as provided by a typical limit switch or microswitch), you could mount a magnet and use a reed switch or a hall effect switch. Or mount something that sticks out slightly and is opaque, and travels through an optical detector (the sort with a small slot in it).

An accelerometer is complicated, more expensive than any of the above, and for the reason eloquently explained by Pete Becker (and now also by Dave Branton), is unlikely to work.

• It might be worth noting that the situation @TheDudeAbides describes is somewhat reminiscent of a pedometer. – user3334690 Feb 9 '15 at 21:59
• @user3334690 I suspect the limited degree of accuracy that pedometers have is partly down to the predictable nature of the human step. If we could arrange to attach magnets to every floor surface, I suspect we could make them more accurate with hall effect switches :-) – abligh Feb 9 '15 at 22:02

A lot of great info here, but I haven't seen anyone suggest a linear potentiometer ...

Simple, apply voltage and count how many times the GPIO reads a HI. Cheapest linear pot? Volume slider from an old radio, trim adjustment from R/C toy controllers, etc

• Are you implying mechanical connections between object, pot, and stationary base? Would that not introduce new forces and resistances. – Octopus Feb 10 '15 at 21:12

If its following rails, what about using an ultrasonic range finder? The arduino can do the math to determine acceleration, and it will be a lot simpler implementation than attaching wires to something that moves. This will certainly work best if the track is straight. Here is one. https://www.sparkfun.com/products/639

• Welcome to electronics.stackechange! I hope you will feel at home here! – WalyKu Feb 10 '15 at 14:06

I would recommend using two thin metal plates to form a capacitor. One plate would be placed on top of the box and the other fixed at some height from the box. As the box moves up and down, the capacitance (C) will vary due to the change in the separation (d) of the plates (C = kA/d). This change can be "converted" by appropriate means to a change in voltage, frequency, etc. and then to a form appropriate for the arduino's interface (amplification might be necessary).

• This will not work. 1: Though we got no dimensions, play a bit with numbers and you'll see the dynamic range is large while the capacitance can be very small. 2.: If the setup is made of metal, each of your plates forms a capacitor with the setup. I.e. you have two caps in series with varying cable length between them. The capacitance will be more or less constant. There are capacitive sensors, but their principle is different and they can measure differences of not much more than 1cm. – sweber Feb 13 '15 at 8:41

## protected by Nick Alexeev♦Sep 6 '15 at 4:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).