Learning Examples | Foundations | Hacking | Links
Examples > Analog I/O
This tutorial shows you how to read an Analog Devices ADXL3xx series (e.g. ADXL320, ADXL321, ADXL322, ADXL330) accelerometer and communicate the acceleration to the a personal computer.
This tutorial was built using the breakout boards from Sparkfun. The Adafruit accelerometer breakout board also works, though the order of the pins is slightly different.
The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. To read this, all you need is the analogRead() function.

Schematic:
click the image to enlarge
An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.
The accelerometer uses very little amperage, so it can run off the output of the Arduino's digital output pins. To do this, you'll use three of the analog input pins as digital I/O pins, for power and ground to the accelerometer, and for the self-test pin. You'll use the other three analog inputs to read the acclerometer's analog outputs.
Here are the pin connections for the configuration shown above:
| Breakout Board Pin | Self-Test | Z-Axis | Y-Axis | X-Axis | Ground | VDD |
| Arduino Analog Input Pin | 0 | 1 | 2 | 3 | 4 | 5 |
Or, if you're using just the accelerometer:
| ADXL3xx Pin | Self-Test | ZOut | YOut | XOut | Ground | VDD |
| Arduino Pin | None (unconnected) | Analog Input 1 | Analog Input 2 | Analog Input 3 | GND | 5V |
Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground. Values should be the same for the other axes, but will vary based on the sensitivity of the device. With the axis horizontal (i.e. parallel to ground or 0°), the accelerometer reading should be around 512, but values at other angles will be different for a different accelerometer (e.g. the ADXL302 5g one).
| Angle | -90 | -80 | -70 | -60 | -50 | -40 | -30 | -20 | -10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |
| Acceleration | 662 | 660 | 654 | 642 | 628 | 610 | 589 | 563 | 537 | 510 | 485 | 455 | 433 | 408 | 390 | 374 | 363 | 357 | 355 |