Source: https://mokxi.com/learn/path/motion-sensors-imu
Updated: 2026-11-20

All paths

# Accelerometers, gyros and IMUs

What a motion sensor really measures: gravity as a vector, tilt from atan2, gyro drift and calibration, the complementary filter, a magnetometer compass, step and tap detection, and a tilt-compensated level and compass.

Arduino Uno R3 Free 7 lessons 6 h 4 chapters 2,319 XP Robotics · Intermediate +150 XP

0 of 7 done

Start the course free Gravity as a vector Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Tilt from the accelerometer

An ADXL345 spirit level from the gallery: turn counts into degrees with asin and atan2, work out how many degrees its dead band is, and tighten it to one degree.
Open it in the simulator

Chapter 2 project

### The complementary filter

One line of code that keeps the gyro’s smoothness and the accelerometer’s honesty. Measure what is left of the drift, shove the board and see the filter shrug, follow a real tilt, and change its time constant.
Open it in the simulator

Chapter 3 project

### Step and tap detection

Turn a stream of accelerometer numbers into events: a step counter with two thresholds and a lockout, cadence in steps a minute, and a tap and double-tap detector that looks for a jump between two samples.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Which way is down

An accelerometer measures gravity as a vector: three numbers, raw counts, and the angle they hide.

Open 236 XP

### Gravity as a vector

Read an MPU6050 straight from its registers and watch 1 g of gravity split across three axes as you tip it. Predict each number with sines and cosines, read the raw counts, and find the one thing an accelerometer cannot tell apart.

0 of 6 steps

Start What is in it

Project Locked 472 XP

### Tilt from the accelerometer

An ADXL345 spirit level from the gallery: turn counts into degrees with asin and atan2, work out how many degrees its dead band is, and tighten it to one degree.

0 of 6 steps

5 questions, graded as you go.

Chapter 2

## Turning and drifting

A gyro added up into an angle, the drift that comes with it, and the one-line filter that fixes it.

Locked 236 XP

### Gyro drift

Add up a gyroscope into an angle and watch it walk away: a real gyro’s 0.4 degrees a second of offset, added in the sketch. Predict when it is 2 degrees off, measure the offset at rest, subtract it, and see the gyro follow a real tilt.

0 of 6 steps

Project Locked 436 XP

### The complementary filter

One line of code that keeps the gyro’s smoothness and the accelerometer’s honesty. Measure what is left of the drift, shove the board and see the filter shrug, follow a real tilt, and change its time constant.

0 of 6 steps

5 questions, graded as you go.

Chapter 3

## North, steps and taps

A magnetometer compass and its traps, then a stream of readings turned into steps and taps.

Locked 218 XP

### Magnetometer heading

An LIS3MDL magnetometer and an LSM6DSOX from the gallery: a compass heading from atan2, the turn rate from the gyro, why tipping a compass throws it off by tens of degrees, and true north from declination.

0 of 6 steps

Project Locked 472 XP

### Step and tap detection

Turn a stream of accelerometer numbers into events: a step counter with two thresholds and a lockout, cadence in steps a minute, and a tap and double-tap detector that looks for a jump between two samples.

0 of 6 steps

5 questions, graded as you go.

Chapter 4

## Boss build

A builder’s level and a compass that stays true when you tip it, on an MPU-9250.

Locked 249 XP

### Boss: a level and compass

An MPU-9250 on an Uno as a builder’s level with a green and a red LED, and a compass that stays right when you tip it: gravity gives roll and pitch, and they turn the magnetic field back to level before atan2.

0 of 7 steps

4 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Which way is down

- Gravity as a vector Read an MPU6050 straight from its registers and watch 1 g of gravity split across three axes as you tip it. Predict each number with sines and cosines, read the raw counts, and find the one thing an accelerometer cannot tell apart.
- Tilt from the accelerometer An ADXL345 spirit level from the gallery: turn counts into degrees with asin and atan2, work out how many degrees its dead band is, and tighten it to one degree.

Chapter 2

### Turning and drifting

- Gyro drift Add up a gyroscope into an angle and watch it walk away: a real gyro’s 0.4 degrees a second of offset, added in the sketch. Predict when it is 2 degrees off, measure the offset at rest, subtract it, and see the gyro follow a real tilt.
- The complementary filter One line of code that keeps the gyro’s smoothness and the accelerometer’s honesty. Measure what is left of the drift, shove the board and see the filter shrug, follow a real tilt, and change its time constant.

Chapter 3

### North, steps and taps

- Magnetometer heading An LIS3MDL magnetometer and an LSM6DSOX from the gallery: a compass heading from atan2, the turn rate from the gyro, why tipping a compass throws it off by tens of degrees, and true north from declination.
- Step and tap detection Turn a stream of accelerometer numbers into events: a step counter with two thresholds and a lockout, cadence in steps a minute, and a tap and double-tap detector that looks for a jump between two samples.

Chapter 4

### Boss build

- Boss: a level and compass An MPU-9250 on an Uno as a builder’s level with a green and a red LED, and a compass that stays right when you tip it: gravity gives roll and pitch, and they turn the magnetic field back to level before atan2.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Accelerometers, gyros and IMUs

Is Accelerometers, gyros and IMUs free?

Yes. All 7 lessons of Accelerometers, gyros and IMUs are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Accelerometers, gyros and IMUs take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Tilt from the accelerometer, The complementary filter and Step and tap detection.

Where do I start?

With "Gravity as a vector", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
