Example Code for Intersection Recognition

Last revision 2026/01/20

This project demonstrates hardware-level intersection recognition on the Maqueen Plus V3, enabling simple and reliable autonomous navigation using MakeCode.

Introduction

The Maqueen Plus V3 integrates hardware-level intersection recognition directly into its onboard microcontroller. It can automatically detect and distinguish the following types of intersections on a black-line track:

  • Cross intersection (four-way)
  • T-intersection
  • Left-and-straight intersection
  • Right-and-straight intersection

This capability enables advanced navigation behaviors, such as route planning, conditional turning, and loop traversal—without requiring complex sensor logic in user code.

Two operational modes are supported:

  • Setting Mode: Predefine actions for each intersection type once at startup; execution runs autonomously in the background.
  • Query Mode: Continuously poll the current intersection state in the main loop for flexible, real-time decision-making.

Example 1: Recognize Intersections in Setting Mode

Introduction

In setting mode, the robot’s response to each intersection type is configured once during initialization (on start). The underlying firmware then handles all detection and action execution automatically during line-following—freeing the micro:bit from continuous polling.

Advantages:

  • Simplifies programming
  • Reduces CPU and memory usage
  • Runs reliably in the background

Limitations:

  • Only works with the built-in line-following function
  • Less flexible for dynamic or conditional logic

Hardware Preparation

  • Maqueen Plus V3
  • Printed track with multiple intersection types (e.g., square loop)
  • micro:bit
  • USB cable

Software Preparation

  • MakeCode Editor with Maqueen Plus V3 extension

Wiring Diagram

All components are integrated—no external wiring required.

Sample Code

View on MakeCode

MakeCode block configuration

Program Logic:

  • Enable built-in line-following at speed level 3
  • Set predefined actions for each intersection:
    • At cross intersection → go straight
    • At T-intersection → turn right
    • At left+straight → turn left
    • At right+straight → go straight (or custom)
  • Robot autonomously navigates the square route

Result

Square track with red navigation path
The robot continuously drives around the square loop without any loop-based logic, demonstrating seamless background execution.


Example 2: Intersection Recognition in Query Mode

Introduction

In query mode, the program actively reads the current intersection state in the main loop using a dedicated sensor block. This approach offers full flexibility—you can combine intersection data with other sensors, display feedback, or implement custom decision trees.

Advantages:

  • Works independently of built-in line-following
  • Can be combined with obstacle avoidance, sound control, etc.
  • Real-time status access

Limitations:

  • Must be called continuously in the loop
  • Avoid pause() or long delays—may miss state changes

Hardware Preparation

  • Maqueen Plus V3
  • Line-following track with intersections
  • micro:bit

Software Preparation

  • MakeCode with Maqueen Plus V3 extension

Wiring Diagram

Fully integrated system.

Sample Code

View on MakeCode
micro:bit shows intersection ID, lights change color
Program Logic:

  • Run basic line-following in the loop
  • Use Maqueen Plus V3.intersectionType() to get current intersection ID
  • Map each ID to:
    • A number displayed on the micro:bit LED matrix
    • A unique vehicle light color (e.g., red for T-junction, green for cross)

Result

Real-time visual feedback confirms accurate intersection detection and enables debugging or interactive applications.


Example 3: Driving Along a Specified Route

Introduction

This advanced example combines both setting mode and query mode with the built-in line-following function to navigate a complex, multi-segment route—similar to GPS-guided car navigation. The robot follows a predetermined path through a sequence of intersections with varying turn instructions.

Route Description

As shown below, the robot follows the red arrow path through:

  • 3 cross intersections
  • 2 T-intersections
  • 2 right-and-straight intersections

Each instance may require a different action (e.g., first T-junction → turn right; second → also turn right, but under different context).

Complex route map with red arrows

Execution Sequence

  1. At first cross intersection → go straight
  2. At next cross intersection → turn left
  3. At first T-intersection → turn right
  4. At next cross intersection → turn left
  5. At second T-intersection → turn right
  6. At first right+straight → turn right
  7. At second right+straight → go straight
  8. Return to start → stop line-following

Hardware Preparation

  • Maqueen Plus V3
  • Full track matching the route diagram
  • micro:bit

Software Preparation

  • MakeCode with Maqueen Plus V3 extension

Sample Code

View on MakeCode
Robot executing multi-turn navigation
Implementation Strategy:

  • Use a step counter/state machine to track progress along the route
  • In the loop, read intersection type via query mode
  • Based on current step + intersection type, execute precise maneuver
  • After final segment, disable line-following

Result

The robot successfully completes the entire route with accurate turns at every junction, demonstrating robust integration of intersection recognition and sequential control logic.

Was this article helpful?

TOP