Accelerometer and gyroscope
An accelerometer measures acceleration, including gravity, along its axes, so at rest it shows which way is down; a gyroscope measures how fast it is rotating, in degrees per second. At rest, an accelerometer gives its tilt as θ = arctan(x ÷ z), so equal readings of 0.71 g on x and z mean 45°.
θ = arctan(x ÷ z)
where x and z are the readings, in g, on the axis tilted and the axis that was pointing up.
Phones, drones and game controllers combine both in an IMU, because each covers the other’s weakness.
What is an accelerometer?
An accelerometer is a sensor that measures acceleration along one, two or three axes, in g, including the constant 1 g pull of gravity.
That makes it a tilt sensor when still: gravity divides between its axes in proportion to the angle, as Figure 1 shows, which is how a phone knows to rotate its screen. While moving, it adds the motion’s acceleration on top, so it also counts steps and detects taps, shakes and falls.
Tilted 30°: gravity splits between the axes: x = sin 30° = 0.5 g and z = cos 30° = 0.866 g, so arctan(x ÷ z) = 30° recovers the tilt.
How does an accelerometer work?
A MEMS accelerometer works with a tiny silicon mass on springs between capacitor plates: when the chip accelerates, the mass lags behind, changing the gaps and so the capacitances.
The chip measures that difference, far smaller than a hair’s width, and turns it into a reading, as Figure 2 shows. MEMS means micro-electro-mechanical systems: machines etched into silicon alongside the electronics, small enough to fit three axes in a few square millimeters.
1 g: the chip speeds up to the right and the mass lags behind, closing the gap at C1. Its capacitance rises to 1.11× while the other falls to 0.909×, and the chip turns that difference into the reading.
What is a gyroscope?
A gyroscope sensor measures how fast it is turning about each axis, its angular rate, in degrees per second, rather than which way is down.
MEMS gyroscopes keep a tiny mass vibrating; when the chip rotates, the Coriolis effect pushes the mass sideways, and the chip measures that push. They respond fast and smoothly, ignore being shaken in a straight line, and are what keeps a drone level and a camera’s image steady.
Why combine an accelerometer and a gyroscope?
An accelerometer and a gyroscope are combined because their errors are opposite: a gyroscope’s angle is smooth but drifts over time, while an accelerometer’s tilt never drifts but jumps with every bump.
A gyroscope gives the angle only by adding up its rate, so any small bias adds up too. A complementary or Kalman filter follows the gyroscope from moment to moment and pulls gently toward the accelerometer’s tilt, so the angle stays smooth and true, as Figure 3 shows.
Gyroscope alone, 1 min: adding up its rate reading gives the angle, but a 0.05 °/s bias adds up too: 0.05 °/s × 60 s = 3° of error, and growing.
What is an IMU sensor, like the MPU-6050?
An IMU, or inertial measurement unit, is a sensor chip combining a 3-axis accelerometer and a 3-axis gyroscope, and sometimes a magnetometer for heading, making 6 or 9 axes.
The MPU-6050 is the common hobby 6-axis IMU. It talks over I²C, and its ranges are set in software: ±2 to ±16 g and ±250 to ±2,000 °/s. Breakout boards include a regulator so an Arduino can power them from 5 V; connect SDA and SCL to the board’s I²C pins.
What are accelerometers and gyroscopes used for?
Accelerometers and gyroscopes are used by phones to turn the screen and count steps, by drones and balancing robots to stay level, and by cameras to steady the picture.
Cars use accelerometers to fire airbags and gyroscopes for stability control; game controllers and VR headsets track movement with both. Like a Hall sensor or a PIR, they sense without touching anything.
How do you work out tilt and acceleration from readings?
To work out tilt at rest, take the arctangent of the x reading over the z reading, so equal readings mean 45°; for acceleration, divide a raw reading by the counts per g.
Example 1: tilt from an accelerometer
An accelerometer lying still reads 0.5 g on x and the rest of gravity on z. How far is it tilted?
- Given
- an accelerometer at rest reading x = 0.5 g and z = 0.866 g
- Find
- its tilt
- Solution
- θ = arctan(x ÷ z) = arctan(0.5 ÷ 0.866) = 30°
- Answer
- 30°
Example 2: a raw reading in g
An MPU-6050 set to ±2 g gives 16,384 counts per g. One axis reads 8,192. What acceleration is that?
- Given
- an MPU-6050 on its ±2 g range, reading 8,192 on one axis
- Find
- the acceleration
- Solution
- a = 8,192 ÷ 16,384 counts per g = 0.5 g
- Answer
- 0.5 g
Summary
Key equations
- θ = arctan(x ÷ z) tilt at rest
- x = sin θ, z = cos θ gravity on the axes, in g
- angle = rate × time from a gyroscope
- g = counts ÷ 16,384 MPU-6050 at ±2 g
Key terms
- g
- 9.81 m/s², gravity’s pull.
- MEMS
- Tiny machines etched in silicon.
- Drift
- A slowly growing angle error.
- IMU
- An inertial measurement unit.
Practice problems
-
An accelerometer lies flat and still. What does its z axis read?
At rest it feels gravity: 1 g on the axis pointing up, even though it isn’t moving.
-
What does a gyroscope measure?
It reports how fast it turns, in degrees per second; the angle comes from adding that up over time.
-
An accelerometer at rest reads x = 0.5 g and z = 0.866 g. What is its tilt?
arctan(0.5 ÷ 0.866) = arctan(0.577) = 30°.
-
A gyroscope has a 0.1 °/s bias. How far off is its angle after 5 minutes?
0.1 °/s × 300 s = 30° of drift, which is why a gyroscope alone can’t hold an angle.
-
An MPU-6050 at ±2 g reads 16,384 on one axis. What is that?
At ±2 g it gives 16,384 counts per g, so 16,384 counts is 1 g.
FAQ
What is the difference between an accelerometer and a gyroscope?
An accelerometer measures acceleration, including gravity, so it senses tilt and movement; a gyroscope measures rotation rate.
Why does my accelerometer read 1 g when it isn’t moving?
It feels the floor holding it up against gravity, which is indistinguishable from accelerating upward at 1 g.
Can an accelerometer measure speed?
Only by adding up acceleration over time, which drifts quickly; phones use GPS for speed instead.
What is gyroscope drift?
A slowly growing angle error, from a small bias in the rate reading being added up over time.
What is a 9-axis IMU?
One with a 3-axis accelerometer, a 3-axis gyroscope and a 3-axis magnetometer, which adds compass heading.
Does the MPU-6050 work on 5 V?
The chip itself runs from about 3.3 V, but most breakout boards add a regulator, so they take 5 V on VCC.
What is g in an accelerometer?
The acceleration of gravity at Earth’s surface, about 9.81 m/s². Readings in g compare an acceleration with it.