← Back to Missions
MEDIUM • 45 MINUTES

Mission 4: Line Follower 🛤️

Teach the robot to follow a path autonomously!

🛤️

🎯 What You'll Learn

📡 Sensor Reading

How infrared sensors detect black vs white surfaces

🧠 If-Then Logic

Making decisions based on sensor data

🤖 Autonomous Behavior

Robot makes decisions without human control

⚖️ Calibration

Fine-tuning sensor sensitivity for accuracy

📦 What You Need

🏗️ First: Build Your Track!

Before coding, create a simple track using black tape on a light floor:

Track Design Tips:

  • Start simple: A straight line 6 feet long
  • Tape width: ¾ to 1 inch works best (about thumb-width)
  • Surface matters: Smooth, non-reflective floors are ideal
  • Gentle curves only: No sharp 90° turns yet—save that for later!
  • Test pattern: Try an oval or figure-8 once the straight line works
💡 Parent Tip: If you don't have tape, draw with a thick black marker on white poster board. The robot needs high contrast between the line and background!

🛠️ Let's Code!

1

Understand the Sensors

Flip the Maqueen upside down. See the two small sensors near the front? These are infrared line sensors. They shine invisible light downward and measure how much reflects back. Black absorbs light (low reading), white reflects (high reading).

🔬 Science Fact: Black objects absorb most light wavelengths, while white objects reflect them. Your robot uses this property to "see" the line!
2

Test the Sensors

In MakeCode, create a test program to see what the sensors detect:

Forever:
  If [Left Line Sensor] = 0:
    Show Icon ← (Left Arrow)
  If [Right Line Sensor] = 0:
    Show Icon → (Right Arrow)
  Else:
    Show Icon ✓ (Check)

Hold the robot over your black tape. The arrows show which sensor sees black!

📊 Sensor Values: 0 = detects black, 1 = detects white. Some Maqueen versions might be reversed—test yours to find out!
3

The Line Following Logic

Here's the strategy: The robot tries to keep the line between its two sensors. When it drifts, it corrects by turning!

Decision Tree:

  • Both sensors see white: Go straight (on the line!)
  • Left sensor sees black: Turn slightly right (drifted left)
  • Right sensor sees black: Turn slightly left (drifted right)
  • Both see black: Stop or slow down (wide line or intersection)
🧠 This is called a "feedback loop" - the robot constantly checks and corrects itself!
4

Write the Code

Here's the complete line-following program:

Forever:
  If [Left Sensor = 1] AND [Right Sensor = 1]:
    // Both see white - go straight
    Set Motors: Left=100, Right=100

  Else If [Left Sensor = 0] AND [Right Sensor = 1]:
    // Drifted left - turn right
    Set Motors: Left=100, Right=30

  Else If [Left Sensor = 1] AND [Right Sensor = 0]:
    // Drifted right - turn left
    Set Motors: Left=30, Right=100

  Else:
    // Both see black - stop
    Set Motors: Left=0, Right=0
⚙️ Speed Tuning: The numbers 100 and 30 control how sharp it turns. Experiment! Try 80/20 for sharper turns, or 100/70 for gentler curves.
5

Test & Tune

Upload the code and place the robot on your track with the line between the sensors. Power it on and watch it go!

Troubleshooting:

  • Robot veers off: Adjust turn speeds (try 100/20 or 100/50)
  • Zigzags wildly: Slow down base speed (try 70 instead of 100)
  • Doesn't detect line: Check tape contrast or sensor height
  • Ignores turns: Make curves wider and more gradual
🎯 Calibration Challenge: Can the boys tune the speeds so the robot follows smoothly without jerky movements? This teaches precision!
6

Level Up: Advanced Tracks

Once the basic line works, try these challenges:

  • Oval track: Can it do complete loops?
  • Figure-8: Test crossing paths (stop at intersections!)
  • Speed zones: Add colored tape = slow down code
  • Gaps in line: Program it to "remember" direction for 1 second
  • Race track: Who can tune their robot fastest without losing the line?

🔬 What's Happening Behind the Scenes?

The infrared sensors emit light at 940nm wavelength (invisible to humans). When this light hits a black surface, most photons are absorbed. White surfaces reflect them back to a photodetector in the sensor. The micro:bit reads this as a digital signal: HIGH (white) or LOW (black).

The program runs this check loop about 100 times per second—so even at full speed, the robot constantly adjusts its path!

Real-World Connection: This is exactly how warehouse robots, automated vacuums (Roomba), and self-driving cars stay on course. They use sensors + decision logic to navigate autonomously! 🚗🤖

Mission Success Checklist

🚀 Ready for More?

Awesome work! The robot now makes autonomous decisions using sensor feedback. This is real robotics! The boys learned about sensors, conditional logic, and calibration—skills used in Mars rovers and factory automation!

Keep experimenting: Can they design a race track with lap counting? Or add obstacles that it must navigate around while following the line?

Next Mission: Obstacle Avoider 🚧 →
← Back to All Missions