Source: https://mokxi.com/teachers/plans/motion-sensors-imu
Updated: 2026-11-19

Lesson plan

# Accelerometers, gyros and IMUs lesson plan

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.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- An accelerometer measures gravity as a vector: three numbers, raw counts, and the angle they hide.
- A gyro added up into an angle, the drift that comes with it, and the one-line filter that fixes it.
- A magnetometer compass and its traps, then a stream of readings turned into steps and taps.
- A builder’s level and a compass that stays true when you tip it, on an MPU-9250.

### Materials for the whole unit

- Accelerometer and gyroscope, MPU6050
- Accelerometer, ADXL345
- Arduino Uno R3
- Half breadboard
- LED x 2
- Magnetometer, LIS3MDL
- Nine-axis IMU, MPU-9250
- Resistor x 2
- Six-axis IMU, LSM6DSOX

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

## Which way is down

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

Lesson | Time | What students do

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. | 50 min

- Run it
- Tip it 30 degrees
- Counts, not g
- Two tilts at once
- A push looks like a tilt
- Change the range

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. | 50 min

- Run it
- Flat is level
- Which way to tip
- How wide is the band?
- atan2, not asin
- Tighten it to a degree

### Materials

- Accelerometer and gyroscope, MPU6050
- Accelerometer, ADXL345
- Arduino Uno R3
- Half breadboard

### Check for understanding

Each student finishes "Tilt from the accelerometer" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Tighten it to a degree".

Chapter 2. About 1 h 40 min

## Turning and drifting

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

Lesson | Time | What students do

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. | 50 min

- Run it
- Watch it walk
- Rate times time
- Calibrate it out
- Follow a real tilt
- A worse gyro

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. | 50 min

- Run it
- Where the drift went
- Shove it
- Follow a real tilt
- Change the time constant
- Pick a tau for a job

### Materials

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3

### Check for understanding

Each student finishes "The complementary filter" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Pick a tau for a job".

Chapter 3. About 1 h 40 min

## North, steps and taps

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

Lesson | Time | What students do

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. | 50 min

- Run it
- The field, as numbers
- Turning, from the gyro
- Tip the compass
- True north
- Hard and soft iron

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. | 50 min

- Run it
- Ten steps
- Cadence
- A knock
- Double tap
- Count gentle steps

### Materials

- Accelerometer, ADXL345
- Arduino Uno R3
- Half breadboard
- Magnetometer, LIS3MDL
- Six-axis IMU, LSM6DSOX

### Check for understanding

Each student finishes "Step and tap detection" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Count gentle steps".

Chapter 4. About 1 h

## Boss build

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

Lesson | Time | What students do

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. | 60 min

- Run it
- Level within a degree
- Off level
- A compass, flat
- Tip it, and it stays true
- True north for your town
- Make it yours

### Materials

- Arduino Uno R3
- Half breadboard
- LED x 2
- Nine-axis IMU, MPU-9250
- Resistor x 2

### Check for understanding

Each student finishes "Boss: a level and compass" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
