Hide minor edits - Show changes to markup
Este tutorial muesta como leer los dispositivos acelerómetros analógicos de la serie ADXL3xx (ej. ADXL320, ADXL321, ADXL322, ADXL330) y enviar los datos de aceleración al ordenador.
Este tutorial muestra cómo leer los dispositivos acelerómetros analógicos de la serie ADXL3xx (ej. ADXL320, ADXL321, ADXL322, ADXL330) y enviar los datos de aceleración al ordenador.
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).
Aquí se muestran algunas medidas adquiridas por un acelerómetro a medida que se va modificando la posición del eje Y del un acelerómetro ADXL322 2g respecto del plano horizontal. Los valores para los otros ejes deberían mantenerse iguales a lo largo del experimento, pero podrían variar en función de la sensibilidad del dispositivo. Con el eje horizontal (paralelo al suelo o, lo que es lo mismo, a 0º de inclinación) las lecturas del acelerómetro deberían ser de aproximadamente 512, pero el valor para los demás ángulos dependen del tipo de acelerómetro y su rango de medida (por ejemplo, para un dispositivo ADXL302 5g).
| 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 |
| Ángulo | -90 | -80 | -70 | -60 | -50 | -40 | -30 | -20 | -10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |
| Aceleración | 662 | 660 | 654 | 642 | 628 | 610 | 589 | 563 | 537 | 510 | 485 | 455 | 433 | 408 | 390 | 374 | 363 | 357 | 355 |
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.
Ejemplos > E/S analógicas
Este tutorial muesta como leer los dispositivos acelerómetros analógicos de la serie ADXL3xx (ej. ADXL320, ADXL321, ADXL322, ADXL330) y enviar los datos de aceleración al ordenador.
Este tutorial fue desarrollado usando la breakout boards de Sparkfun. El Adafruit módulo con el acelerómetro también sirve, aunque el orden de los pins es levemente distinto.
El dispositivo ADXL3xx devuelve datos de aceleración en cada eje en forma de un voltaje en forma analógico etre 0 y 5 voltios. Para leer este voltaje tan sól hace falta hacer uso de la función analogRead().
Schematic:
click the image to enlarge
Esquema:
pincha sobre la imagen para verla a mayor tamaño
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.
el dispositivo ADXL322 incluído en el módulo de Sparkfun debe insertarse en los pins de entrada analógica de la placa Arduino.
El acelerómetro hace uso de un amperaje muy bajo, por lo que puede funcionarThe 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:
Estos son los pins de conexión para la configuración mencionada anteriormente:
| 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:
| Pins del módulo | Autocomprobación | Eje Z | Eje Y | Eje X | Negativo | Alimentación |
| Pins de entrada analógica de Arduino | 0 | 1 | 2 | 3 | 4 | 5 |
o, si sólo estás usando el acelerómetro:
| ADXL3xx Pin | Self-Test | ZOut | YOut | XOut | Ground | VDD |
| Arduino Pin | None (unconnected) | Analog Input 1 | Analog Input 2 | Analog Input 3 | GND | 5V |
| Pins ADXL3xx | Autocomprobación | Salida Z | Salida Y | Salida X | Negativo | Alimentación |
| Pins Arduino | Ninguno (desconectado) | Entrada analógica 1 | Entrada analógica 2 | Entrada analógica 3 | Negativo | 5V |
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde border=0:)
/* ADXL3xx Reads an Analog Devices ADXL3xx accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from Sparkfun, available from: http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc created 2 Jul 2008 by David A. Mellis modified 26 Jun 2009 by Tom Igoe
*/
// these constants describe the pins. They won't change: const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage const int xpin = 3; // x-axis of the accelerometer const int ypin = 2; // y-axis const int zpin = 1; // z-axis (only on 3-axis models)
void setup() { // initialize the serial communications: 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() { // print the sensor values: Serial.print(analogRead(xpin)); // print a tab between values: Serial.print("\t"); Serial.print(analogRead(ypin)); // print a tab between values: Serial.print("\t"); Serial.print(analogRead(zpin)); Serial.println(); // delay before next reading: delay(100); }
const int groundPin = 18; // analog input pin 4 -- ground const int powerPin = 19; // analog input pin 5 -- voltage const int xPin = 3; // x-axis of the accelerometer const int yPin = 2; // y-axis const int zPin = 1; // z-axis (only on 3-axis models)
const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage const int xpin = 3; // x-axis of the accelerometer const int ypin = 2; // y-axis const int zpin = 1; // z-axis (only on 3-axis models)
[@
/*
ADXL3xx
(:div class=code :)
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc
/* ADXL3xx Reads an Analog Devices ADXL3xx accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from Sparkfun, available from: http://www.sparkfun.com/commerce/categories.php?c=80
created 2 Jul 2008 by David A. Mellis modified 26 Jun 2009 by Tom Igoe
// these constants describe the pins. They won't change: const int groundPin = 18; // analog input pin 4 -- ground const int powerPin = 19; // analog input pin 5 -- voltage const int xPin = 3; // x-axis of the accelerometer const int yPin = 2; // y-axis const int zPin = 1; // z-axis (only on 3-axis models)
void setup() {
// initialize the serial communications: 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() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
}
@]
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc created 2 Jul 2008 by David A. Mellis modified 26 Jun 2009 by Tom Igoe
*/
// these constants describe the pins. They won't change: const int groundPin = 18; // analog input pin 4 -- ground const int powerPin = 19; // analog input pin 5 -- voltage const int xPin = 3; // x-axis of the accelerometer const int yPin = 2; // y-axis const int zPin = 1; // z-axis (only on 3-axis models)
void setup() { // initialize the serial communications: 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() { // print the sensor values: Serial.print(analogRead(xpin)); // print a tab between values: Serial.print("\t"); Serial.print(analogRead(ypin)); // print a tab between values: Serial.print("\t"); Serial.print(analogRead(zpin)); Serial.println(); // delay before next reading: delay(100); }
(:divend:)
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)
/*
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc
created 2 Jul 2008 by David A. Mellis modified 26 Jun 2009 by Tom Igoe
// these constants describe the pins. They won't change: const int groundPin = 18; // analog input pin 4 -- ground const int powerPin = 19; // analog input pin 5 -- voltage const int xPin = 3; // x-axis of the accelerometer const int yPin = 2; // y-axis const int zPin = 1; // z-axis (only on 3-axis models)
// initialize the serial communications:
pinMode(groundPin, OUTPUT); pinMode(powerPin, OUTPUT); digitalWrite(groundPin, LOW); digitalWrite(powerPin, HIGH);
pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH);
// print the sensor values:
Serial.print(" ");
// print a tab between values:
Serial.print("\t");
Serial.print(" ");
// print a tab between values:
Serial.print("\t");
delay(1000);
// delay before next reading: delay(100);
@@
[@
@@
@]
[@
@@
@]
@@
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).
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).
delay(1000);
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).
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).
delay(1000);
delay(1000);
delay(1000);
delay(1000);
%color=#CC6600%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).
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).
%color=#CC6600% delay(1000);
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).
%color=#CC6600%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).
delay(1000);
%color=#CC6600% delay(1000);
%color=#CC6600%int groundpin = 18; // analog input pin 4
int groundpin = 18; // analog input pin 4
int groundpin = 18; // analog input pin 4
%color=#CC6600%int groundpin = 18; // analog input pin 4
Pinout for the above configuration:
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:
This tutorial shows you how to read 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.
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.
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.
This tutorial shows you how to read 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.
Examples > Devices
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 acceleration on each axis is output as an analog voltage between 0 and 5 volts, which is read by an analog input on the Arduino.
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.
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.
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 acceleration on each axis is output as an analog voltage between 0 and 5 volts, which is read by an analog input on the Arduino.
Here are some accelerometer readings from the y-axis of an ADXL322 2g accelerometer. Values should be the same for the other axes, but will vary based on the sensitivity of the device.
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).
@]
@]
Here are some accelerometer readings from the y-axis of an ADXL322 2g accelerometer. Values should be the same for the other axes, but will vary based on the sensitivity of the device.
| 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 |
Pinout for the above configuration:
Or, if you're using just the accelerometer:
An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.
| Accelerometer Pin | Arduino Pin |
| Self-Test | Analog Input 0 |
| Z-Axis | Analog Input 1 |
| Y-Axis | Analog Input 2 |
| X-Axis | Analog Input 3 |
| Ground | Analog Input 4 |
| VDD | Analog Input 5 |
| Breakout Board Pin | Self-Test | Z-Axis | Y-Axis | X-Axis | Ground | VDD |
| Arduino Analog Input Pin | 0 | 1 | 2 | 3 | 4 | 5 |
| ADXL3xx Pin | Self-Test | ZOut | YOut | XOut | Ground | VDD |
| Arduino Pin | None (unconnected) | Analog Input 1 | Analog Input 2 | Analog Input 3 | GND | 5V |
| Accelerometer Pin | Arduino Pin |
| Self-Test | Analog Input 0 |
| Z-Axis | Analog Input 1 |
| Y-Axis | Analog Input 2 |
| X-Axis | Analog Input 3 |
| Ground | Analog Input 4 |
| VDD | Analog Input 5 |
| Accelerometer Pin | Arduino Pin |
| Self-Test | Analog Input 0 |
| Z-Axis | Analog Input 1 |
| Y-Axis | Analog Input 2 |
| X-Axis | Analog Input 3 |
| Ground | Analog Input 4 |
| VDD | Analog Input 5 |
Examples > Devices
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.

| Accelerometer Pin | Arduino Pin |
| Self-Test | Analog Input 0 |
| Z-Axis | Analog Input 1 |
| Y-Axis | Analog Input 2 |
| X-Axis | Analog Input 3 |
| Ground | Analog Input 4 |
| VDD | Analog Input 5 |
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);
}