Home β€Ί Sensor Fusion
⚑ Module 02 · Intermediate

Meet Your Robot's Super-Sense!

What if your robot could feel which way is up, even with its "eyes" closed? That's the superpower of Sensor Fusion! We're going to combine different robot sensesβ€”like balance and spinβ€”to create one super-smart sense that's better than the sum of its parts. Let's build a brain! 🧠

✨ PAN'S RULE: If it's not chaotic, it's not magic! ✨

⚠️ SAFETY CHECK: We only work with safe 5V USB power or AA/AAA batteries. NEVER plug homemade electronics into a wall outlet. Also, always handle batteries with care β€” never puncture them, and ask a parent for help if you're not sure!
πŸ”Œ

The Robot Post Office

Imagine your robot's brain is a post office, and all its sensors are houses on the same street. How does the brain send a message to just *one* house without bothering all the others? It uses a special postal service called I2C (Inter-Integrated Circuit). It's a clever system that lets tons of sensors share just two wires!

🧠
Robot Brain
(Post Office)
πŸ“¬ Mail Wires (I2C)
🏠
Gyroscope
(0x68)
🏠
Accelerometer
(0x53)
πŸ€” How it Actually Works: The "Mail Wires" are a team of two! The SDA (Serial Data) wire carries the actual letter (the data). The SCL (Serial Clock) wire is like a metronome, ticking to tell all the sensors exactly when to check for new mail.

The Postman Challenge! πŸ“¬

The brain needs spin data from the Gyroscope at address `0x68`. Can you click the right mailbox?

Address: 0x53
Address: 0x68
Address: 0x77
πŸ“Ί Lesics β€” "Sensor Fusion | An Unsung Hero of Modern Engineering" β€” A super clear animation of how combining sensors creates a super-sense!

Meet the Sensors! πŸ‘‹

These three sensors are often combined in phones and robots. Let's match the sensor to its super-power! Which sensor tells the robot if it's spinning around?

Accelerometer (senses gravity)
Gyroscope (senses rotation)
Magnetometer (senses magnetic north)
πŸ€–

Your First Sensor Fusion

Sometimes, one sensor is a little shaky. An accelerometer knows which way is down, but it wiggles. A gyroscope knows when it's turning, but it can drift over time. By *fusing* their data together, we get one smooth, super-smart reading! Let's try it.

MISSION: Stabilize the robot! The accelerometer is trustworthy, but the gyroscope is a little shaky. The *real* angle should be 90. Tweak the 'weights' in the code below. Give the trustworthy sensor a bigger weight to get the 'Fused Angle' to exactly 90.00! Ready, pilot?

Output will appear here...
πŸš€

From Simulation to Reality

That was cool, right? On a real Arduino, that same idea looks like this. Don't worry about understanding every lineβ€”just see how the ideas we learned (like the I2C address!) connect to real code.

curious to see what REAL robot code looks like? πŸ‘€

The `setup()` function runs once when the robot first turns on. It's for waking everything up. Click on the blue words to learn more!

// This is REAL code for an Arduino!
#include <Wire.h> 
#define MPU6050_ADDR 0x68 // The sensor's I2C address! See?

void setup() {
  Wire.begin(); // Wake up the I2C "post office"
  Wire.beginTransmission(MPU6050_ADDR); // Ping the sensor
  Wire.write(0x6B); // Talk to the power register
  Wire.write(0);    // Tell it to wake up!
  Wire.endTransmission(true);
}

The `setup()` function runs once. But a robot needs to check its sensors constantly! That's what the `loop()` function is for. It runs over and over, forever.

// This code runs again and again!
void loop() {
  // 1. Read the raw sensor values
  long accel_val = readSensor(ACCEL_REG);
  long gyro_val = readSensor(GYRO_REG);

  // 2. Do the fusion math (like our simulator!)
  float fused_angle = 0.98 * (last_angle + gyro_val * dt) + 0.02 * accel_val;

  // 3. Print it to the screen so we can see it
  Serial.print("Fused Angle: ");
  Serial.println(fused_angle);

  delay(10); // Wait a tiny bit before looping
}

πŸ‘¨β€πŸ‘©β€πŸ‘§ Parent Corner: Weekend Project

Ready to build a real robot brain? The concepts on this page can be brought to life with an Arduino board and an "MPU-6050" sensor module. You can find these parts on sites like Adafruit or SparkFun for under $10 total. Before buying anything, you can try these concepts for free in an online simulator like Wokwi. It's a fantastic way to experiment with code and circuits right in your browser! This is a great weekend project to tackle together.

Watch a Beginner Tutorial

🧠 Boss Level: The Kalman Filter

You've learned to combine two sensor readings. But what if you could use math to *predict* where the sensor will be next, even before it moves? That's the magic of a Kalman Filter. It's the algorithm used in rocket guidance systems and self-driving cars. The video below is advanced, but it's a real look at how the pros do sensor fusion. No quiz, just pure discovery. Ready for the deep dive?

For another mission, check out the Adafruit guide and see if you can find the name of the sensor they use to measure altitude. Good luck!

Adafruit Guide to Sensors β†’