Accelerometers
Accelerometers measure linear acceleration and also gravity; the two are indistinguishable. Thus they unavoidably function as tilt sensors as well. Inexpensive 1, 2, and 3-axis accelerometers are available which are constructed with MEMS techniques. MEMS gyroscopes are also available, for measuring angular velocity, but are more expensive.
The LIS2L02AS4-TR accelerometer gives you a choice of +/-2g or +/-6g full scale. It needs only a single +5V supply. Its bandwidth is from DC to 1.5KHz. The output is usually low-pass filtered in applications which do not need the full 1.5KHz bandwidth, using an external capacitor.
The chip is available only in a surface-mount SO-24 package. Fortunately an adapter socket (Digikey A322-ND) can be used to give the chip convenient DIP-24 legs.
Soldering the chip into the adapter socket is a little challenging. Here are some tricks that make it easier. The more of these you can take advantage of, the easier it will be.
- Use a very fine pointed soldering iron and fine solder.
- Apply a bead of liquid flux to the pads, which will make the solder flow in between the pin and the pad enthusiastically.
- Tape the chip down onto its socket adapter.
- Have a magnifying lens or loupe available.
- Know which pins are not used.
The last point is especially useful. Start with pin 1 which is NC (Not Connected), so that even if you get a solder blob connecting pins 1 & 2 that's ok. If the other pins are all aligned with their pads, pin 1's solder will now hold them there. If not, melt pin 1's solder and adjust.
Now solder only the other pins that are in use, as shown in red on the diagram. Solder one or two on the opposite edge as well, for mechanical stability.
Pins marked "reserved" should not be solder-blobbed to their neighbors because we don't know what they connect to inside the chip. Reserved is not the same thing as NC.
Use a supply shunt near the chip (1uF) from +5 to ground). Use low-pass filter capacitors on the outputs (called Cload in the diagram). The output impedance of the chip is 110Kohm, so a 0.1uF capacitor gives a low pass time constant of ~10mS.
Tie ST, PD low, and FS low for +/-2g full scale operation. The output voltage ranges 0-5V, well matched to PIC inputs. 2.5V is the output when acceleration is zero and and the chip is horizontal (not tilted.)
The circuit shows some optional buffer amplifiers to produce a low impedance output.
Accelerometers and Low Pass Filtering
When using accelerometers in applications with high ambient vibrations, filtering the output signal is essential for limiting noise. While in many cases first order (RC) low pass filters may be sufficient to attenuate ambient vibration, if those vibrations are great in magnitude and/or relatively close in frequency to the desired output, second order filtering may be necessary. In addition, in order to protect the accelerometer from sourcing excessive current and dropping its output voltage, it is advisable to use active rather than passive filtering. Both of these criteria are met by Second Order Active Filters, specifically a second order active low pass filter.
The one major disadvantage of a second order filter is an increased maximum lag from 90 to 180 degrees but as with any filter, if C and R values are chosen carefully, the desired signal should not lie within that range.
Two Axis Accelerometer Analog Devices ADXL203
This accelerometer from Analog Devices is very useful due to its availability from circuit suppliers as an evaluation board. Although the component itself is small it comes mounted to a board which allows it to be plugged into any breadboard for testing and prototyping. The range of the accelerometer is ±1.7 times gravity which is useful when the primary value of interest is the angle of a plane with respect to gravity.
The accelerometer takes in a 5V power signal and outputs two voltages which are the x axis and y axis outputs. When the accelerometer is perpendicular to gravity both the x and y outputs read a voltage of about 2.5V. Tilting in the x axis has no effect on the y output but will cause the x output to vary from 1.75V at -45 degrees to 3.25 at +45 degrees. The same response is given for tilting the accelerometer solely in the y axis.
Orientation of a Three Dimensional Object
Because the accelerometer gives the same response whether the face is up or the face is down, two accelerometers are needed to distinguish between these two orientations. The second accelerometer should be oriented out of plane with the first accelerometer, preferably at a 90 degree angle. With this placement of the two accelerometers the face down or face up orrientation of the first accelerometer can be determined from the outputs of the second accelerometer.
Using the Output
To read the x axis and y axis outputs, which are analog voltage signals, you can use the analog to digital converter built into the PIC. This converter takes in the analog signal and converts it to either a 10 bit or 8 bit value which can be understood by the PIC. A 10 bit value will have greater resolution. With 10 bit resolution a signal of 5V would have a decimal value of 1023 (binary 1111111111) and a signal of 0V would have a decimal value of 0. All other voltage values can be determined by a linear relationship between these two points. For example, 2.5V would have a decimal value of 511.
To determine which side is upwards, the controller can compare the four accelerometer outputs. When any side is facing upwards, one of the four accelerometer inputs will be either very high voltage (greater than 3.25V) or very low voltage (less than 1.75V). The controller checks the accelerometer output values until one of these conditions is met and references the correct side as being upward.