PRIME LESSONS
By the Makers of EV3Lessons
INTRODUCTION TO COLOR SENSOR
BY SANJAY AND ARVIND SESHAN
This lesson uses SPIKE 3 software
LESSON OBJECTIVES
¢ Learn how to use the Color Sensor
¢ Learn how to use the Wait Until Block
¢ Note: Although images in this lessons may show a SPIKE Prime, the code blocks are the
same for Robot Inventor
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 2
WHAT IS A COLOR SENSOR?
¢ In the software, the sensor can detect
Detectable Colors
color or reflectivity Black (0)
Violet (1)
¢ Unlike the EV3, reflectivity is with white Blue (3)
light, not a red light. Light Blue (4)
Green (5)
¢ The sensor can detect 8 colors and no Yellow (7)
color (what those colors are vary Red (9)
between SPIKE Prime and Robot White (10)
No Color (-1)
Inventor)
¢ Optimal reading distance according to the Detectable Colors
specs: 16 mm (depending on object size, Black (0)
color, and surface) Violet (1)
Blue (3)
Teal (4)
Green (5)
¢ Note: In Robot Inventor, the light blue Yellow (7)
color is replaced with teal Red (9)
White (10)
No Color (-1)
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 3
NOTE: ADB AND SENSING COLOR
¢ The color sensor on ADB (Advanced Driving Base
in SPIKE Prime) is mounted at about 8mm off the
ground, but the optimal distance for mounting the
sensor according to the specs is 16mm.
¢ When using this robot design, Black does not
read correctly in Color Mode using electrical
tape lines or a FIRST LEGO League challenge
mat.
¢ See the next slide for modifications. The build
16mm
instructions are also provided as a separate
2M (2 LEGO Modules)
file on our site.
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 4
MODIFICATIONS TO ADB
¢ Build instructions for modifying the front bumper of ADB so that the color sensors are
raised one LEGO module up are included on this website
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 5
HOW DO YOU PROGRAM WITH A COLOR SENSOR?
¢ The two modes you can program the color sensor in: Color Mode and Reflected light
mode
¢ We will use color mode in this lesson
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 6
CHALLENGE 1
¢ Program your robot to move forward until the color sensor sees black
¢ You will need to use the Wait For block and the Boolean block of the color sensor
¢ Basic steps:
¢ Set the movement motors for your robot (A and E for Droid Bot IV and ADB robot)
¢ Set the movement speed for your robot
¢ Start moving forward
¢ Use the wait until block to detect when the color sensor sees black
¢ Stop moving
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 7
CHALLENGE 1: SOLUTION
In previous lessons, you learnt how to configure your robot. The first set of blocks sets
the movement motors and speed. (See Configuring Your Robot Lesson)
Note: 50% is the default speed so
the set movement speed block can be
omitted in this case. It is provided so
you can adjust the speed as needed.
Configure robot
Start moving
Wait until the color sensor sees black
Stop moving
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 8
CREDITS
¢ This lesson was created by Sanjay Seshan and Arvind Seshan for Prime Lessons
¢ More lessons are available at [Link]
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
License.
Copyright © 2023 Prime Lessons ([Link]) CC-BY-NC-SA. (Last edit: 5/12/2023) 9