Accelerometer

An accelerometer is a device which can detect the acceleration due to any external force such as gravity. The ADXL345 is a 3 axis accelerometer with a thirteen-bit measurement. The data which is output from the module is a digital data and is accessible through SPI or I2C digital interface.

See live demo of the project- Click here to see

The ADXL345 measures all types of static acceleration due to any force including Earth's gravitational force. This module can be used in different applications such as motion orientation sensing, etc. Tilt-sensing is the most important application of this module.

Components Required :

  • Arduino Uno Board
  • Accelerometer ADXL 345
  • Bread Board
  • Jumper Wires
  • LCD Display
Due to its high resolution(4mg/LSB), it is capable of measuring the inclination which may be less than 1.0 degrees.

Applications of accelerometer:

  • Robotics : In many of the Robotics applications, there can situation, where the standing or sliding orientation of the Robot must be determined to predict whether the Robot can proceed or not. In such cases, using accelerometer can be the best option.
  • Vibration Sensing : There are different mechanisms where the vibrations of a particular material or area should be determined. For example, an area where ICs are manufactured, should not be shock-prone, in such cases, an accelerometer can help to sense the vibration. There are infinite requirements for vibration sensing.
  • Games : Nowadays there are different games which require motion sensing. There are games such as car racing, where the gamer gets the chance to slide the car just by sliding the steering or the joystick in the physical world and the same happens on the screen.
  • Smart Vehicle : In real life, vehicles also, the accelerometer can be integrated to change some mechanism of the car using automatic road sensing. For, example, in cars which uses auto-gear, the car can shift its gear to down, when its senses an up in the road, as it requires more force when the car goes up, against gravity.
  • Virtual music Instruments : There are virtual musical instruments which can sense the orientation of hands and can automatically produce sounds as par the movement.
  • In Airplanes : The most important use of this device is in the Airplanes or Aircraft. When the aircraft flies in the air, then the only way to sense its orientation is to measure gravitational balance maintained by its different wings. In this case, an accelerometer present inside all the wings of the airplanes sends the flight stability data to the flight monitor.
  • Industry : In heavy industries such as the manufacturing of different metal related equipment such as nuts, bolts, metal pins, thread, etc. In these cases, if there is a little vibration inside drilling or cutting arm, the entire work may be destroyed or the product may turn unusable. In such cases, vibration sensing through the accelerometer plays an important role, as little or internal vibrations cannot be checked by human beings directly.
  • Earthquake detection : This device can detect an Earthquake.
  • Some other application includes Construction Works, wind force calculation, load balancing, etc.

Details of the Accelerometer: ADXL345

ADXL 345 Description:
  • Material: Gold plated PCB Board.
  • Digital Interface: I2C/ SPI.
  • Ultra-Low Power: 40 micro-ampere in measurement mode.
  • 0.1 micro-ampere in standby mode.
  • Tap/Double Tap detection
  • Free Fall Detection
Features of the ADXL 345
  • The module has 3-axis.
  • Communication means: IIC/ SPI communication protocol.
  • Measuring Range: +(-) 2g to 16g.
PIN Details of the ADXL345

arduino-accelerometer

  • GND : Ground (-).
  • Vcc : 5V
  • CS : Chip Select (Active high, that is, will make the chip active if CS is made HIGH).
  • INT1: Interrupt 1 Output
  • INT2 : Interrupt 2 Output.
  • SDO : Serial data Output.
  • SDA : Serial Data Input and Output.
  • SCL : Serial Communication Clock.

Pin Connections

Connecting the LCD Pins


arduino-16by2-lcd

  • Connect the Anode Pin of the LCD into the GND of the Arduino.
  • Connect the Cathode Pin of the LCD into the 5V Pin of the Arduino.
  • Connect the PIN D7 of the LCD into the PIN 13 of the Arduino.
  • Connect the PIN D6 of the LCD into the PIN 12 of the Arduino.
  • Connect the PIN D5 of the LCD into the PIN 11 of the Arduino.
  • Connect the PIN D4 of the LCD into the PIN 10 of the Arduino.
  • Connect Vss PIN of the LCD into the GND of the Arduino.
  • Connect the VDD pin of the LCD into the 5v pin of the Arduino.
  • Connect the Contrast pin of the LCD into the GND pin of the Arduino via a 10K ohm Resistor or a 10K potentiometer.
  • Connect the RS pin of the LCD to the PIN 4 of the Arduino.
  • Connect the RW pin of the LCD to the GND of the Arduino.
  • Connect the Enable pin of the Arduino to the PIN 6 of the Arduino.

Connecting the Accelerometer:

arduino-accelerometer

  • Connect the GND of the Sensor to the GND of the Arduino.
  • Connect the Vcc of the Sensor to the 5v pin of the Arduino.
  • Connect the CS of the Sensor to the 5v pin of the Arduino.
  • Connect the SDA pin of the Sensor to the A4 pin of the Arduino.
  • Connect the SCL pin of the Sensor to the A5 pin of the Arduino.

Edit the following program into the Arduino Editor :

#include <Wire.h>        
#include <LiquidCrystal.h>   
#define Register_ID 0    
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Register_Z0 0x36
#define Register_Z1 0x37
                    
#define Reg_OFSX 0x1E    
#define Reg_OFSY 0x1F
#define Reg_OFSZ 0x20
#define Reg_PWR_CTL 0x2D

LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  
int ADXAddress = 0xA7>>1;  
int reading = 0;
int val = 0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
int Z1,Z0,Z_out;
double Xg,Yg,Zg;

void setup()
{
   lcd.begin(16, 2);      
   lcd.clear();           
   delay(100);
   Wire.begin();          
   setAccReg(0x31,0x0B);   
   setAccReg(0x2C,0x08);  
   setAccReg(0x2D,0x08);   
   setAccReg(0x2E,0x80);  
   setAccReg(0x1E,0x00);  
   setAccReg(0x1F,0x00);   
   setAccReg(0x20,0x05);   
   delay(100);
   Wire.beginTransmission(ADXAddress);
   Wire.write(Register_2D);
   Wire.write(8);
   Wire.endTransmission();
   delay(500);
}

void loop()
{
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_X0);
  Wire.write(Register_X1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    X0 = Wire.read();
    X1 = Wire.read();
    X1 = X1<<8;
    X_out = X0+X1;
  }
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_Y0);
  Wire.write(Register_Y1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    Y0 = Wire.read();
    Y1 = Wire.read();
    Y1 = Y1<<8;
    Y_out = Y0+Y1;
  }
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_Z0);
  Wire.write(Register_Z1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    Z0 = Wire.read();
    Z1 = Wire.read();
    Z1 = Z1<<8;
    Z_out = Z0+Z1;
  }
  Xg = X_out/256.00;   
  Yg = Y_out/256.00;
  Zg = Z_out/256.00;
  lcd.clear();         
  lcd.setCursor(0, 0); 
  lcd.print(" X="); 
  lcd.print(Xg);
  lcd.setCursor(0, 1);
  lcd.print("Y=");
  lcd.print(Yg);
  lcd.setCursor(8, 1); 
  lcd.print("Z=");
  lcd.print(Zg);
  delay(300);          
}
void setAccReg(int reg,byte value){
    setReg(ADXAddress,reg,value);    
}
void setReg(int device,int reg,byte value){
    Wire.beginTransmission(device);
    Wire.write(reg);
    Wire.write(value);
    Wire.endTransmission();
}

Program Analysis :

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions