Accelerometer Readings

Z2M Part: EMS-00003-B

Read X, Y, Z axis values from an analog accelerometer module.

Circuit Diagram
Circuit diagram for Accelerometer Readings
Wire Connections & Pin Configuration

Wire Color Connections:

Yellow → A0 to X output, A1 to Y output, A2 to Z output
Red → 5V to VCC
Black → GND to GND

Pin Configuration:

Arduino Analog Pin A0 → Accelerometer X output
Arduino Analog Pin A1 → Accelerometer Y output
Arduino Analog Pin A2 → Accelerometer Z output
Arduino 5V → Accelerometer VCC
Arduino GND → Accelerometer GND
Arduino Code
Edit
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;

int RawMin = 0;
int RawMax = 1023;
const int sampleSize = 10;

void setup() {
  analogReference(EXTERNAL);  // Use external reference (if connected)
  Serial.begin(9600);
}

void loop() {
  // Read inputs for X, Y, and Z axes
  int xRaw = ReadAxis(xInput);
  int yRaw = ReadAxis(yInput);
  int zRaw = ReadAxis(zInput);

  // Scale raw values to ±3g range
  long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
  long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
  long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);

  // Convert to G-force (approximate)
  float xAccel = xScaled / 1000.0;
  float yAccel = yScaled / 1000.0;
  float zAccel = zScaled / 1000.0;

  // Display values on Serial Monitor
  Serial.print(\"X, Y, Z :: \");
  Serial.print(xRaw);
  Serial.print(\", \");
  Serial.print(yRaw);
  Serial.print(\", \");
  Serial.print(zRaw);
  Serial.print(\" :: \");
  Serial.print(xAccel, 1);
  Serial.print(\"G, \");
  Serial.print(yAccel, 1);
  Serial.print(\"G, \");
  Serial.print(zAccel, 1);
  Serial.println(\"G\");

  delay(200);
}

// Function to read and average multiple samples for stable output
int ReadAxis(int axisPin) {
  long total = 0;
  for (int i = 0; i < sampleSize; i++) {
    total += analogRead(axisPin);
  }
  return total / sampleSize;
}

Instruction Details

Wiring: Connect accelerometer X output to Analog Pin A0, Y to A1, Z to A2. Connect VCC to 5V and GND to GND.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Open Serial Monitor (Tools → Serial Monitor) at 9600 baud. X, Y, Z raw values and G-force readings display. Tilt board to see values change.

How to Use

  1. Connect the required components as per the Pin Configuration above
  2. Open Arduino IDE and create a new sketch
  3. Copy and paste the code above
  4. Select your Arduino board and COM port from Tools menu
  5. Click the Upload button to upload the code to your Arduino
  6. Open Serial Monitor (if applicable) to see the output

Components Required

  • Arduino Uno
  • Analog Accelerometer Module (e.g., ADXL335)
  • Breadboard
  • Jumper Wires

Category: Sensors