Discover our
resources
Activity: Color detection
This activity explores how a color sensor works with the LEGO Spike robot, and howartificial intelligence can learn to recognize and react to specific colors, via a process called supervised learning.
Students will build a simple tri-object, train an AI model, and observe how it can operate autonomously.
🧩 Activity objectives
- Understand how a color sensor works.
- Train an AI model to react to specific colors.
- Experiment with generalization: what happens if a color has not been seen during learning?
- Discover the limits and strengths of machine learning in a real-life context.
🛠️ Materials required
- 1 LEGO Spike Prime set per group of 2 to 3 students.
- Computer with AlphAI software installed.
- Objects in different colors (ideally LEGO bricks and non-LEGO objects).
🚀 Activity steps
- Configuring the color sensor
- In AlphAI, go to the "Sensors" tab , select "Color sensor", then choose "LEGO bricks - 9 colors".
- Testing color recognition
- Pass different bricks under the sensor to see which are correctly recognized.
- Discuss the limits: some close nuances are sometimes misinterpreted.
- Define actions associated with colors
- In the "Actions" tab , select simple actions (sounds, emoticons, movements).
- Assign one action for each color detected.
- Training the model
- Activate "Learning" mode .
- Show the sensor a color, then click on the action to associate.
- Repeat for each color. The training data counter increases with each example.
- Test stand-alone mode
- Click on the "Stand-alone" button.
- The robot then automatically executes the action corresponding to the detected color, based on what it has learned.
- Testing generalization
- Try a color not used for training (e.g. orange if only red has been trained). The robot then chooses the closest action.
🧹 Data cleansing
Training data can be reviewed:
- Delete mislabeled data.
- Observe the impact of biased or too little data.
This highlights the importance of a clean, balanced dataset in any AI project.
🌈 Advanced mode: RGB detection
To go one step further, activate the "RGB " mode in the sensor tab:
- The sensor no longer identifies fixed colors, but reads Red, Green and Blue values (between 0 and 255).
- This makes it possible to detect non-LEGO objects in a wider range of colors.
Students can then train new behaviors based on the RGB reading, making sorting more realistic for everyday objects.
🧠 Summary
This activity highlights :
- The foundations ofsupervised learning.
- The importance of training data in the performance of an AI model.
- Practical applications of AI in simple but realistic scenarios (waste sorting, visual recognition, etc.).