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

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

Triple axis accelerometer and custom Arduino board

Triple axis accelerometer and 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 Wiring.org.co to test the device.

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

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

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;
  digitalWrite(13,pin13);
  delay(100);
}

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.

 

Tags: , , , , ,

2 Replies

Trackback  •  Comments RSS

  1. MArk says:

    How did you get 3.3V to the accelerometer directly from the ATMEGA328 ?

    does pin 20 gives 3.3 voltage ? if yes then how ?

    is there a voltage regulator inside the chip that gives the 3.3 V ? or a resistor reducing the voltage from 5 volts to 3.3 volts ?

    please explain, thanks

Post a Reply

Your email address will not be published. Required fields are marked *

Top