loading

The MMA8452Q is a smart, low-power, three-axis, capacitive, micromachined accelerometer with 12 bits of resolution. Flexible user programmable options are provided with the aid of embedded functions in the accelerometer, configurable to two interrupt pins. It has user selectable full scales of ±2g/±4g/±8g with high-pass filter filtered data as well as non-filtered data available real-time. Here is its demonstration with Arduino nano.

Step 1: What You Need..!!

1. Arduino Nano

2. MMA8452Q

LINK : https://www.controleverything.com/content/Accelorometer?sku=MMA8452Q_I2CS

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Arduino Nano

https://www.controleverything.com/content/I2C-Master?sku=ANI2C

Step 2: Connection:

Take an I2C shield for Arduino Nano and gently push it over the pins of Nano.

Then connect the one end of I2C cable to MMA8452Q sensor and the other end to the I2C shield.

Connections are shown in the picture above.

Step 3: Code:

The arduino code for MMMA8452Q can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/MMA8...

The datasheet of MMA8452Q can be found here:

https://s3.amazonaws.com/controleverything.media/c...

We include library Wire.h to facilitate the I2c communication of the sensor with the Arduino board.

You can also copy the code from here, it is given as follows:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// MMA8452Q

// This code is designed to work with the MMA8452Q_I2CS I2C Mini Module available from ControlEverything.com.

// https://www.controleverything.com/content/Accelor...

#include<Wire.h>

// MMA8452Q I2C address is 0x1C(28)

#define Addr 0x1C

void setup()

{

// Initialise I2C communication as MASTER

Wire.begin();

// Initialise Serial Communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x2A);

// StandBy mode

Wire.write(0x00);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x2A);

// Active mode

Wire.write(0x01);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select control register

Wire.write(0x0E);

// Set range to +/- 2g

Wire.write(0x00);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[7];

// Request 7 bytes of data

Wire.requestFrom(Addr, 7);

// Read 7 bytes of data

// staus, xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

if(Wire.available() == 7)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

data[4] = Wire.read();

data[5] = Wire.read();

data[6] = Wire.read();

}

// Convert the data to 12-bits

int xAccl = ((data[1] * 256) + data[2]) / 16;

if (xAccl > 2047)

{

xAccl -= 4096;

}

int yAccl = ((data[3] * 256) + data[4]) / 16;

if (yAccl > 2047)

{

yAccl -= 4096;

}

int zAccl = ((data[5] * 256) + data[6]) / 16;

if (zAccl > 2047)

{

zAccl -= 4096;

}

// Output data to serial monitor

Serial.print("Acceleration in X-Axis : ");

Serial.println(xAccl);

Serial.print("Acceleration in Y-Axis : ");

Serial.println(yAccl);

Serial.print("Acceleration in Z-Axis : ");

Serial.println(zAccl);

delay(500);

}

Step 4: Applications:

MMA8452Q has various applications which include E-Compass applications, Static orientation detection which incorporate Portrait/Landscape, Up/Down, Left/Right, Back/ Front position identification, Notebook, e-reader, and Laptop Tumble and Freefall Detection, Real-time orientation detection including virtual reality and gaming 3D user position feedback, Real-time activity analysis such as pedometer step counting, freefall drop detection for HDD, dead-reckoning GPS backup and much more.

About This Instructable

500views

1favorite

More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay board Motion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python 3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python 
Add instructable to: