AI with ZOOM:BIT: Color Detection

AI with ZOOM:BIT: Color Detection

In this tutorial, we'll use the traffic light system to control the movements of ZOOM:BIT.

 

Video Tutorial

 

 

How Does This Project Work?

 

We'll teach ZOOM:BIT to recognize three different colors—green, yellow, and red—just like a traffic light.

 

 

Based on the color it detects, ZOOM:BIT will perform different actions. If it sees green, it will go forward.

 

 

If it sees yellow, it will slow down.

 

 

And if it sees red, it will stop.

 

 

Building the Code

 

Firstly, we'll need to add ZOOM:BIT and Huskylens extensions in MakeCode Editor. Once they are ready, we can jump into building the code.

You can view and download the complete code from here.

 

 

What the Code Does?

 

The code starts by setting up Huskylens for color recognition and clears all RGB pixels.

 

 

When you press Button A, ZOOM:BIT learns the green color as ID 1. The RGB pixels light up in green for 1 second to confirm.

 

 

In the same way, pressing Button B teaches ZOOM:BIT the yellow color as ID 2, and the RGB pixels light up in yellow for 1 second.

 

 

Pressing both Button A and Button B together sets the red color as ID 3, lighting up the RGB pixels in red for 1 second.

 

 

Pressing the logo clears all learned colors and turns off the RGB pixels.

 

 

Inside the Forever loop, ZOOM:BIT continuously checks for recognized colors. If it sees green that was assigned to (ID 1), the RGB pixels light up in green, and ZOOM:BIT moves forward at a speed of 160.

 

 

For yellow (ID 2), the RGB pixels light up in yellow, and ZOOM:BIT moves forward at a slower speed of 80.

 

 

If it sees red (ID 3), the RGB pixels light up in red, and ZOOM:BIT stops by braking.

 

 

If no colors are recognized, ZOOM:BIT stops and turns off the RGB pixels.

 

 

Project Complete

Well done on completing the third project of ZOOM:BIT & Huskylens! We've now seen how ZOOM:BIT can use color detection to respond to traffic light signals. Next, we'll learn about tag recognition.

Hardware Components

ZOOM:BIT Robot Car Kit for micro:bit

$37.25++ $47.50++ $37.25

x 1 unit(s)