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.
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.
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 vectorRead 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 |
|
| Tilt from the accelerometerAn 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 |
|
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".
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 driftAdd 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 |
|
| The complementary filterOne 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 |
|
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".
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 headingAn 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 |
|
| Step and tap detectionTurn 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 |
|
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".
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 compassAn 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 |
|
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".
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.