Lesson 5 Light Hunter

In nature, sunflowers rotate their flower heads to follow the sun, and smart streetlights can automatically turn on or off by sensing ambient light. These behaviors rely on the ability to perceive light.
In this lesson, students will program the Maqueen Lite V5 car to exhibit similar intelligent behavior: using its built-in light sensors to automatically detect and track a light source.
Through this lesson, students will learn the fundamentals of sensor data reading, logical decision-making, and action execution, gaining an understanding of the basic “sensing–thinking–acting” workflow in automated systems.

 

 

Task Objective


This lesson aims to guide learners in programming the Maqueen Lite V5 to automatically adjust its driving direction based on the difference in light intensity detected by the left and right light sensors, thereby enabling it to track a light source.

 

 

Knowledge Points


1.Understand the basic working principle of light sensors.
2.Learn how to read sensor values via the serial port and observe data changes.
3.Understand how conditional statements are used to control turning behavior.
4.Enable the robot car to intelligently adjust its path based on the direction of a light source.


Materials List

HARDWARE LIST
1 Maqueen Lite V5
1 micro:bit
1 Micro USB Cable

Software

Mind+ Programming Software x1
Download link: https://mindplus.cc/

 

 

Practical Exercise

To enable the Maqueen Lite V5 car to track light, two key tasks must be completed:
First, understand how the light sensors work and read the values from the left and right sensors via the serial port. This helps in recognizing how the sensor data changes under different lighting conditions.
Second, based on the collected light data, write a program with conditional statements that allows the car to automatically adjust its driving direction when it detects a difference in light intensity, thereby tracking the light source.
Task 1: Read Light Sensor Values
Use the serial port to display real-time light intensity readings from both the left and right sensors. Observe how the values change under different lighting conditions.
Task 2: Automatic Light-Tracking Robot
Based on the sensor data, write a program that enables the car to automatically adjust its direction when it detects a light source shift, achieving light-tracking functionality.


Task 1: Read Light Sensor Values

1.Understanding the Light Sensor

The Maqueen Lite V5 is equipped with built-in light sensors on both the left and right sides of its front, acting like the car’s “eyes” that can detect the intensity of surrounding light.
By comparing the light intensity values detected by the two sensors, the robot can determine the direction of the light source.
The position of the light sensors is shown in the figure below:

 

 

1.Programming

(1)Serial Communication Setup
First, initialize the car. Then, use the “serial output string” command to establish a communication bridge between the device and the computer.

 

 

(2)Reading Sensor Values
Next, use the “read light sensor value” command to send the light intensity data from the left and right sensors to the computer, and display them in real time through the serial monitor. Set the data update frequency to once per second.
At this point, an interesting question arises: how can we distinguish between the values collected from the left and right sensors?
The solution is to add identification labels to each sensor’s data. For example, use "L:" as a prefix for the left sensor value and "R:" for the right sensor value. Then, concatenate each label with its corresponding sensor reading into a string. This way, the serial monitor will clearly show which light intensity data comes from the left and which from the right.

 

 

2.Program Execution

Once the program is uploaded to the device, click the“Open Serial Monitor”button to view the real-time data from the left and right sensors displayed on the computer screen.

 


3.Give it a try

Feel free to try placing a light source close to one side of the car’s light sensor. Observe how the data changes as the light intensity varies.


Task 2: Automatic Light-Tracking Robot

1.1.Programming

(1)Flowchart Analysis
The secret behind the light-tracking robot’s smooth movement under light is about to be revealed! Let’s follow the flowchart below to understand its action logic step by step:
- If the left light sensor value is higher than the right by 150 or more, it indicates the light source is on the left side. The car should turn left to approach the light.
- If the right light sensor value is higher than the left by 150 or more, it indicates the light source is on the right side. The car should turn right to approach the light.
- If the difference between the left and right sensor values is less than 150, it means the car is approximately facing the light source. It should continue moving forward without turning.

 

 

(2)Implementing the Light-Tracking Robot
Have you ever wondered how to make the car automatically “chase” a light source like a sunflower? This is where a new programming “partner” comes in—conditional statements.
In the light-tracking project, conditional statements help the car decide which direction to turn based on the difference between the light intensity values from the left and right sensors.

 

 

1. First, complete the initialization. Then, check if the left light sensor value is higher than the right by more than 150. If this condition is true, the car will execute a left turn.

 

 

2.Next, check if the right light sensor value is higher than the left by more than 150. If this condition is true, the car will execute a right turn.

 

 

3.If neither of the above conditions is met, the car will continue moving forward.

 

 

4.Program Execution

After successfully uploading the program, start the car. The car will automatically adjust its direction based on the difference in light sensor values:
- Stronger light on the left: the car turns left;
- Stronger light on the right: the car turns right;
- Balanced light intensity: the car moves straight forward.
By using a flashlight to simulate a light source, you can observe how the car responds to the direction of the light.

 

 

Knowledge Corner

1.Working Principle of the Light Sensor

The light sensor acts like the car’s “eyes,” capable of sensing the intensity of surrounding light. When light shines on the sensor, it outputs an electrical signal proportional to the light intensity.
- The stronger the light, the higher the output signal value.
- The weaker the light, the lower the output signal value.
In this way, the light sensor converts light intensity into electrical signals and sends them to the control system. This helps the car determine the direction of the light source and perform corresponding actions, such as turning or moving forward.
In simple terms, the function of the light sensor is:
Sense light → Convert to electrical signal → Control system receives information → Car executes action.


2.Logic of Conditional Statements for Steering Control

We can imagine the program as a person walking through a maze. Conditional statements are like the signposts the person sees at crossroads. The signposts show certain conditions, such as, “If there’s no obstacle ahead, go straight; if there is an obstacle, turn right.”

 

 

In a program, these conditions are expressed as if statements, such as: “If a variable’s value equals 5, execute this block of code; otherwise, execute another block.”
The steering control logic decides which part of the program to run based on the outcome of these condition checks. It’s like a person choosing which path to take based on signposts they see.
Here’s a real-life example: deciding whether to go out. The condition is: if the weather is sunny, go for a walk in the park; if it’s raining, stay at home and read a book. Here, “sunny” or “rainy” is the condition. Based on the actual weather (the condition’s result), you decide either to go out (execute the “go for a walk” action, like running a block of code) or stay inside (execute the “stay home and read” action, like running another block).
This is exactly how conditional statements control the steering logic in the program.


3.Learning the Commands

 

 

Challenge Yourself

Through this lesson, students have mastered the basic method of using light sensors to track a light source. Next, they can try adding a feature that stops the car when no light is detected. 

icon 2. program.zip 332KB Download(0)
License
All Rights
Reserved
licensBg
0