Accelerometer, Gyroscope and IMU Sensors – Tutorials

This article was last modified on March 2018.

Before starting to work on a project, it usually takes a few tens of minutes for me to collect pieces of information about the components used in the project. Probably the same thing happens to you. And that’s why I write this article to stop searching all the information needed in different places and save some precious time.

In this article, I refer to the best sensors to build projects like a self-balancing robot, or a system to measure road conditions or even a gaming system. In all these projects and not only, you need to measure the force of the gravity and the angular velocity. These measurements can be made with an accelerometer, gyroscope, or an IMU sensor.

To work with these sensors, you need specifications, to know how to connect the sensor to a development board, and the programming code. All these information and much more are described below for each sensor.

What sensors you’ll find in this article:
Accelerometer Sensors

  • ADXL335
  • ADXL345

Gyroscope Sensor

  • L3GD20H

IMU Sensors

  • MPU6050
  • MPU9250


The ADXL335 (GY-61) is probably the most popular analog accelerometer used in the DIY community. It has a full sensing range of +/-3g on three axes (X, Y, Z) with a power consumption of 320uA. The sensor has a high accuracy and a very reasonable price.

Generally, the ADXL335 sensor is integrated into a module that makes easier the readings returned by this. Even if the sensor is 3V3 compatible, some of these modules have an on-board 3V3 regulator. This means that it is a perfect choice for directly interfaced to the analog pins of a 5V microcontroller such as the Arduino.

The price for an ADXL335 module varies depending on the features of the breakout board. Here on Amazon US and Amazon UK you can find a long list of ADXL335 models with different features and prices.

AXDLX335 Tutorials

  • Calibration and Programming
    Calibrating the sensor is an important step for applications requiring accurate measurements. The calibration is done by determining the sensor outputs for each axis when it is precisely aligned with the axis of gravitational pull. In this tutorial you have the calibration sketch for Arduino.
  • Interfacing ADXL335 with Arduino – In this tutorial are explained the steps required to read the values returned by the sensor with an Arduino UNO board. The tutorial includes the connection scheme and the Arduino sketch.
  • ADC Differential Pi with ADXL335 Accelerometer – The ADXL335 sensor can also be used with Raspberry Pi. In this tutorial, an ADC Differential Pi board is used to convert the analog signal returned by the sensor into a digital value for Raspberry Pi. It also uses the AB Electronics python library to talk to the ADC Differential Pi.


I treated separately the ADXL345 sensor by the ADXL335 because there are major differences between them. ADXL345 (also known as GY-291) is a more advanced sensor designed for mobile applications which run on battery. In other words, it’s perfect for robots and drones.

ADXL345 has a measuring range between +-2g and +-16 g. The sensor has a higher accuracy (angle measurement of less than 1°) and an energy consumption of about 10 times less than the ADXL335 version. Low power consumption is due to a sleep mode that is activated when the sensor is inactive.

Besides the differences above, there is at least another major difference between ADXL345 and ADXL335. The ADXL345 is a digital sensor that returns values via the I2C or SPI digital protocol.

The ADXL345 sensor can be purchased (Amazon US, Amazon UK) at a price below $10.

ADXL345 Tutorials

  • ADXL345 Hookup Guide – The first step with the ADXL345 is to calibrate it. In this tutorial, you will find information on how to read the minimum and maximum values returned by the sensor. These values can be used to calculate as accurately as possible the force of the gravity. The tutorial also includes the sensor mounting scheme and the Arduino sketch for reading the values returned by the sensor.
  • Interfacing Accelerometer ADXL345 (GY-291) with Arduino UNO/ Mega – This tutorial includes instructions for using the Adafruit_ADXL345_U.h library with Arduino UNO or Mega to return the values read by the sensor.
  • Connecting the ADXL345 accelerometer to the Raspberry Pi 3 – Because it is a digital sensor, the ADXL345 is also easy to use with a Raspberry Pi board, in this case with Raspberry Pi 3. The first step in this tutorial is to connect the sensor to Pi, then the author explains the commands to read the G forces on each axis.


A gyroscope sensor measures the rotational movement in degrees per second. One of the most used gyroscope sensors in the DIY area is the L3GD20H. This sensor is an improved version of the L3GD20 and L3GD4200.

This sensor can measure the rotational movement on 3 axes at a full scale of ±250, ±500 or ±2000 degrees per second.

L3GD20H is actually a small chip integrated on a breakout board. This small chip supports both I2C and SPI protocols. This means that you can interface with any microcontroller such as Arduino easily.

Most of the breakout boards who have an L3GD20H chip are designed with a built-in voltage regulator. The chip itself works at 3.3V, while most of the microcontrollers provide 5V.

The L3GD20H chip provides sufficient accuracy for most applications in robotics. For other applications where maximum accuracy is required, the sensor should be calibrated for zero-rate and sensitivity.

The price for a L3GD20H breakout board does not exceed $30 on Amazon US and £20 on Amazon UK.

L3GD20H Tutorials

  • Adafruit Triple Axis Gyro Breakout
    In this tutorial, you will find how to wire Arduino and the L3GD20H breakout board and how to read the data returned by the sensor. To make work even easier, the Adafruit L3GD20 Library is used in the tutorial to work on the low-level device communication with the Gyro module.
  • Raspberry Pi and L3GD20 sensor – This tutorial covers the Raspberry Pi communication with the L3GD20 sensor and the code needed to read the values returned by the sensor. Even if in the tutorial uses an L3GD20 sensor, the steps described remain the same for the L3GD20H sensor.


The MPU6050 is an accelerometer and a gyroscope sensor at the same time. This combination solves many of the problems of an accelerometer and a gyroscope sensor.

An accelerometer sensor measures the force of the gravity. In general, the measurements have a lot of error and noise. A gyroscope sensor measures the angular velocity. Also, this sensor can return the angular velocity of a robot with deviation. All these problems are solved by combining an accelerometer with a gyroscope sensor.

The MPU6050 has a 3-axis accelerometer and a 3-axis gyroscope in a single breakout board.

The sensor is based on MEMS (Micro Electro Mechanical Systems) technology and uses the I2C-bus to interface with the Arduino or any other prototyping board.

The price for this sensor does not pass $10 on Amazon US while on Amazon UK the price is also under £10.

MPU6050 Tutorials



The MPU9250 is even a bit more complicated than the MPU6050 sensor. The 9250 includes an accelerometer, gyroscope, and a magnetometer. This means that the sensor combines reading from the earth’s electromagnetic field as a magnetometer with readings of gravitational force and angular velocity. All these information makes it a compact navigation breakout board.

The sensor includes some nice features such as low pass filtering, motion detection, and a programmable specialized processor.

The price for a MPU9250 breakout board exceeds with few US dollars the $10 threshold on Amazon US. In most cases, the £ 10 threshold is not exceeded either on Amazon UK.

MPU9250 Tutorials

9 comments » Write a comment

  1. hello..
    can you help me brother to know about accelerometer+arduino?
    do you have a tutorial about it?
    if you have it, share it for me, please..


  2. Hi Sir,

    Can you mention something about the differences between accelero and gyro sensors and also their interdependence in some cases. How to come up to a decision as to use which one for which application ?

    Thanks in advance.

    • Hi,

      “If an accelerometer sensor is designed to measure the acceleration and tilt, or the gyroscopic sensor to measure angular velocity and orientation, IMU sensor is a special one designed to combine the features of an accelerometer and gyroscope in order to display complete information about the acceleration, position, orientation, speed, etc. for a robot.”

  3. can you pls help me out to learn basics of accelerometer and to interface it with atmega 8 microcontroller.

  4. I am sorry, but “Razor 6DOF and Arduino” link does not work.
    If you happen to remember, what is the link for this solution?
    Thank you

  5. Hello,
    This post is really informative & helped me a lot.
    Could you please give me a basic guideline for placement of the accelerometer & gyroscope on the PCB.
    Is there any need to add an error correction algorithm if the unit (with accelerometer & gyroscope) is placed in the tilted position?
    Would appreciate your response.

    Thank you

Leave a Reply

Required fields are marked *.