Did you have a project that detected if it was moving?

As I embark on my first serious project on Arduino, greatly appreciate your help on my question.

I would like to find out how I can detect if my project is moving at any instance and if so the direction of the motion. As an example, I want to detect if a car is moving from inside the car without any access to outside of the car's interior (say, the wheels or view of static objects on the street through the window) to use it as a reference.

There are numerous questions on this topic in this and other forums. After going through as many of them as I could find, it seems to me there are few prevalent solutions:

1) Use an accelerometer and use general laws of dynamics to detect if there is any distance traversed from the acceleration detected. For example, see this: http://forum.arduino.cc/index.php?topic=256184.0.

2) Use a spring-in-tube vibration sensor (such as this: http://www.beelee-switch.com/prodcuts/Tact-Switches/prodcuts/vibratio/051292012.html). However, it is not clear to me if it detects simply vibration as opposed to a motion (with a linear or non-linear direction).

My question is: have you actually used any of them (or something else) and got results similar to what I am describing? I am only interested about practical answers that worked for you, not theoretical discourses.

Thanks again in advance for your valuable direction.

An acelerometer only has three axis so you have to use Trig to calculate direction from x & y axis values ( Pyhagorean Theorem or some such). You can only detect acceleration which goes to zrro if veocity remains constant so when you slow down and turn a corner and speed up to the speed limit the aceleration becomes zero when you reach speed limit and stop acelerating.

Obviously, GPS has no such limitations.

you might add a compass to see in which direction it is moving (and to detect rotation?)

I should add that:

  1. This is a cost-sensitive project. A GPS module will set me back for ~$35 USD. A cheaper option is preferred.
  2. Please include references (datasheet etc.) whenever possible.
  3. I would like to get feedback only from other designers who actually did similar projects. As I have mentioned, I already have seen numerous solutions that 'theoretically' solved the problem.

I would like to find out how I can detect if my project is moving at any instance and if so the direction of the motion.

In general, this is not possible. That is simple physics (Newtonian relavitivity).

Furthermore, you have not defined the specifics of how your "project" is expected to be moving, so no one will be able to give you relevant technical advice.

I would like to get feedback only from other designers who actually did similar projects.

Yes I would agree, detecting velocity inside a frame of reference is impossible. Detection acceleration is but you can not imply anything from that.

So anyone saying they have done it is is not telling the truth.

To be more clear, it is impossible to detect or even define uniform motion of any object without using an external position reference.

You can use an accelerometer to detect [u]changes[/u] in motion, but that doesn't tell you anything about the motion itself. However, given the inexpensive accelerometers available to hobbyists, accurately detecting changes in motion can be difficult. This is because all objects near the Earth's surface are subjected to a constant acceleration of 9.8 m/s^2 due to gravity and that has to somehow be separated from accelerations caused by other forces.

To clarify on detecting acceleration versus velocity: I will know the initial condition (velocity = 0 at time = 0 as in the example of the car I gave originally) for motion. There were several threads on this forums to discuss the need of an initial condition set so I did not mention that explicitly.

However, my intent is to find out if anyone actually applied an accelerometer for this purpose successfully. Or perhaps any other sensor or technique.

sm535: anyone actually applied an accelerometer for this purpose successfully

Sure, I've flown a quad-copter stabilized with accelerometers. I used someone eles's code but I did read the hardware datasheets and combed through the code to get a fair idea of what was going on.

The field of AHRS (Attitide, Heading, and Reference Systems) using IMUs (Intertial Measurement Units) is fairly mature, the military has been doing it for decades in order to create INS (Inertial Navigation Systems). You are setting out to explore well-trod soil. It is simple enough to use accelerometers to measure the magnitude and direction of travel assuming a 0 velocity starting frame of reference. You will find, though, that consumer-level hardware is subject to "drift". That is, if you start at 0, accelerate to a few dozen MPH and take a couple of turns and then stop, your directional accuracy would have degraded. The more starts and stops and turns you make, the less accurate your computed solution will become until it is completely useless.

That's why AHRS generally integrates data from other sensors in addition to accelerometers. In your case, you would probably want to use a magnetometer to sense magnetic north to cancel out heading errors accumulated over time. GPS would also be useful, to correct velocity errors that accumulate over time. These corrections aren't strictly necessary, depending on the accuracy you require -- you can use software algorithms to compensate to some degree for certain narrow applications.

Datasheets: http://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf

I will know the initial condition (velocity = 0 at time = 0 as in the example of the car I gave originally) for motion.

Well, you need to figure out just what is the frame of reference that the movement is going to be compared to. With your car example, the car may have velocity = 0 in reference to the ground it is sitting on, but it is actually moving quite fast as the earth's surface is rotating, the earth is orbiting around the sun, the sun is moving in this galaxy... Movement is usually referenced to a specific point.

I will know the initial condition (velocity = 0 at time = 0 as in the example of the car I gave originally) for motion.

You are describing the process of integrating the equations of motion to get position and velocity, from a starting postion and velocity, as a function of measured acceleration. Consumer grade accelerometers are not yet accurate enough to permit this process to continue for more than a few seconds before the result is wildly in error. This is a result of measurement errors in the acceleration vector and the need to subtract acceleration due to gravity.

For a clear and quantitative discussion see http://www.chrobotics.com/library/accel-position-velocity Note that there are decimal position errors in Table 1, however, the velocity error column is correct. The position column is high by a factor of 2.

@tylernt (August 10, 2014, 06:39:01 pm) and @jremington (August 10, 2014, 08:13:59 pm): very good inputs. Thanks very much.

Quite frankly, if you want to detect if a car is moving (and how fast), the proper way - when all is said and done - is to tap into the odometer circuit.

That is unquestionably the only sensible way to do it for a car. Of course, for any other situation, the answer may be different.

The simpler version - if you want to know if the car is being driven, then an accelerometer will readily detect road vibration. That tells you it is going somewhere, but not where or how far or fast.

And if you actually need to know where, then of course, GPS is the only way.