Translate

Accelerometer Interfacing with Arduino (ADXL335)

 1. Introduction

This project demonstrates how to interface an ADXL3xx series (like the ADXL335) 3-axis accelerometer with an Arduino Uno. Accelerometers measure static acceleration (gravity) to detect tilt and dynamic acceleration to detect motion, shock, or vibration. This specific setup uses a clever "no-wires" approach by repurposing analog pins to power the sensor directly.

2. Components

  • Arduino Uno (or any compatible board)

  • ADXL3xx Accelerometer Breakout Board (e.g., ADXL335)

  • Breadboard

  • Jumper Wires (though the code supports direct mounting)

3. Circuit and Connections


Diagram of Arduino-ADXL 3xx Accelerometer
Circuit Diagram of Arduino-ADXL 3xx
Pin Diagram ADXL 335




The wiring follows a specific sequence to allow the sensor to be powered directly from the Analog Header:

Accelerometer PinArduino PinFunction
ST (Self Test)A0Testing the sensor integrity
Z-AxisA1Analog input for vertical movement
Y-AxisA2Analog input for forward/backward movement
X-AxisA3Analog input for left/right movement
GNDA4Ground (set to LOW in code)
VCCA5Power (set to HIGH in code)

4. Circuit Working

The circuit operates by converting physical acceleration into variable voltage. The ADXL3xx outputs an analog voltage for each axis proportional to the G-force it senses.

  • Power Trick: Instead of using the dedicated 5V/GND pins, we use A4 and A5. By setting A4 to LOW and A5 to HIGH via software, they act as a power supply for the low-current sensor.

  • Signal Processing: The Arduino's ADC (Analog-to-Digital Converter) reads these voltages on pins A1, A2, and A3 and converts them into a digital range of 0 to 1023.

5. Code

const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A3;                  // x-axis
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis

void setup() {
  Serial.begin(9600);
  
  // Repurposing analog pins as Power and Ground
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
}

void loop() {
  Serial.print(analogRead(xpin));
  Serial.print("\t");
  Serial.print(analogRead(ypin));
  Serial.print("\t");
  Serial.print(analogRead(zpin));
  Serial.println();
  delay(100);
}

6. Code Working

  1. Pin Definition: The code defines groundpin as 18 and powerpin as 19. On an Arduino Uno, digital pins 14–19 correspond to Analog pins A0–A5.

  2. Initialization: In setup(), the serial monitor is started. The power pins are set to OUTPUT to provide the necessary electricity to the sensor.

  3. Data Acquisition: In loop(), analogRead() captures the raw voltage levels from the X, Y, and Z pins.

  4. Output: These values are printed to the Serial Plotter or Serial Monitor, separated by tabs for easy reading.


7. Tips

  • Voltage Warning: Most ADXL335 sensors are 3.3V devices. While this code works by using an Arduino pin as a high signal, ensure your specific breakout board has a voltage regulator if you connect it to a standard 5V rail.

  • Calibration: Raw values (e.g., 400-600) don't mean much without calibration. You'll need to map these values to actual G-force or degrees of tilt for advanced projects.

8. Uses

  • Tilt Sensing: Used in auto-leveling cameras or controllers.

  • Gesture Control: Creating "air-mice" or wearable controllers.

  • Drop Detection: Protecting hard drives or sensitive equipment.

  • Gaming: Tilt-to-steer mechanics in DIY gaming peripherals.

9. Conclusion

Interfacing an ADXL3xx with an Arduino is a straightforward way to add motion sensitivity to your projects. By utilizing the analog pins for power, you reduce wiring complexity, making it an ideal setup for beginners or compact builds.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.