1 Project Introduction
In a road of a city, a smart car equipped with "eyes" is driving flexiblyāwhen the traffic lights ahead turn red, it immediately stops smoothly; switching to green, it moves forward briskly; if the yellow light flashes, it slows down gradually, just like a real driver following the rules. This is not a complex large-scale device, but a "smart traffic light recognition" car co-developed by UNIHIKER K10 and HuskyLens 2, which uses lightweight AI technology to realize a complete closed-loop from "seeing signals" to "car controlling".
From "seeing traffic lights" to "controlling the car", this project uses the simplest component combinations to demonstrate the charm of the combination of AI and hardwareāit is not only a small device that can "obey traffic rules", but also a window to open the "AI+traffic" world, allowing creativity to be implemented through touchable interactions and making technology "visible and tangible".
Demo Video
2. Project Implementation Principle
Its core logic is as follows: This project uses the UNIHIKER K10 as the control core. First, it initializes HuskyLens 2 via I2C communication and switches it to the built-in Color Recognition function. The system then enters a loop, continuously requesting HuskyLens 2 for color recognition data. HuskyLens 2 performs real-time detection of color blocks in the image and feeds back the ID of the color block closest to the frame center to the UNIHIKER K10. The UNIHIKER K10 executes corresponding actions based on the obtained ID values: when ID is 1(green), it controls all motors to move forward at a high speed; when ID is 2(yellow), the motors move at medium speed; and when ID is 3(red), the motors stop. The entire process leverages HuskyLens 2's built-in Color Recognition capability to achieve rapid color block detection and ID output, with the UNIHIKER K10 performing logical judgment and peripheral control. This forms a real-time closed loop of "Color Detection - ID Feedback - Action Execution", enabling the carās automatic start/stop function based on traffic light color recognition.

3. Hardware and Software Preparation
3.1 Equipment List
Note: HuskyLens requires Version HuskyLens 2.
Ā
Software: Mind+ Graphical Programming Software
Ā
Ā
3.2 Hardware Connection
Make connections by referring to the diagram below.
Ā

Ā
3.3 Software Preparation
Download and install the Mind+ installation package(Version 2 or above) from the official website. Double-click to open it after installation.
Ā

Ā
Ā
4. Project Making
Ā
4.1 HuskyLens 2
Ā
First, select the protocol type for HuskyLens 2.
Tap System Settings -> Protocol Type -> select I2C communication mode, then return to the main menu interface.
Ā

Ā
Second, swipe the screen to find the "Color Recognition" function.
Ā

Ā
Please follow these steps to learn target colors:
Aim at the specified color to be learned, adjust HuskyLens 2's viewing angle so the "+" in the center of the screen aligns with the target color, then press Button A in its top-right corner to learn this color.
Ā

Ā
Upon completion of learning, if a learned color is detected, HuskyLens 2 will frame the color block with a colored box and display the color name and ID number above it, e.g., "Color:ID1". The default color name is "Color". To learn more colors, repeat this process.
Ā

Ā
For more detailed usage of HuskyLens 2, please refer to the following URL:
https://wiki.dfrobot.com/_SKU_SEN0638_Gravity_HUSKYLENS_2_AI_Camera_Vision_Sensor
Ā
After completing the parameter configuration and mode selection in HuskyLens 2, you can start writing code to implement a traffic light detection car based on color recognition.
Ā
Ā
4.2 Programming
Ā
Open the programming software Mind+, choose "Coding" mode, then click "Upload Mode" to create a new project.
Ā

Ā
Next, add the required extensions in Mind+, including UNIHIKER K10, HuskyLens 2 and expansion board.
Enter the "Extensions" page, switch to "Board" tab, search for "K10", and click "UNIHIKER K10".
Ā



Ā
Load the "HuskyLens 2 AI Camera" and "expansion board" library by the same way from the "Module" page.
Ā


Ā
Ā
Click the "Back" button to return to the programming interface.
Ā

Ā
Click the "Connect Devices", choose your device and "Connect".
Ā




Ā
After the device is successfully connected, write the program as follows:
Ā

Ā
The analysis of the core code is as follows:
Ā

Ā
There is a complete program file for this project in the attachment. (Note: The .mp file is compatible with both Mind+ v1.x (e.g., v1.8.1) and v2.x (e.g., v2.0), while the .mpcode file only works with Mind+ v2.0)
Open Project->Open Local File to load project.
Ā


Ā
Select the project in the attachment and click "Open".
Ā

Ā
Click "Upload" to run the program.
Ā

Ā
Disconnect the UNIHIKER K10 from the computer, and correctly install the UNIHIKER K10 and HuskyLens 2 onto the vehicle frame. Power on the device by toggling the switches in the order shown in the following figure.
Ā

Ā
Note: Please first complete the program upload before installing UNIHIKER K10 onto the vehicle. When installing or removing UNIHIKER K10 on the expansion board, ensure the vehicle power supply is turned off.
Ā
The effect is as follows:
Ā



Ā
Ā
5. Attachment









