Understanding Accelerometers: Interface ADXL335 With Arduino

by AKP in Circuits > Arduino

121 Views, 0 Favorites, 0 Comments

Understanding Accelerometers: Interface ADXL335 With Arduino

adxl335-accelerometer-arduino-tutorial.png

Have you ever pondered how your smartphone determines its orientation? It’s among the most remarkable functionalities of modern smartphones. Each one contains a miniature component known as an accelerometer within its circuitry. This component detects shifts in the device’s orientation, enabling your smartphone to seamlessly switch between portrait and landscape modes.

Accelerometers find extensive application in various fields requiring motion and tilt sensing capabilities, including mobile devices, gaming consoles, disk drive protection mechanisms, image stabilization systems, as well as sports and health monitoring devices.

Supplies

  • Arduino Uno REV3 Amazon
  • Adafruit ADXL335-5V Ready Triple-axis Accelerometer Amazon

How Does an Accelerometer Function?

Accelerometer-Working-Illustration-Weightless-State.jpg
Accelerometer-Working-Illustration-Sudden-Movement.jpg
Accelerometer-Working-Illustration-Gravitation-Force.jpg

To grasp the operation of accelerometers, envision a sphere enclosed within a three-dimensional cube.

In a scenario where the cube exists in outer space, devoid of gravitational effects, the sphere will remain suspended at the cube’s center.

Now, envisage each face of the cube representing a distinct axis.

If we suddenly shift the cube to the left with an acceleration of 1g (where 1g equals 9.8 m/s², representing the gravitational force), the sphere will inevitably collide with face X. By measuring the force exerted by the sphere on face X, we can derive an output value of 1g along the X axis.

Consider what occurs when we position the cube on Earth. The sphere will promptly descend onto face Z, exerting a force of 1g, as illustrated in the diagram:

In this instance, although the cube remains stationary, we still register a 1g measurement along the Z axis. This arises because gravity, functioning as a form of acceleration, pulls the sphere downward with a force of 1g.

While this model doesn’t precisely replicate the construction of a real-world accelerometer sensor, it aids in comprehending why accelerometer output signals are typically expressed in ±g, or why an accelerometer records 1g along the z-axis when stationary, or what accelerometer readings to anticipate at varying orientations.

In practical terms, accelerometers rely on Micro-Electro-Mechanical Systems (MEMS fabrication technology). Hence, let’s explore the functioning of a MEMS accelerometer.

How Does a MEMS Accelerometer Work?

MEMS-Accelerometer-Working.gif

A MEMS (Micro-Electro-Mechanical System) accelerometer comprises a micro-machined framework constructed atop a silicon wafer.

This framework is supported by polysilicon springs, enabling deflection when subjected to acceleration along the X, Y, and/or Z axes.

As deflection occurs, the capacitance between fixed plates and plates linked to the suspended framework alters. This variation in capacitance correlates with the acceleration along the respective axis.

The sensor interprets this capacitance shift, transforming it into an analog output voltage.

ADXL335 Module Hardware Overview

ADXL335-Accelerometer-Module-Hardware-Overview.jpg

At the heart of this module lies a compact, energy-efficient, and low-noise triple-axis MEMS accelerometer manufactured by Analog Devices – the ADXL335. This device is capable of not only detecting static acceleration induced by gravity but also dynamic acceleration resulting from movement, impact, or vibration.

This module, designed to fit onto a breadboard seamlessly, exposes each pin of the ADXL335 through a 6-pin, 0.1′′ pitch header. These pins include three analog outputs for measuring acceleration along the X, Y, and Z axes, two power supply pins, and a self-test pin.

Power

The ADXL335 operates within a voltage range of 1.8V to 3.6VDC (typically 3.3V). However, the inclusion of an onboard 3.3V regulator renders it suitable for interfacing with 5V microcontrollers like the Arduino.

Under normal operating conditions, the sensor consumes a mere 350μA of current.

Measurement Range

With a full sensing range of ±3g, the ADXL335 can accurately measure and represent accelerations within this range. If subjected to accelerations exceeding ±3g, the accelerometer will not malfunction, but its output may saturate.

The absolute maximum acceleration the ADXL335 can withstand is 10,000g. Accelerations beyond this threshold may cause the device to malfunction.

Ratiometric Output

The output of the ADXL335 is ratiometric, meaning the output voltage increases linearly with acceleration across its range. Consequently, the output voltage corresponds to specific acceleration levels: 0g yields half of the 3.3V supply voltage (1.65V), -3g corresponds to 0V, and +3g corresponds to 3.3V, with linear scaling in between.

Wiring an ADXL335 Accelerometer to an Arduino

Wiring-ADXL335-Accelerometer-Module-to-Arduino-UNO.png

Now that we understand how the ADXL335 accelerometer operates, let’s proceed to connect it to our Arduino.

The connections are straightforward. Begin by placing the accelerometer on the breadboard. Connect the VCC pin to the Arduino’s 5V pin and the GND pin to the Arduino’s ground pin. Then, connect the X, Y, and Z outputs to the Arduino’s analog pins A0, A1, and A2 respectively.

For precise results, we need to adjust the analog reference (AREF) voltage on the Arduino. This can be achieved by linking the Arduino’s 3.3V pin to the AREF pin.

The following diagram illustrates the wiring configuration.

Arduino Example Code – Reading the ADXL335 Accelerometer

The code is straightforward. It merely showcases the calibrated sensor output for each axis on the serial interface. Before delving into the specifics, give the sketch a try.

const int xInput = A0;
const int yInput = A1;
const int zInput = A2;

// initialize minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;

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

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

void loop()
{
//Read raw values
int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);

// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);

// re-scale to fractional Gs
float xAccel = xScaled / 1000.0;
float yAccel = yScaled / 1000.0;
float zAccel = zScaled / 1000.0;

Serial.print("X, Y, Z :: ");
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
Serial.print(" :: ");
Serial.print(xAccel,0);
Serial.print("G, ");
Serial.print(yAccel,0);
Serial.print("G, ");
Serial.print(zAccel,0);
Serial.println("G");

delay(200);
}

// Take samples and return 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;
}


See Full Article Here