In this article you will learn, how to measure acceleration using ADXL320 acceleration measurement sensor and very famous Arduino Uno R3. What is ADXL320 acceleration sensor? How to use ADXL320 acceleration sensor? How to interface acceleration sensor with Arduino Uno R3 ? How to write its code? How to measure two directional movements of any object from starting point to end point? There are many acceleration measurement sensors are available in market. Name of some good quality acceleration sensors are given below:
- ADXL203CE (SFSEN-00844),
- ADXL320 (SF SEN 00847),
- MMA7260Q (SF SEN00252)
Uses of all these acceleration measurement sensors are almost same. But I will discuss only ADXL320 acceleration measurement sensor in this article. You can easily use other above mentioned articles also with few changes in circuit connections and coding. Before going further in this article you should know how to measure analog values using Arduinoand how to write code for Arduino in Arduino IDE?
ACCELERATION SENSOR?
Acceleration sensors are used to detect movement of objects from starting point to end point. ADXL320 acceleration sensor can work in 2 directions only. Its mean It can detect bi directional movements only in X and Y axis. Acceleration sensors are also used to detect orientation of objects according to X and Y axis.
Acceleration sensors are analog sensors. In other words, to interface them with microcontrollers or Arduino, you need to use Analog to digital converter channel of Arduino. In ADXL320 sensor two analog outputs of sensor should be connected with two ADC channels of Arduino. Connection diagram of Arduino Uno R3 with ADXL320 sensor is shown below.
ADXL320 sensor pin outs:
ADXL320 acceleration measurement sensor has 6 pins. Four pins are used to connect with Arduino. Description of each pin is given below:
- X anlog pin is analog output along x-axis.
- Y analog pin is analog output along y-axis.
- VDD 5 volt power supply input pin.
- GND ground pin.
Circuit diagram:
Circuit diagram of acceleration measurement module is given below:
Code:
Code for acceleration measurement sensor is given below. The code given below is written in Arduino IDE . Just copy and paste this code to your Arduino IDE. Make hardware connection as given in above circuit diagram. After connections, burn this code in your Arduino Board and check X and Y direction values in serial monitor of your computer.
int XINPUT = 4; // Analog channel four connected with pin x of acceleration sensor
int YINPUT = 5; // Analog channel four connected with pin y of acceleration sensor
void setup()
{
Serial.begin(9600); // It is used to send values to serial monitor with transfer rate of 9600
}
void loop()
{
int x; // values from accelerometer stored here
int y;
x = analogRead(XINPUT);
y = analogRead(YINPUT);
Serial.print(“X value = “);
Serial.println(x);
Serial.print(“Y value = “);
Serial.println(y);
delay(200);
}
I have made necessary comments in code for your understanding. But if you still feel any issue in code, feel free to comment on this post with your concern.