Using an Analog Accelerometer

Dear readers, please note that this is the old website of maxEmbedded. The articles are now no longer supported, updated and maintained. Please visit the new website here and search for this post. Alternatively, you can remove .wordpress from the address bar to reach the new location.

Example: If the website address is, then removing .wordpress from it will become

We apologize for the inconvenience. We just want to give you a better viewing and learning experience! Thanks!

Everybody would have at least once heard of  “accelerometer“, most probably, in some way associated to smartphones. But what actually are they?


What are they?

Well, according to the dictionary, an accelerometer is a device (a sensor) that is typically used to measure the acceleration (very obvious from the name!).

An accelerometer is an electromechanical device that will measure acceleration forces. These forces may be static, like the constant force of gravity pulling at your feet, or they could be dynamic – caused by moving or vibrating the accelerometer.

There are two types of accelerometers available:

  1. Analog
  2. Digital

In this post, we will be discussing about the analog accelerometers. We will discuss about digital ones later.

Where are they used?

Accelerometers find a variety of uses in the modern world. Nowadays, they are an integral part of your smartphones! Yes! They are the ones, which are responsible for screen rotation when you change the orientation of your phone! Motion gaming is another use of the accelerometer. They are also used to measure the acceleration of automobiles, ships, aircrafts, spacecraft, or in those applications wherein vibrations of a machine, a building etc. need to be found out.

So we see that there are a vast number of uses of this device. Wondering how it works?

How they work?

There are many ways in which accelerometers work, some of them are:

  1. Some use the piezoelectric effect i.e. they contain microscopic crystal structures which upon getting stressed by acceleration forces generate a voltage across its ends.
  2. Another way to do it is by sensing changes in capacitance. If you have two microstructures next to each other, they have a certain capacitance between them. If an acceleration force moves one of the structures, then the capacitance will change. Add some circuitry to convert from capacitance to voltage, and you will get an accelerometer.
  3. Accelerometers use a quartz crystal mounted between a fixed point and a free floating mass. The mass puts pressure on the crystal and generates a tiny voltage (some work on resistance or capacitance change). As the direction of gravity’s pull changes, so does the force of the crystal and the signal it generates.
  4. There are even more methods, including use of the piezoresistive effect, hot air bubbles, and light.

3-Axis Accelerometer

We are using a 3-Axis Accelerometer. But why 3-axis? 3-axis accelerometers are the most convenient to use, and they provide us the flexibility to use all the 3 spatial axes, viz the x-axis, the y-axis, and the z-axis. Of course you can go for  a single axis or a dual axis accelerometer if only the respective axes are required, but if you are buying an accelerometer module for experimental purposes, go for a 3-axis one!

Since ours is an Analog Accelerometer, it gives an output of varying voltage depending upon the acceleration, but obviously it has some minimum output voltage and a maximum output voltage. There are many IC packages available for 3-axis accelerometers. Most popular of them are the ADXL330 and ADXL335 by Analog Devices.

slide6 slide8

They have a sensitivity of ±3g. There are many more available, which have better sensitivity, such as ADXL326 which has a sensitivity of ±16g, etc. I use A7260 based module, which has selectable sensitivity from ±1.5g to ±6g. It also has a ‘sleep mode’ to reduce power consumption when not in use. But what does sensitivity of an accelerometer exactly mean?


Sensitivity is the ratio of change in acceleration (input) to change in the output signal. It is the absolute minimum amount of change in input signal which can be detected by the measuring device. This defines the ideal, straight-line relationship between acceleration and output.  For analog-output sensors, sensitivity is ratiometric to supply voltage; doubling the supply, for example, doubles the sensitivity. In terms of accelerometers, sensitivity refers to the minimum change in acceleration which can be detected by the device.

Pin Description

Below is the pin description of the ADXL ICs, which are available only in TQFP packages:

ADXL330 Pinout

ADXL330 Pinout

The pinout for all the ADXL ICs is the same as shown above.

ADXL Pinouts

ADXL Pinouts

Before we proceed to the Pin Description, we will get acquainted with some basic terms:

  1. Input supply voltage: this is the Supply voltage (VSS) for the IC to work on. The ADXL330 and ADXL335 are capable of working on supply voltages ranging from 1.8 volts (minimum) to 3.6 volts (maximum)
  2. Ratiometric Output: This means that the output voltage from the pins (ZOUT, YOUT, XOUT) depend on the supply voltage given at the Vss pin.
  3. Zero g Bias level: this means the voltage output through the Out pins at the mean position, i.e. when there is no net acceleration in the respective axis.

ADXL330 vs ADXL335

Now here comes the difference between the two ICs! While in ADXL330, the Zero g bias level for all the Axes stands same at 1.5 volts, typical min at 1.2 volts and typical max at 1.8 volts, in the ADXL335, the Zero g Bias Level is 1.5 volts for all axes as well, but the typical extremes differ: they are 1.35v to 1.65v for the X, Y axes, while they range from 1.2v to 1.8v in the Z-axis.

You might feel there is not much difference between the two. Indeed you are right, but when it comes to precision, ADXL335 is better. Since the typical extremes range is lesser in ADXL335, one will have easier calibration issues and lesser inaccuracies.

PIN Description

  1. NO CONNECTION: you have to leave these pins floating. They do not need to be connected anywhere.
  2. COMMON: these pins need to be connected to the ground.
  3. VSS: this is the supply input voltage for the IC to work. The recommended input supply voltage is 3.0 volts.
  4. ZOUT, YOUT, XOUT: These are the analog output pins for the respective axes.
  5. Self-Test: The ST pin controls the self-test feature. When this pin is set to VSS, an electrostatic force is exerted on the accelerometer beam. The resulting movement of the beam allows the user to test if the accelerometer is functional. The typical change in output is −1.08 g (corresponding to −325 mV) in the X-axis, +1.08 g (or +325 mV) on the Y-axis, and +1.83 g (or +550 mV) on the Z-axis. The ±g are with respect to the Zero g bias level, and hence we always get a +voltage output.

This ST pin can be left open-circuit or connected to common (COM) in normal use.

In the market, we mostly find the Accelerometer Modules… i.e. with all the connections already made. A number of them are available here, and here and here and here and here as well! So don’t you worry, you wont have to solder the circuit all by yourself! 😉

I have an MMA7260 based Accelerometer module, which looks like this:

MMA7260 Accelerometer

MMA7260 Accelerometer

MMA7260 Accelerometer

MMA7260 Accelerometer

MMA7260 Accelerometer

MMA7260 Accelerometer

MMA7260 is an accelerometer by Freescale Semiconductor. Recently Freescale has stopped manufacturing this unit and hence you may not find it available in the market. Although this is not ADXL based, but it’s working is similar.

The ADC – Analog to Digital Conversion

Well, obviously, one cannot use an analog accelerometer without the prior knowledge of ADC. So, if you are not clear with the concepts of ADC, take a detour and go through Mayank’s awesome Post on ADC!

Hardware Connections

These are the schematics for ADXL3xx based accelerometer modules:


ADXL Schematics (Click to Enlarge)

Some points to note are:

  1. The Vss Pin is to be connected to +5V supply. This is because all the modules have a 3V voltage regulator.
  2. The Vdd Pin is to be connected to the ground.
  3. The Self Test Pin is to be left floating/ grounded.
  4. The Pins ZOUT, YOUT, XOUT have to be connected to the ADC Inputs of the Microcontroller.

I will be using ATMega16A to demonstrate the use. As an example, I will display the output on a character LCD. If you are not well versed with the use of LCD, read Mayank’s great post on LCD here!

Problem Statement

Let us define a problem statement for this. Our task is to initialize the Accelerometer module and display the results of all the axes on a Character LCD.


Now if you follow Mayank’s ADC tutorial, there is no more explanation necessary. Here is the final code! This code is compiled using Atmel Studio 6.

This code is also available for viewing/downloading at the AVR Code Gallery and Pastebin.

#ifndef F_CPU
#define F_CPU 16000000UL

#include <avr/io.h>
#include <stdlib.h>		//include Library for 'itoa' function
#include "lcd.h" 		//include LCD Library
#include <util/delay.h>

void adc_init(void)
    ADCSRA|=(1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2); //ENABLE ADC, PRESCALER 128

uint16_t adc_read(uint8_t ch)
    ch&=0b00000111; 		//ANDing to limit input to 7
    ADMUX = (ADMUX & 0xf8)|ch; 	//Clear last 3 bits of ADMUX, OR with ch
    return(ADC); 		//RETURN ADC VALUE

int main(void)
    uint16_t x,y,z;
    char bufferx[10], buffery[10], bufferz[10]; //Initialize character arrays for each

    adc_init(); 		//INITIALIZE ADC
    lcd_init(LCD_DISP_ON); 	//INITIALIZE LCD
    lcd_clrscr(); 		//CLEAR LCD SCREEN

        lcd_home(); 		//LCD - GO TO HOME POSITION

        x=adc_read(0); 		//READ ADC VALUE FROM CHANNEL 0
        y=adc_read(1); 		//READ ADC VALUE FROM CHANNEL 1
        z=adc_read(2); 		//READ ADC VALUE FROM CHANNEL 2

        itoa(x,bufferx,10); 	//STORE THE ADC VALUES IN ARRAYS

        lcd_puts("x="); 	//DISPLAY THE RESULTS ON LCD



Though the code is self explanatory, a few points need to be highlighted. As you would see in the video (scroll down), the output from the ADC Conversion shows values ranging from ~300 to ~750 for all the three axes. This is because we have set the reference voltage as 5V, but the accelerometer is giving an output ranging from ~1.46V (corresponding to -ve extreme) to ~3.6V (corresponding to +ve extreme).

Experimental Setup and Video

My final Setup looks like this:


The Final Setup

The Final Setup


So this is it! We will be posting a few more accelerometer based projects soon. More interesting posts to come up! So subscribe to stay updated! And don’t forget to jot down any comment which will help in improving the quality of this and upcoming posts on!

Thanks and Regards,

Yash Tambi

10 responses to “Using an Analog Accelerometer

  1. Nice tutorial :D. Well currently i don’t have an accelerometer module but i somehow managed to found the ADXL377 ic.How can i connect it to various component to make a module so that it can be interfaced with the microcontroller ?

    • Hello Tushar!
      Thanks! 🙂
      I believe that ADXL337 is available only in MLF, so you would find it very difficult to solder it.
      Anyways, to make a module, few things that you will need to know:
      1. The IC operates in ~1.8 to 3.6V range. So you will have to use a suitable voltage regulator.
      2. The typical supply current at the Vcc pin is ~300µA. So select a suitable resistor to be used.
      3. To decouple from supply noise, a capacitor of 0.1µF, connected from the supply line to the ground is enough.
      4. Similarly, Capacitors must be added at the X, Y, and Z output pins to implement low-pass filtering for antialiasing and noise reduction. A 4.7µF capacitor connected to each output line, the other end of the capacitor grounded, will serve the purpose.

      Hope this helps!

  2. Pingback: Sensor Fundamentals | maxEmbedded·

    i have a doubt in this tutorial.Why the voltage value is changing when the accelerometer is tilted.

    • This is what an accelerometer does.It’s a MEMS based device and gives the voltage proportional to it’s tilt position just like a temperature sensor,which gives voltage according to the temperature detected

  4. very nice tutorial………..thanks for tutorial …..
    please tell me how can i interface my smartphone’s accelerometer to any bot?????????

    • Hello Mohan!
      Yes definitely you can! Youll need an app which interprets the accelerometer data and sends it, most suitably, through bluetooth (the protocol would be UART).

  5. What is these two lines says
    and what is itoa function ??
    I am getting error here. can u plz help me out??
    #include //include Library for ‘itoa’ function
    #include “lcd.h” //include LCD Library

    • Hashah,
      itoa() converts integer to character. Google up for more information.
      #include statements are used to include libraries necessary to compile and build your code. Please be familiar with C before jumping into embedded systems programming.

We'd love to hear from you!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s