The sky is blue, the grass is green—colors are everywhere around us. Today, we’re going to grab a color sensor and “catch” some of these beautiful colors to build a fun color-matching game on the UNIHIKER M10. Ready to begin?

Goal
After the game starts, the UNIHIKER screen displays a target color. Within two seconds, use the color sensor to pick a matching color. The UNIHIKER M10 will show whether the selection is correct and update the correct count.

Get to Know
1.Learn how to use TCS34725 color sensor
2.Understand the basic working principle of the color sensor
Materials List

Software:
Mind+ Programming Software x1(download at https://mindplus.cc/en)

Hands-on Practice
The rule of the color-picking game is to identify a target color from the environment within a limited time using the color sensor. How many times can you get it right? Let’s build and experience it together!
Task 1: Pick a Fixed Color
In this task, we will learn how to use the color sensor to detect a fixed color, helping you quickly and accurately determine color categories.
Task 2: Pick a Random Color
Building on Task 1, we will now generate random target color blocks. Your challenge is to pick the correct color within a limited time, with the system keeping track of how many correct attempts you make. Let’s see how many you can get right!
Task 1: Pick a Fixed Color
1.Hardware Connection
Use the 4-pin cable to connect the color sensor to the I²C port on the UNIHIKER M10. After the hardware connection is completed, connect the UNIHIKER M10 to your computer using a USB cable.
Note: The color sensor communicates over I²C. The UNIHIKER has two I²C ports—either one can be used.

2.Software Preparation
Open Mind+ and follow the diagram below to complete the software preparation process.

3.Write a Program
Add the color sensor library:
Click “Extensions” → locate “Color Sensor” in the pinpong library → click to add.

In the color-matching game, we need to read the RGB values from the sensor and compare them with the target color category.
So how do we use the color sensor, and how do we determine color correctness? Let’s begin with the target color Red.
(1) Reading RGB Values
First, learn the basic commands for the sensor:
· Use “Initializes the TCS34725 color sensor I2C address 0x29” to initialize the interface
· Then use “get TCS34725 data once” to obtain raw sensor data. For continuous reading, place this command inside the forever block.
Note: For more information about the color sensor, see the “Knowledge Base”.

To extract RGB values, use:“Parse the TCS34725 color sensor R/G/B turn GAMMA form the data”, Choose R, G, or B to get the respective component.

Now make variables R, G, and B, and print the values using “print” and “join” blocks. Run the program and observe the values in the terminal.

To observe red, place the sensor ~1 cm above a red color patch. Even though ambient light may cause fluctuations, red (R value) will always be higher than green (G) and blue (B). This serves as the rule for determining color.

(2) Determining the Color
Since red has the feature R > G and R > B, we can build a simple check: If R > G and R > B
, then the color picked is correct; otherwise, it is incorrect.

To match the game interface, you may add a red color block on screen and display the result for a short time before clearing it. A full example program is provided below.

4.Run the Program
Click Run. The UNIHIKER M10 displays a red color block. Use the sensor to pick a color: the screen will show whether the picked color is correct.
Note:The color sensor is sensitive to ambient light. Avoid testing on light-emitting surfaces such as the UNIHIKER M10 screen.

5.Have a try
You have learned how to detect red. Now try the same method to detect green and blue. Display the detected color category as text (no need to judge correctness).

Task 2: Pick a Random Color
1.Write a Program
Based on Task 1, we will now generate random colors to complete the full color-matching game.
Before coding, let’s analyze the game flow:
· UNIHIKER generates a random color block
· Sensor detects the color
· Compare results to determine correctness

(1)Generating a Random Color Block
This project uses three colors: Red, Green, Blue. Each color corresponds to a number from 1 to 3.
Thus, use the block “pick random from 1 to 3 integer”. Then, use three if–then blocks to change the color block object.
Store the random number in a variable and make “Generate Random Color” block.

(2) Detecting Color with the Sensor
This part is similar to Task 1, but for easier comparison, convert detected color into a numeric result. Make “Get Color Value” block and related variables.

(3)Comparing Results
Finally, in the main program, we call the two functions—one to get the picked color and the other to generate a random color—and compare the results to check whether the color pick is correct.

Finally, you can add a display for the correct count and clear the color block and result before the next round. A complete sample program is shown below.


2.Run the Program
Click Run. The UNIHIKER displays a random color block. Pick a color with the sensor: If correct → display “✓” and increase the score; If incorrect → display “×”.

Knowledge Base
1.Understanding the Color Sensor
A color sensor measures and compares the RGB values of an object's surface.
This project uses the TCS34725 color sensor, which consists of: a white-LED light source a photodiode array for receiving reflected light.
It is well known that the human eye is most sensitive to the three primary colors—red, green, and blue (RGB). Any visible color can be formed by mixing these three in different ratios. The color we perceive from an object comes from the light reflected off its surface. For instance, grass appears green because it reflects green light when sunlight shines on it.

The color sensor uses a similar principle to capture RGB values. The sunlight shown in the illustration represents the white light produced by the sensor’s LED, which contains all three RGB colors. When this light hits objects of different colors, the surfaces reflect varying proportions of red, green, and blue light.

The reflected RGB light is captured by the sensor’s photodiode array. This array includes red, green, and blue filtered photodiodes, as well as clear (unfiltered) ones. Each photodiode responds to its specific color channel, allowing the sensor to measure the relative amounts of red, green, and blue light and convert them into numerical RGB values.

Since the color sensor identifies colors by detecting reflected light, it is important to use it within the proper sensing distance. For the TCS34725, the recommended working distance is about 3 mm to 1 cm. Keeping the sensor within this range ensures accurate readings and minimizes interference from ambient light. Because lighting can vary across environments, it’s a good idea to test and adjust the sensing distance to achieve the sensitivity you need.
When programming, simply open Extensions and look for the “Color Sensor” blocks in the pinpong library. For more information about the TCS34725, please visit the link below:
https://wiki.dfrobot.com/TCS34725_I2C_Color_Sensor_For_Arduino_SKU__SEN0212

2.Command Overview

Challenge
You’ve already mastered the basics of creating a color-picking game with the color sensor. Up to now, you’ve been picking colors based on the color block shown on the UNIHIKER screen—your eyes can easily tell what to look for. But what if the block itself becomes a distraction and the word on the block becomes the real target? Will your eyes still respond correctly? Try the challenge below:
(1)Add a color name in the middle of the block as the target color category (the text color and block color don’t need to match);

(2)If the picked color matches the color indicated by the text, increase the score; if not, end the game and show a Game Over screen;

(3)Create a start page for your game to make the experience more complete (refer to the sample illustration).










