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:
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.
- 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.
- 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.
- 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.
- Arduino script for MPU-6050 auto-calibration – If you want to start working with the MPU6050 sensor, this is the first step. The calibration.
- Arduino – MPU6050 GY521 – 6 Axis Accelerometer + Gyro (3D simulation with processing) – This tutorial is for working with the 6 axis sensor and Arduino. You have the scheme and the code to read the values returned by the sensor through the I2C protocol.
- Measuring Rotation and acceleration with the Raspberry Pi – If you want to use Raspberry Pi to read the sensor’s values, this tutorial covers the steps to connect the sensor to the board and write the python code to display the values returned by the sensor.
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.
- Simple and Effective Magnetometer Calibration – Like many other sensors, the first step to have accurate data is to calibrate the sensor. This guide includes all the data to calibrate the MPU9250 sensor.
- Using the MPU9250 to get Real-time Motion Data – In this tutorial you find information how to get the direction and motion data of the sensor. In addition, the tutorial includes the code for auto-calibration of the magnetometer, which is necessary for accurate readings.
- How to setup the MPU9250 on a Raspberry Pi – A complete guide to read the MPU9250 data with a Raspberry Pi. The Pi runs a Python script and read the data through the I2C protocol.