# Adafruit Analog Accelerometer Breakouts

## Overview

The ADXL335 , ADXL326 and ADXL377 are low-power, 3-axis MEMS accelerometer modules with ratiometric analog voltage outputs. The Adafruit Breakout boards for these modules feature on-board 3.3v voltage regulation which makes them simple to interface with 5v microcontrollers such as the Arduino.

 **The ADXL335** can measure at least +/- 3G in the X, Y and Z axis. &nbsp;It is perfect for high-resolution&nbsp;static acceleration measurements such as tilt-sensing,&nbsp;as well as for moderate dynamic accelerations from motion, shock or vibration.![sensors_ADXL335_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/469/medium640/sensors_ADXL335_LRG.jpg?1396783433)

 **The ADXL326** can measure at least +/- 16G(!) in the X, Y and Z axis. It is ideal for measuring more dynamic accelerations from high-performance land and air vehicles as well as for shock and impact measurements.![sensors_ADXL326_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/470/medium640/sensors_ADXL326_LRG.jpg?1396783443)

 **The ADXL377** can measure at least +/- 200G(!) in the X, Y and Z axis. This is the sensor for measuring extreme dynamic accelerations encountered in applications such as rocketry experiments and high-impact shock measurements.![sensors_1413_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/010/618/medium640/sensors_1413_LRG.jpg?1377368066)

## How it Works:

## MEMS - Micro Electro-Mechanical Systems
The sensor consists of a micro-machined structure on a silicon wafer. The structure is suspended by polysilicon springs which allow it to deflect in the when subject to acceleration in the X, Y and/or Z axis. Deflection causes a change in capacitance between fixed plates and plates attached to the suspended structure. This change in capacitance on each axis is converted to an output voltage proportional to the acceleration on that axis.  
  

## Ratiometric Output
Ratiometric output means that the output voltage increases linearly with acceleration over the range.   

- For the ADXL335, that is approximately 0v at -3G to 3.3v at +3G.  
- For the ADXL326, that is approximately 0v at -16G to 3.3v at +16G. 
- For the ADXL377, that is approximately 0v at -200G to 3.3v at +200G. 
- For all modules, the output at 0G in each axis, is about 1/2 full-scale, or 1.65v.  

  
Info: 

# Adafruit Analog Accelerometer Breakouts

## Assembly

These boards come with all surface-mount components pre-soldered. The included header strip can be soldered on for convenient use on a breadboard or with 0.1" connectors. However, for applications subject to extreme accelerations, shock or vibration, locking connectors or direct soldering plus strain relief is advised.

## Prepare the header strip:
Cut the strip[ to length if necessary. &nbsp;It will be easier to solder if you insert it into a breadboard - long pins down.![sensors_DSC_0780-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/517/medium640/sensors_DSC_0780-1024.jpg?1396783989)

## Add the breakout board:
Place the breakout board over the pins.![sensors_DSC_0782-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/518/medium640/sensors_DSC_0782-1024.jpg?1396783996)

## And Solder!
Be sure to solder all pins for reliable electrical contact.  
![sensors_DSC_0783-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/519/medium640/sensors_DSC_0783-1024.jpg?1396784004)

# Adafruit Analog Accelerometer Breakouts

## Arduino Wiring

# Wiring:

## Connect the&nbsp;Power:

- Connect the GND pin to GND on the Arduino.  
- Connect the VIN pin to the 5v pin on the Arduino.  
- (For 3.3v microprocessors, connect the pin marked 3Vo to the 3.3v supply)

![](https://cdn-learn.adafruit.com/assets/assets/000/002/471/medium800/sensors_Accelerometer_Power_bb-1024.jpg?1396783450)

## Connect the X, Y and Z Signal Outputs:
Connect X, Y and Z to the analog pins as shown below:  
![](https://cdn-learn.adafruit.com/assets/assets/000/002/472/medium800/sensors_Accelerometer_bb-1024.jpg?1396783459)

## Using the Voltage Reference:
For the best possible accuracy and precision, you can&nbsp;use the output of the accelerometer boards voltage regulator as the analog reference for the Arduino. &nbsp;Connect the 3Vo pin on the&nbsp;accelerometer&nbsp;board to the AREF pin on the Arduino. Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/002/497/medium800/sensors_AccelerometerRef_bb-1024.jpg?1396783813)

# Adafruit Analog Accelerometer Breakouts

## Calibration and Programming

# Static Calibration:
As with all sensors, there is some variation in output between samples of these accelerometers. For non-critical applications such as game controllers, or simple motion or tilt sensors, these variations are not important. But for applications requiring precise measurements, calibration to a reliable reference is a good idea.  
![](https://cdn-learn.adafruit.com/assets/assets/000/002/498/medium800/sensors_Jiminy_Gravity.jpg?1396783816)

## Gravity as a&nbsp;Calibration Reference
Acceleration is measured in units of gravitational force or "G", where 1G represents the gravitational pull at the surface of the earth. &nbsp;[Despite what you may have heard](http://www.youtube.com/watch?v=2ORJ7B1bqEY), gravity is a pretty stable force and makes a convenient and reliable&nbsp;calibration reference if you happen to be a&nbsp;surface-dwelling earthling. Danger: 

## Calibration Method:
To calibrate the sensor to the gravitational reference, you need to determine the sensor output for each axis when it is precisely aligned with the axis of gravitational pull. &nbsp;Laboratory quality calibration uses precision positioning jigs. &nbsp;The method described here&nbsp;is simple and gives surprisingly&nbsp;good results.&nbsp; ![](https://cdn-learn.adafruit.com/assets/assets/000/002/514/medium800/sensors_Coordinates.png?1396783976)

 **Mount the Sensor:**  
First mount the sensor to a [small breadboard](http://www.adafruit.com/products/65)&nbsp;like the one on the left. &nbsp;The back and squared edges of the breadboard make a reasonably accurate set of reference planes to orient&nbsp;the sensor for calibration.  
  
**Wire the Sensor:**  
Wire the sensor&nbsp;as shown below. &nbsp;This is equivalent to the&nbsp;circuit shown on the previous page, with the addition of a switch.  
![sensors_tinybreadboard_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/515/medium640/sensors_tinybreadboard_LRG.jpg?1396783982)

![](https://cdn-learn.adafruit.com/assets/assets/000/002/513/medium800/sensors_Accelerometer_Calibration_bb-1024.jpg?1396783962)

## Run the&nbsp;Calibration Sketch

- Load the sketch below onto the Arduino and run it.  
- Open the Serial Monitor.  
- Lay the breadboard with the sensor on a flat surface

  - Press and hold the button until you see "Calibrate" in the serial monitor.
  - This will calibrate the minimum value for the z axis.

- Stand the breadboard on the front edge and press the button again. to calibrate +y  
- Repeat this for the three other edges to calibrate +x, -y and -x.  
- Turn the breadboard upside down and press the button again to calibrate +z. &nbsp;(Hint, the underside of a table works well to steady it.)

## Calibration Sketch Output:
  
Once calibrated, the output will show the calibrated raw range for each axis, followed by the&nbsp;measured "G" forces. &nbsp;The raw ranges can be used as constants in sketches.  
  
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625  
511, 511, 625 :: -0.01G, 0.07G, 1.00G  
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625  
511, 511, 625 :: -0.01G, 0.07G, 1.00G  
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625  
511, 511, 625 :: -0.01G, 0.07G, 1.00G  
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625  
511, 511, 625 :: -0.01G, 0.07G, 1.00G  
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625  
# Calibration Sketch
```auto
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
const int buttonPin = 2;

// Raw Ranges:
// initialize to mid-range and allow calibration to
// find the minimum and maximum for each axis
int xRawMin = 512;
int xRawMax = 512;

int yRawMin = 512;
int yRawMax = 512;

int zRawMin = 512;
int zRawMax = 512;

// Take multiple samples to reduce noise
const int sampleSize = 10;

void setup() 
{
  analogReference(EXTERNAL);
  Serial.begin(9600);
}

void loop() 
{
  int xRaw = ReadAxis(xInput);
  int yRaw = ReadAxis(yInput);
  int zRaw = ReadAxis(zInput);
  
  if (digitalRead(buttonPin) == LOW)
  {
    AutoCalibrate(xRaw, yRaw, zRaw);
  }
  else
  {
    Serial.print("Raw Ranges: X: ");
    Serial.print(xRawMin);
    Serial.print("-");
    Serial.print(xRawMax);
    
    Serial.print(", Y: ");
    Serial.print(yRawMin);
    Serial.print("-");
    Serial.print(yRawMax);
    
    Serial.print(", Z: ");
    Serial.print(zRawMin);
    Serial.print("-");
    Serial.print(zRawMax);
    Serial.println();
    Serial.print(xRaw);
    Serial.print(", ");
    Serial.print(yRaw);
    Serial.print(", ");
    Serial.print(zRaw);
    
    // Convert raw values to 'milli-Gs"
    long xScaled = map(xRaw, xRawMin, xRawMax, -1000, 1000);
    long yScaled = map(yRaw, yRawMin, yRawMax, -1000, 1000);
    long zScaled = map(zRaw, zRawMin, zRawMax, -1000, 1000);
  
    // re-scale to fractional Gs
    float xAccel = xScaled / 1000.0;
    float yAccel = yScaled / 1000.0;
    float zAccel = zScaled / 1000.0;
  
    Serial.print(" :: ");
    Serial.print(xAccel);
    Serial.print("G, ");
    Serial.print(yAccel);
    Serial.print("G, ");
    Serial.print(zAccel);
    Serial.println("G");
  
  delay(500);
  }
}

//
// Read "sampleSize" samples and report the average
//
int ReadAxis(int axisPin)
{
  long reading = 0;
  analogRead(axisPin);
  delay(1);
  for (int i = 0; i < sampleSize; i++)
  {
    reading += analogRead(axisPin);
  }
  return reading/sampleSize;
}

//
// Find the extreme raw readings from each axis
//
void AutoCalibrate(int xRaw, int yRaw, int zRaw)
{
  Serial.println("Calibrate");
  if (xRaw < xRawMin)
  {
    xRawMin = xRaw;
  }
  if (xRaw > xRawMax)
  {
    xRawMax = xRaw;
  }
  
  if (yRaw < yRawMin)
  {
    yRawMin = yRaw;
  }
  if (yRaw > yRawMax)
  {
    yRawMax = yRaw;
  }

  if (zRaw < zRawMin)
  {
    zRawMin = zRaw;
  }
  if (zRaw > zRawMax)
  {
    zRawMax = zRaw;
  }
}
```

# Adafruit Analog Accelerometer Breakouts

## CircuitPython Code

It's easy to use the analog accelerometer breakouts&nbsp;with CircuitPython and its [built-in analog I/O&nbsp;module](../../../../circuitpython-basics-analog-inputs-and-outputs). &nbsp;You can read the X, Y, Z accelerometer axis values as simple analog inputs that are converted to acceleration values with simple Python code.

This page will show how to use the ADXL335 with a CircuitPython board like the Feather M0. &nbsp; **Remember your CircuitPython board must support and have three analog inputs** , so the ESP8266 and small boards like Gemma M0 won't work. &nbsp;Stick with a Feather or Metro M0.

Wire up the ADXL335 to your board as follows:

![](https://cdn-learn.adafruit.com/assets/assets/000/048/758/medium800/sensors_m0_adxl335_bb.png?1512176186)

- **Board 3V** &nbsp;to&nbsp; **sensor VIN**
- **Board GND** &nbsp;to&nbsp; **sensor GND**
- **Board A1** &nbsp;to&nbsp; **sensor&nbsp;Xout**
- **Board A2** &nbsp;to&nbsp; **sensor&nbsp;Yout**
- **Board A3&nbsp;** to&nbsp; **sensor Zout**

Remember you can use any available analog inputs for the X, Y, Z outputs. &nbsp;**Be sure that these analog inputs are tolerant of up to 3.3 volt input (the Feather and Metro M0 powered by 3.3-5V as shown will be tolerant)!**

Next&nbsp;[connect to the board's serial REPL&nbsp;](../../../../welcome-to-circuitpython/the-repl)so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

If you haven't read it yet it will be helpful to [read the analog I/O guide](../../../../circuitpython-basics-analog-inputs-and-outputs) as it explains the basics of reading analog inputs with the board's analog to digital converter. &nbsp;We will read the X, Y, Z axis values as analog inputs. &nbsp;First import the necessary **board** and&nbsp; **analogio** modules and create three inputs, one for each axis:

```auto
import board
import analogio
x_axis = analogio.AnalogIn(board.A1)
y_axis = analogio.AnalogIn(board.A2)
z_axis = analogio.AnalogIn(board.A3)
```

You can read the raw value of an axis with the **value** property:

```auto
print('Raw XYZ: ({0}, {1}, {2})'.format(x_axis.value, y_axis.value, z_axis.value))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/048/759/medium800/sensors_Screen_Shot_2017-12-01_at_5.04.30_PM.png?1512176690)

Raw values aren't that interesting though, you really want the acceleration. &nbsp;Luckily it's easy to convert raw values to acceleration with a simple formula. &nbsp;Remember these sensors output a radiometric analog voltage proportional to the acceleration between -3G and 3G. &nbsp;Let's define a function to do this conversion:&nbsp;

```auto
def accel_value(axis):
    # Convert axis value to float within 0...1 range.
    val = axis.value / 65535
    # Shift values to true center (0.5).
    val -= 0.5
    # Convert to gravities.
    return val * 3.0
```

Now try reading the axis values again using the function to convert to gravities:

```auto
x = accel_value(x_axis)
y = accel_value(y_axis)
z = accel_value(z_axis)
print('Acceleration (G): ({0}, {1}, {2})'.format(x, y, z))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/048/760/medium800/sensors_Screen_Shot_2017-12-01_at_5.14.20_PM.png?1512177307)

![](https://cdn-learn.adafruit.com/assets/assets/000/048/761/medium800/sensors_Screen_Shot_2017-12-01_at_5.14.44_PM.png?1512177370)

That's all there is to using the ADXL335 with CircuitPython! &nbsp;You can use the built-in analog input capabilities to convert the accelerometer's X, Y, Z axis acceleration into a gravity value for your own use!

Here's a complete example of printing the X, Y, Z axis acceleration every second. &nbsp;Save this as **main.py** on your board and examine the REPL output:

```auto
import analogio
import board
import time


# Create analog inputs for each ADXL335 axis.
x_axis = analogio.AnalogIn(board.A1)
y_axis = analogio.AnalogIn(board.A2)
z_axis = analogio.AnalogIn(board.A3)

# Define function to convert raw analog values to gravities.
def accel_value(axis):
    # Convert axis value to float within 0...1 range.
    val = axis.value / 65535
    # Shift values to true center (0.5).
    val -= 0.5
    # Convert to gravities.
    return val * 3.0

# Main loop prints acceleration every second.
while True:
    x = accel_value(x_axis)
    y = accel_value(y_axis)
    z = accel_value(z_axis)
    print('Acceleration (G): ({0}, {1}, {2})'.format(x, y, z))
    time.sleep(1.0)
```

# Adafruit Analog Accelerometer Breakouts

## Downloads

# Files

- [ADXL335 Documentation Page](http://www.analog.com/en/mems-sensors/mems-inertial-sensors/adxl335/products/product.html "Link: http://www.analog.com/en/mems-sensors/mems-inertial-sensors/adxl335/products/product.html")
- [ADXL326 Documentation Page](https://www.analog.com/en/mems-sensors/mems-inertial-sensors/adxl326/products/product.html "Link: http://http://www.analog.com/en/mems-sensors/mems-inertial-sensors/adxl326/products/product.html")
- [ADXL377 Data Sheet](http://www.analog.com/static/imported-files/data_sheets/ADXL377.pdf)
- [ADXL335, ADXL326 & ADXL377 Breakout Board Eagle Files](https://github.com/adafruit/Adafruit-Analog-Accelerometers-PCBs)
- [Fritzing objects in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library)

# ADXL326 Schematic & Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/036/181/medium800/sensors_schem.png?1475678197)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/182/medium800/sensors_fabprint.png?1475678207)

# ADXL377 Schematic & Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/036/083/medium800/sensors_schem.png?1475008631)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/084/medium800/sensors_fabprint.png?1475008643)


## Related Guides

- [Make It Shake, Rattle, and Roll: Accelerometer Use](https://learn.adafruit.com/make-it-shake-rattle-and-roll.md)
- [IR Sensor](https://learn.adafruit.com/ir-sensor.md)
- [MIDI for Makers](https://learn.adafruit.com/midi-for-makers.md)
- [How to Build a Testing Jig](https://learn.adafruit.com/how-to-build-a-testing-fixture.md)
- [Adafruit DACx578 - 8 x Channel I2C DAC](https://learn.adafruit.com/adafruit-dac7578-8-x-channel-12-bit-i2c-dac.md)
- [Flora-Powered TARDIS Costume (for Dogs!)](https://learn.adafruit.com/wearable-flora-powered-tardis-costume-dogs.md)
- [ulab: Crunch Numbers fast in CircuitPython](https://learn.adafruit.com/ulab-crunch-numbers-fast-with-circuitpython.md)
- [Adafruit AS7331 UV / UVA / UVB / UVC Sensor](https://learn.adafruit.com/adafruit-as7331-uv-uva-uvb-uvc-sensor.md)
- [Adafruit STSPIN220 Stepper Motor Driver Breakout Board](https://learn.adafruit.com/adafruit-stspin220-stepper-motor-driver-breakout-board.md)
- [Integrating Home Assistant with Adafruit IO](https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant.md)
- [Arduino Ethernet + SD Card](https://learn.adafruit.com/arduino-ethernet-sd-card.md)
- [Adafruit PMSA003I Air Quality Breakout](https://learn.adafruit.com/pmsa003i.md)
- [Adafruit TLV493 Triple-Axis Magnetometer](https://learn.adafruit.com/adafruit-tlv493-triple-axis-magnetometer.md)
- [Adafruit QMC5883P - Triple Axis Magnetometer](https://learn.adafruit.com/adafruit-qmc5883p-triple-axis-magnetometer.md)
- [Adafruit QT Py ESP32 Pico](https://learn.adafruit.com/adafruit-qt-py-esp32-pico.md)
