Questo sito non è ne attivo ne aggiornato, specialmente la pagina del download รจ ferma a 5 vesioni fa , utilizzate il sito in inglese finchè questo sito non sarà annunciato ufficialmente
Learning Examples | Foundations | Hacking | Links
Examples > Analog I/O
Reads an Analog Devices ADXL3xx series (e.g. ADXL320, ADXL321, ADXL322, ADXL330) accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts, which is read by an analog input on the Arduino.

An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.
Pinout for the above configuration:
| 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 |
int groundpin = 18; // analog input pin 4
int powerpin = 19; // analog input pin 5
int xpin = 3; // x-axis of the accelerometer
int ypin = 2; // y-axis
int zpin = 1; // z-axis (only on 3-axis models)
void setup()
{
Serial.begin(9600);
// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundPin, OUTPUT);
pinMode(powerPin, OUTPUT);
digitalWrite(groundPin, LOW);
digitalWrite(powerPin, HIGH);
}
void loop()
{
Serial.print(analogRead(xpin));
Serial.print(" ");
Serial.print(analogRead(ypin));
Serial.print(" ");
Serial.print(analogRead(zpin));
Serial.println();
delay(1000);
}
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 |