Source: https://mokxi.com/teachers/plans/sensor-fusion-and-kalman
Updated: 2026-11-19

Lesson plan

# Sensor fusion and the Kalman filter lesson plan

The math behind fusing sensors, honest about its limits: noise as variance, the EMA, the complementary filter derived, the Kalman filter from one state to two, GPS fused with a compass, and an attitude display that learns its gyro biases.

4 chapters, 7 lessons, about 7 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

- Variance, the square-root law, and the noise and lag of the two everyday smoothing filters.
- The complementary filter derived, then the scalar Kalman filter worked to its steady state.
- Angle and bias in a two-state filter, and a GPS fused with a compass, wrong compass included.
- An artificial horizon that learns its gyro biases and holds steady through a shake.

### Materials for the whole unit

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- GPS module, NEO-6M
- Half breadboard
- LED x 2
- Nine-axis IMU, MPU-9250
- OLED display, 128x64
- Resistor x 2

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

## Noise, measured

Variance, the square-root law, and the noise and lag of the two everyday smoothing filters.

Lesson | Time | What students do

Noise, measured Every filter starts from a number for the noise. Measure a noisy pitch in windows of 200: mean, standard deviation, variance and the 68-95 rule, then see averaging cut the noise by the square root of the count. | 55 min

- Run it
- Mean and standard deviation
- The 68-95 rule
- Noise does not care about the angle
- Averaging divides by the square root
- A noisier sensor

Moving average and EMA Two smoothing filters on the same noise: a moving average of 8 and an exponential moving average. Predict how much noise each removes and how long each lags, measure both with a step test, and trade one for the other. | 55 min

- Run it
- How much noise each removes
- The step test
- Trade noise for lag
- A longer average
- When averages fail

### Materials

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3

### Check for understanding

Each student finishes "Moving average and EMA" 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: "When averages fail".

Chapter 2. About 1 h 50 min

## From fusion to Kalman

The complementary filter derived, then the scalar Kalman filter worked to its steady state.

Lesson | Time | What students do

The complementary filter, derived The filter you tuned by hand, done properly: alpha from tau and dt, the crossover frequency where gyro hands over to gravity, the steady error a bias leaves (bias x tau), and the accelerometer noise that gets through, each predicted and then measured. | 55 min

- Run it
- Two filters that add to one
- Bias times tau
- The noise that gets through
- A shorter tau
- Where the complementary filter stops

The 1D Kalman filter One state, four lines: predict, gain, update, shrink. Work the first steps by hand, watch the gain settle to the steady state Q and R set, catch a move with the innovation test, and see what a wrong R does. | 55 min

- Run it
- The first step by hand
- The steady state
- The innovation test
- Tune Q
- Lie about R

### Materials

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3

### Check for understanding

Each student finishes "The 1D Kalman 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: "Lie about R".

Chapter 3. About 2 h

## Kalman for real

Angle and bias in a two-state filter, and a GPS fused with a compass, wrong compass included.

Lesson | Time | What students do

Kalman for tilt The gallery’s Kalman filter tilt angle: an MPU6050 through TKJ Electronics’ two-state filter, angle and gyro bias, plotted beside the accelerometer, the gyro alone and a complementary filter. Read the 2 x 2 matrices, follow a tilt, and tighten the level. | 55 min

- Run it
- Two states
- Follow a tilt
- Off level
- A tighter level
- Kalman or complementary?

GPS plus IMU A NEO-6M GPS and an MPU-9250 compass fused into one position: dead reckoning from speed and heading between fixes, a gain that weighs each fix, the error measured against the truth, a GPS outage, and a compass that is 10 degrees wrong. | 65 min

- Run it
- Predict, then update
- Score it
- Lose the fix
- A wrong compass
- Trust the GPS more
- What a real INS adds

### Materials

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- GPS module, NEO-6M
- Half breadboard
- LED x 2
- Nine-axis IMU, MPU-9250
- Resistor x 2

### Check for understanding

Each student finishes "GPS plus IMU" 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: "What a real INS adds".

Chapter 4. About 1 h 5 min

## Boss build

An artificial horizon that learns its gyro biases and holds steady through a shake.

Lesson | Time | What students do

Boss: a steady attitude display An artificial horizon on an SSD1306 OLED, driven by two two-state Kalman filters written out in the sketch: they learn each gyro’s bias while they run, follow a tilt, and hold steady through a shake by trusting the gyro while the accelerometer lies. | 65 min

- Run it
- The horizon
- Learning the biases
- Bank it
- Shake it
- A worse gyro
- Make it yours

### Materials

- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- OLED display, 128x64

### Check for understanding

Each student finishes "Boss: a steady attitude display" 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.
