2.1.14. Exercise: Read Analog Accelerometer

2.1.14.1. Objective

Measure motion and tilt as numbers. Use the serial port for debugging.

The world is an analog place; physical phenomena have continuity and exist over time. To represent a physical property computationally, the physical process information must be transduced into electrical form and then converted from an analog voltage into a digital number by an analog-to-digital converter, or ADC.

This is a wide and deep topic ranging from signal and information theory to robotics and epistemology, and we will only just begin to explore this idea. But to start, this exercise will represent a physical pose and trajectory as several streams of integers.

An accelerometer is essentially a tiny mass suspended on three tiny springs at right angles. Each output is the measured deflection of one of the springs When at rest, gravity pulls the mass down and the three outputs reflect the direction of the gravity vector. When in motion, the acceleration of the chip pulls on the mass through the springs, and the output reflects the combination of the gravity vector and the acceleration vector. When falling, all springs can relax and the output is the zero vector.

../../../_images/read-analog-accel.png

2.1.14.2. Steps and observations

  1. Wire the circuit on the breadboard. Note that this module has amplified voltage outputs which can drive the analog pins directly. (It is not a resistive sensor like the photocell.)

  2. Connect the Arduino to a USB port for power and use a DMM to verify that the accelerometer outputs vary with the tilt of the device.

  3. Load and run the ReadAccelerometer sketch.

  4. Within the Arduino IDE, open the serial monitor console and make sure it is set to 9600 baud.

  5. Observe the numbers printed in the serial monitor as you tilt the sensor slowly.

  6. Try slowing the sampling rate by increasing the delay.

  7. Determine the highest and lowest values observed.

  8. Observe the noise in the numbers for different constant inputs.

  9. The numbers produced by the ADC are a voltage measurement expressed in the somewhat arbitrary units of the converter (e.g. 4.9 mV/unit).

    The arithmetic for the calibration mapping can be as simple as multiplying by a constant gain and adding an offset (e.g. a linear function); the key point is choosing a units system which is understandable and deciding how to take repeatable reference measurements.

    A sample calibration is in the code; formulate a strategy for calibrating the measurement so that the numbers are more precise.

  10. Try jerking the sensor along one axis without tilting it; can you see the transient signal in the corresponding axis?

2.1.14.3. Comments

The Arduino analog inputs are converted at 10 bits of precision, that is, voltages between 0 and 5V are measured as integer numbers between 0 and 1023, with a nominal resolution of about 4.9 mV per step. However, analog noise in the conversion also limits the precision, so the minimum detectable signal change may be somewhat larger.

The frequency resolution is determined by the sampling rate and the Nyquist-Shannon sampling theorem, which states that a periodic sampling rate must be at least twice as fast as the highest frequency in the input. The Arduino ADC converter runs at a maximum of about 10 kHz, so in principle it can measure signals which vary at up to a 5 kHz rate.

2.1.14.4. Next Steps

There are many other sensor modules in the lab which can conveniently measure physical properties with minimal circuitry. Not all run at 5V, so be careful to check the specifications and test the supply voltages before applying power. Many modules require tightly regulated voltage and will be destroyed at higher input voltages and malfunction at lower input voltages.

A buffered or amplified module can drive a modest current through the output if needed; it has a low-impedance output. Many unbuffered or unamplified sensors only output a small current or voltage and require an amplifier to bring the signal to a usable level. When in doubt, consult the datasheet or spec sheet for the module for specific details of the output signal.

For a challenge, try testing a GP2Y0A21YK0F Analog Distance Sensor: these are very useful active sensors which emit infrared light and measure the distance to the nearest object using the parallax of the reflection.

Other challenges: try testing a joystick, the TEMT6000 Ambient Light Sensor, the “Electret Microphone” module which measures the overall sound energy level, or the ENC-03RC single axis gyro. These are all sensors with analog outputs; some of the other stock communicates digitally over I2C, which we will use in a later exercise.

2.1.14.5. Arduino Code

  1. Documentation: ReadAccelerometer Arduino Sketch
  2. Sketch Folder: ReadAccelerometer

2.1.14.6. Suggested Layout

../../../_images/read-analog-accel-layout.jpg

2.1.14.7. Other Files

  1. EAGLE file: read-analog-accel.sch