This tutorial shows you how to read an Analog Devices ADXL3xx series (e.g.ADXL320, ADXL321, ADXL322, ADXL330) accelerometer and communicate the acceleration to the a personal computer through the serial monitor of the Arduino Software (IDE) or another application that receives data over the serial port.
This tutorial was built using the breakout boards from Sparkfun. The adafruit accelerometer breakout board also works, though it must be wired differently.
The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. To read this, all you need is the analogRead() function.
Step 1: What You Need?
Don't have components? Don't worry. Just click the component's name.Step 2: Build Your Circuit.
The accelerometer uses very little current, so it can be plugged into your board and run directly off of the output from the digital output pins. To do this, you'll use three of the analog input pins as digital I/O pins, for power and ground to the accelerometer, and for the self-test pin. You'll use the other three analog inputs to read the accelerometer's analog outputs.Breakout Board Pin | Self-Test | Z-Axis | Y-Axis | X-Axis | Ground | VDD |
Arduino Analog Input Pin | 0 | 1 | 2 | 3 | 4 | 5 |
ADXL3xxPin | Self-Test | ZOut | YOut | XOut | Ground | VDD |
Arduino Pin | None(unconnected) | Analog Input 1 | Analog Input 2 | Analog Input 3 | GND | 5V |
Step 3: Upload The Code.
1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.
2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.
Select the right port: Tools >> Port >> Select the port number.
3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 06.Sensors >> ADXL3xx
Click press the "upload" button (see the button with right arrow mark).
const int groundpin = 18;
const int powerpin = 19;
Setting pin 19 (A5) as HIGH and pin 18 (A4) as LOW provides the 5V with few milliamps needed by the accelerometer to work.
This solution allows the breakout boards from Sparkfun to be connected directly to your Arduino board. Different boards may be connected to standard 5V - or 3.3V -and GND pins. In this latter case, the code may be amended commenting the lines above in the void setup() section.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
This solution allows the breakout boards from Sparkfun to be connected directly to your Arduino board. Different boards may be connected to standard 5V - or 3.3V -and GND pins. In this latter case, the code may be amended commenting the lines above in the void setup() section.
Data
Here are some accelerometer readings collected by positioning the y-axis of anADXL322 2g accelerometer at various angles from ground. Values should be the same for the other axes, but will vary based on the sensitivity of the device. With the axis horizontal (i.e. parallel to ground or 0°), the accelerometer reading should be around 512, but values at other angles will be different for a different accelerometer (e.g. the ADXL302 5g one).Angle | -90 | -80 | -70 | -60 | -50 | -40 | -30 | -20 | -10 | 0 |
Acceleration | 662 | 660 | 654 | 642 | 628 | 610 | 589 | 563 | 537 | 510 |
Angle | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |
Acceleration | 510 | 485 | 455 | 433 | 408 | 390 | 374 | 363 | 357 | 355 |
Download:
Arduino IDESources:https://www.arduino.cc/en/Tutorial/ADXL3xx
0 comments:
Post a Comment