Build an Arduino Clone (Part 2) – 3 Axis Accelerometer

I just received a adxl335 triple axis accelerometer breakout board from I decided to test it on my custom Arduino board.

Make sure, while wiring the accelerometer, to respect the maximum voltage of the device. This specific accelerometer accept a maximum voltage of 3.3v. You can get 3.3v from the Atmega328 Avcc pin #20. You should also make sure the reference voltage for the analog inputs is the same as the output voltage of the accelerometer. Do this by connecting the Aref pin #21 to the Avcc pin #20.

I added a blinking LED to the code from to test the device.

int x, y, z;
int pin13 = LOW;

void setup()
  pinMode(13, OUTPUT);

void loop()
  x = analogRead(0);
  y = analogRead(1);
  z = analogRead(2);

  Serial.print("acceleretations are x, y, z: ");
  Serial.print(x, DEC);
  Serial.print(" ");
  Serial.print(y, DEC);
  Serial.print(" ");
  Serial.println(z, DEC);

  pin13 = !pin13;

You can read the output using the Arduino IDE Serial Monitor. Values for the three axis will be displayed 10 times per second on the output of the Serial Monitor.

Arduino Serial Monitor showing X, Y and Z values of the accelerometer
Arduino Serial Monitor showing X, Y and Z values of the accelerometer

Values for all three axis analog inputs are ranging from a little less than 400 to a little more than 600 with a neutral value around 500.

When mounted the same way as in the picture above, the X and Y axis can be compared to the pitch and roll of an airplane. The Z axis on the other hand ranges from 600 when pointing to the ceiling to 400 when flipped over, pointing to the floor.

I also received an electronic compass with this accelerometer … I’ll add that to our custom Arduino board and write a short note about it.