Getting Started with an Accelerometer
Acceleration is a measure of how quickly speed changes. Just as a speedometer is a meter that measures speed, an accelerometer is a meter that measures acceleration. You can use the ability to sense acceleration to measure a variety of things that are very useful to electronic and robotic projects and designs:
- Acceleration (of course!)
- Tilt, tilt angle
- Incline
- Rotation
- Vibration
- Collision detection
- Gravity
Accelerometers are already used in a wide variety of machines, specialized equipment and personal electronics. Here are just a few examples:
- Self balancing robots
- Tilt-mode game controllers
- Model airplane auto pilot
- Car alarm systems
- Crash detection/airbag deployment
- Human motion monitoring
- Leveling tool
Once upon a time, accelerometers were large, clunky and expensive instruments that did not lend themselves to electronic and robotic projects. This all changed thanks to the advent of MEMS, micro-electro-mechanical-systems. MEMS technology is responsible for an ever increasing number of formerly mechanical devices designed right onto silicon chips. The accelerometer you will be working with in the forthcoming activities is the Parallax Memsic 2125 Dual Axis Accelerometer module.
This module measures less than 1/2” X 1/2” X 1/2”, and the accelerometer chip itself is less than 1/4” X 1/4” X 1/8”.

People naturally sense acceleration on three axes, forward/backward, left/right and up/down. Just think about the last time you were in the passenger seat of a car on a hilly and curvy road. Forward/backward acceleration is the sensation of speeding up and slowing down. Left/right acceleration involved making turns, and up down acceleration is what you felt going over hills.
Up/down acceleration is also the way we sense gravity. When on the ground, people tend to sense gravity as their own weight. In free-fall, they sense gravity as weightlessness. In physics terms, gravity is a form of acceleration. When an object is on the ground, gravity is sometimes called static acceleration. When an object is rolling down hill or falling, gravity becomes dynamic acceleration.
Instead of the three axes people sense, the MX2125 accelerometer senses acceleration on two axes. The acceleration it senses depends on how it’s positioned. By holding it one way, it can sense forward/backward and left/right. If you hold it a different way, it can sense up/down and forward/backward.
The MX2125 Accelerometer – How it Works
The MX2125’s design is amazingly simple. It has a chamber of gas with a heating element in the center and four temperature sensors around its edge. Just as hot air rises and cooler air sinks, the same applies to hot and cool gasses. If you hold the accelerometer still, all it senses is gravity. When you hold the accelerometer level, the hot gas pocket is rises to the top-center of the accelerometer’s chamber, and all the temperature sensors measure the same temperature. Depending on how you tilt the accelerometer, the hot gas will collect closer to one or maybe two of the temperature sensors.

Both static acceleration (gravity and tilt) and dynamic acceleration (like taking a ride in a car) are detected by the temperature sensors. If you take the accelerometer for a car ride, the hotter and cooler gasses slosh around in the chamber in a manner similar to a container that is partially filled with water.
In most situations, making sense out of these measurements is a simple task thanks to the electronics inside the MX2125. The MX2125 converts the temperature measurements into signals that are easy for the BASIC Stamp® module to measure and decipher.
Connecting and Testing the MX2125
ü Gather the parts listed here, and build the circuit shown below.
Parallax
Part Number Quantity Description
800-00016 (1) 3-inch Jumper wires - bag of 10
150-02210 (2) Resistor – 220
28017 (1) Memsic MX2125 Dual-Axis Accelerometer
The two axes the MX2125 uses to sense gravity and acceleration are labeled X and Y. It will help if you set your board flat on the table in front of you as shown in the figure below. That way, the X and Y axes point the same directions they do on an XY plot. For room temperature testing, you can get a decent indication of tilt by just measuring the high times of the pulses sent by the MX2125’s Xout and Yout pins with the PULSIN command. Depending on how far you tilt the board and in which direction, the PULSIN time measurements should range from 1875 to 3125. When the board is level, the PULSIN command should store values in the neighborhood of 2500.

ü Make sure your board is sitting flat on the table, oriented with its X and Y axes as shown in the figure above.
ü Enter and run SimpleTilt.bs2.
' SimpleTilt.bs2 ' Measure room temperature tilt.
'{$STAMP BS2} '{$PBASIC 2.5}
x VAR Word
y VAR Word
DO
PULSIN 6, 1, x
PULSIN 7, 1, y
DEBUG CLS, ? X, ? Y
PAUSE 100
LOOP
ü Check to make sure the Debug Terminal reports that the x and y variables are both storing values around of 2500.

ü Grab the edge of the board with the Y-Axis label and gradually lift it toward you. The y value should increase as you increase the tilt.
ü Tilt the board straight up and down. The Debug Terminal should report that the y variable stores a value near 3125.
ü Next, instead of tilting the board toward you, gradually tilt it away from you. The y axis value should drop below 2500 and gradually decrease to 1875 as you tilt the board until it’s straight up and down.
ü Repeat this test with the X-axis. As you tilt the board up with your right hand, the x value should increase and reach a value near 3125 when the board is vertical. As you tilt the board upward with your left hand, the x value should approach 1875.
ü Finally, hold your board in front of you, straight up and down like a steering wheel.
ü As you slowly rotate your board, the x and y values should change. These values will be used in another activity to determine the rotation angle in degrees.
___________________________________________________________________
This draft material is part of a forthcoming Stamps in Class text by Andy Lindsay.
(c) 2004 by Parallax Inc - all rights reserved. Post Edited (Andy Lindsay) : 12/11/2004 5:52:41 AM GMT
|