Accelerometer

Introduction

The accelerometer is a compact motion sensor that provides triaxial acceleration measurement, enabling it to detect movement in three directions: X-axis, Y-axis and Z-axis. Its operation is based on capacitive sensors that react to gravitational and inertial forces.

For this course, we’ll be using the ADXL335. This uses micro-machined elements to measure acceleration, transforming these movements into electrical signals that can be interpreted by the Arduino.

The advantage of this accelerometer is its versatility. It can be used in a variety of projects, including motion detection, object stabilization, robotics and even virtual reality applications.

  • Accelerometer pins

Z, Y and X axis : Connect to one of the analog pins on the Arduino board.

GND: To be connected to the ground of your Arduino board

VCC: Connect to +3.3V on your Arduino board

Electronic diagram

Here’s the circuit diagram for connecting the accelerometer to the arduino board:

Programming

Here’s the program to run the adxl335 accelerometer. For this component, you don’t need a library to retrieve the values:

// Definition of ADXL335 pins connected to the Arduino
const int xPin = A0; // Analog pin for X axis
const int yPin = A1; // Analog pin for Y axis
const int zPin = A2; // Analog pin for Z axis

void setup() {
 // Starts serial communication at 9600 baud rate
 Serial.begin(9600);
}

void loop() {
 // Read analog values from corresponding pins
 int xValue = analogRead(xPin);
 int yValue = analogRead(yPin);
 int zValue = analogRead(zPin);

 // Display values on serial monitor
 Serial.print("Accelerometer values - X: ");
 Serial.print(xValue);
 Serial.print(" | Y: ");
 Serial.print(yValue);
 Serial.print(" | Z: ");
 Serial.println(zValue);

 // Wait 500 milliseconds before next reading
 delay(500);
}