Tutorial.ADXL3xx History

Hide minor edits - Show changes to markup

May 02, 2012, at 04:04 PM by Scott Fitzgerald -
Changed line 45 from:
to:
November 16, 2011, at 04:19 AM by Scott Fitzgerald -
Changed line 45 from:
to:
September 23, 2010, at 10:41 PM by Christian Cerrito -
Changed lines 3-4 from:

ADXL3xx Accelerometer

to:

ADXL3xx Accelerometer

September 19, 2010, at 10:07 PM by Christian Cerrito -
Changed lines 1-2 from:

Examples > Analog I/O

to:

Examples > Sensors

September 19, 2010, at 08:23 AM by Christian Cerrito -
Added lines 22-23:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

September 18, 2010, at 02:32 AM by Christian Cerrito -
Changed lines 61-64 from:
to:
September 18, 2010, at 02:31 AM by Christian Cerrito -
Changed lines 7-8 from:

This tutorial was built using the breakout boards from Sparkfun. The adafruit accelerometer breakout board also works, though it must be wired differently.

to:

This tutorial was built using the breakout boards from Sparkfun. The adafruit accelerometer breakout board also works, though it must be wired differently.

September 18, 2010, at 02:31 AM by Christian Cerrito -
Changed lines 7-8 from:

This tutorial was built using the breakout boards from Sparkfun. The Ping - detect objects with an ultrasonic range finder]] also works, though the order of the pins is slightly different.

to:

This tutorial was built using the breakout boards from Sparkfun. The adafruit accelerometer breakout board also works, though it must be wired differently.

September 18, 2010, at 02:28 AM by Christian Cerrito -
Changed lines 7-8 from:

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.

to:

This tutorial was built using the breakout boards from Sparkfun. The Ping - detect objects with an ultrasonic range finder]] also works, though the order of the pins is slightly different.

September 18, 2010, at 02:25 AM by Christian Cerrito -
Changed line 58 from:
to:
Changed line 67 from:
  • [[Tutorial/Memsic2125] - read a two axis accelerometer
to:
Changed line 69 from:
  • Ping - detect objects with an ultrasonic range finder
to:
  • Ping - detect objects with an ultrasonic range finder
September 18, 2010, at 02:24 AM by Christian Cerrito -
Changed line 58 from:
to:
Changed lines 60-64 from:
  • delay()

  • WhileLoop - Use a While Loop to calibrate a sensor while a button is being pressed.
  • SwitchCase - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
  • Array: a variation on the For Loop example that demonstrates how to use an array.
to:
  • analogRead()
  • serial.begin
  • serial.print

  • AnalogInput - Use a potentiometer to control the blinking of an LED.
  • AnalogInOutSerial - read an analog input, map its values, and then use that information to dim or brighten an LED.
  • [[Tutorial/Memsic2125] - read a two axis accelerometer
  • Knock - detect knocks/impacts with a piezo element
  • Ping - detect objects with an ultrasonic range finder
September 18, 2010, at 02:16 AM by Christian Cerrito -
Changed line 17 from:

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.

to:

The accelerometer uses very little amperage, so it can be plugged into your Arduino and run directly off of the output from 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.

September 18, 2010, at 02:14 AM by Christian Cerrito -
Changed lines 53-64 from:
Acceleration662660654642628610589563537510485455433408390374363357355
to:
Acceleration662660654642628610589563537510485455433408390374363357355

See Also:

  • for()
  • digitalWrite()
  • delay()

  • WhileLoop - Use a While Loop to calibrate a sensor while a button is being pressed.
  • SwitchCase - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
  • Array: a variation on the For Loop example that demonstrates how to use an array.
September 18, 2010, at 02:13 AM by Christian Cerrito -
Deleted lines 39-43:

An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.

September 18, 2010, at 02:12 AM by Christian Cerrito -
Added lines 19-27:

Schematic:

click the image to enlarge

Changed lines 41-49 from:

Schematic:

click the image to enlarge

to:
September 18, 2010, at 02:12 AM by Christian Cerrito -
Deleted lines 16-26:

Schematic:

click the image to enlarge

An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.

Added lines 31-43:

Schematic:

click the image to enlarge

An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.

September 18, 2010, at 02:10 AM by Christian Cerrito -
Changed lines 11-14 from:
to:

Hardware Required

  • Arduino Board
  • ADXL3xx Accelerometer
September 18, 2010, at 02:08 AM by Christian Cerrito -
Changed lines 20-22 from:

to:

September 18, 2010, at 02:07 AM by Christian Cerrito -
Changed lines 14-15 from:
to:
September 18, 2010, at 02:07 AM by Christian Cerrito -
Changed lines 14-15 from:
to:
September 18, 2010, at 02:05 AM by Christian Cerrito -
Changed lines 14-15 from:
to:
September 18, 2010, at 01:57 AM by Christian Cerrito -
September 18, 2010, at 01:56 AM by Christian Cerrito -
Changed lines 14-15 from:

Attach: ADXL3X_BB.png

to:
September 18, 2010, at 01:54 AM by Christian Cerrito -
Changed lines 14-15 from:
to:

Attach: ADXL3X_BB.png

Changed lines 20-22 from:

to:

September 18, 2010, at 01:53 AM by Christian Cerrito -
Changed lines 5-6 from:

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.

to:

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.

September 16, 2010, at 10:18 PM by Tom Igoe -
Changed line 42 from:
to:
September 16, 2010, at 10:18 PM by Tom Igoe -
Changed line 42 from:
to:
February 24, 2010, at 04:30 AM by Tom Igoe -
Added line 42:
Deleted lines 43-104:
 /*
  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);
 }
September 23, 2009, at 01:25 AM by David A. Mellis - Pin -> pin
Changed lines 69-73 from:
 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)
to:
 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)
July 05, 2009, at 07:45 PM by Tom Igoe -
Changed lines 40-44 from:

[@

/*

 ADXL3xx
to:
Changed lines 43-56 from:
 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
to:
 /*
  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
Changed lines 51-96 from:
 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);

}

@]

to:
June 30, 2009, at 09:31 PM by Tom Igoe -
Changed lines 42-47 from:

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)

to:

/*

 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)

Added line 77:
  // initialize the serial communications:
Changed lines 84-87 from:
  pinMode(groundPin, OUTPUT);
  pinMode(powerPin, OUTPUT);
  digitalWrite(groundPin, LOW); 
  digitalWrite(powerPin, HIGH);
to:
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);
Added line 92:
  // print the sensor values:
Changed lines 94-95 from:
  Serial.print(" ");
to:
  // print a tab between values:
  Serial.print("\t");
Changed lines 97-98 from:
  Serial.print(" ");
to:
  // print a tab between values:
  Serial.print("\t");
Changed lines 101-102 from:
  delay(1000);
to:
  // delay before next reading:
  delay(100);
Added line 104:
Changed line 111 from:
to:
June 30, 2009, at 09:27 PM by Tom Igoe -
June 30, 2009, at 09:24 PM by Tom Igoe -
Added lines 16-22:

Schematic:

click the image to enlarge

June 30, 2009, at 08:04 PM by Tom Igoe -
June 30, 2009, at 07:50 PM by Tom Igoe -
Changed line 34 from:

@@

to:

[@

Changed lines 65-66 from:

@@

to:

@]

June 30, 2009, at 07:49 PM by Tom Igoe -
Changed line 34 from:

[@

to:

@@

Changed lines 65-66 from:

@]

to:

@@

June 30, 2009, at 07:49 PM by Tom Igoe -
Changed lines 69-70 from:

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).

to:

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).

June 30, 2009, at 07:48 PM by Tom Igoe -
Changed line 63 from:

delay(1000);

to:
  delay(1000);
Changed lines 69-70 from:

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).

to:

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).

June 30, 2009, at 07:48 PM by Tom Igoe -
Changed line 63 from:
  delay(1000);
to:

delay(1000);

June 30, 2009, at 07:48 PM by Tom Igoe -
Changed line 63 from:
  delay(1000);
to:
  delay(1000);
Changed lines 69-70 from:

%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).

to:

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).

June 30, 2009, at 07:47 PM by Tom Igoe -
Changed line 63 from:

%color=#CC6600% delay(1000);

to:
  delay(1000);
Changed lines 69-70 from:

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).

to:

%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).

June 30, 2009, at 07:47 PM by Tom Igoe -
Changed line 63 from:
  delay(1000);
to:

%color=#CC6600% delay(1000);

June 30, 2009, at 07:45 PM by Tom Igoe -
Changed line 35 from:

%color=#CC6600%int groundpin = 18; // analog input pin 4

to:

int groundpin = 18; // analog input pin 4

June 30, 2009, at 07:45 PM by Tom Igoe -
Changed line 35 from:

int groundpin = 18; // analog input pin 4

to:

%color=#CC6600%int groundpin = 18; // analog input pin 4

June 30, 2009, at 07:36 PM by Tom Igoe -
Changed lines 18-20 from:

Pinout for the above configuration:

to:

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:

Changed line 28 from:
to:
June 30, 2009, at 07:33 PM by Tom Igoe -
Changed lines 5-6 from:

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.

to:

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.

June 30, 2009, at 07:29 PM by Tom Igoe -
Changed lines 5-6 from:

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.

to:

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.

July 02, 2008, at 09:07 PM by David A. Mellis -
Changed lines 1-2 from:

Examples > Devices

to:

Examples > Analog I/O

July 02, 2008, at 08:58 PM by David A. Mellis -
Changed lines 5-6 from:

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.

to:

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.

July 02, 2008, at 08:57 PM by David A. Mellis -
Changed lines 5-6 from:

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.

to:

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.

July 02, 2008, at 08:52 PM by David A. Mellis -
Changed lines 62-63 from:

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.

to:

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).

July 02, 2008, at 08:49 PM by David A. Mellis -
Changed line 64 from:
to:
July 02, 2008, at 08:49 PM by David A. Mellis -
Changed lines 58-66 from:

@]

to:

@]

Data

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-100102030405060708090
Acceleration662660654642628610589563537510485455433408390374363357355
July 02, 2008, at 08:43 PM by David A. Mellis -
Changed line 21 from:
to:
July 02, 2008, at 08:43 PM by David A. Mellis -
Changed line 15 from:
to:
July 02, 2008, at 08:42 PM by David A. Mellis -
Added lines 13-14:

Pinout for the above configuration:

Added lines 19-20:

Or, if you're using just the accelerometer:

July 02, 2008, at 08:41 PM by David A. Mellis -
Changed line 13 from:
to:
Changed line 17 from:
to:
July 02, 2008, at 08:40 PM by David A. Mellis -
Changed line 13 from:
to:
Changed line 17 from:
to:
July 02, 2008, at 08:40 PM by David A. Mellis -
Changed line 17 from:
to:
July 02, 2008, at 08:40 PM by David A. Mellis -
Changed line 13 from:
to:
July 02, 2008, at 08:40 PM by David A. Mellis -
Added lines 11-12:

An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino.

Changed lines 14-21 from:
Accelerometer PinArduino Pin
Self-TestAnalog Input 0
Z-AxisAnalog Input 1
Y-AxisAnalog Input 2
X-AxisAnalog Input 3
GroundAnalog Input 4
VDDAnalog Input 5
to:
Breakout Board PinSelf-TestZ-AxisY-AxisX-AxisGroundVDD
Arduino Analog Input Pin012345

ADXL3xx PinSelf-TestZOutYOutXOutGroundVDD
Arduino PinNone (unconnected)Analog Input 1Analog Input 2Analog Input 3GND5V
July 02, 2008, at 08:33 PM by David A. Mellis -
Added line 11:
July 02, 2008, at 08:33 PM by David A. Mellis -
Changed lines 11-18 from:
Accelerometer PinArduino Pin
Self-TestAnalog Input 0
Z-AxisAnalog Input 1
Y-AxisAnalog Input 2
X-AxisAnalog Input 3
GroundAnalog Input 4
VDDAnalog Input 5
to:
Accelerometer PinArduino Pin
Self-TestAnalog Input 0
Z-AxisAnalog Input 1
Y-AxisAnalog Input 2
X-AxisAnalog Input 3
GroundAnalog Input 4
VDDAnalog Input 5
July 02, 2008, at 08:32 PM by David A. Mellis -
Added lines 1-52:

Examples > Devices

ADXL3xx Accelerometer

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.

Circuit

Accelerometer PinArduino Pin
Self-TestAnalog Input 0
Z-AxisAnalog Input 1
Y-AxisAnalog Input 2
X-AxisAnalog Input 3
GroundAnalog Input 4
VDDAnalog Input 5

Code

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);
}

Share