Lesson 1, Part 3: Color and Distance Sensor

In this lesson, we’ll learn about and use the LEGO Spike Prime Color Sensor and Distance Sensor. You’ll use block coding to train your robot to respond to signals based on color and proximity.

Table of contents

  1. Video
  2. Quiz

Video

Quiz

Which task would require the use of a different sensor than the others? Making the robot stop before it hits a wall. Making the robot follow a black line on the floor. Making the robot beep when your hand gets close. Making the robot stop when it gets near another robot. If your program only has a "when color is yellow" event block and nothing else, what happens when the sensor sees a yellow brick? The program will not work. The robot will do nothing. The hub will show an error. The robot will start moving. What do you change in the "when closer than" block to make the robot do something when an object moves away from it? Change the number. Change the block to "farther than." Change the unit to inches. Add a sound block. Your distance sensor is set to "closer than 20%." If you want the robot to beep when an object is farther away, what should you do? Make the number bigger (e.g., 50%). Make the number smaller (e.g., 5%). Change it to centimeters. Add another "play beep" block. Why can't you use the "when closer than" block to find a red line on the floor? That block is only for measuring how far something is. That block is only for motors. That block needs a "play beep" block to work. You can't use percentages with a color sensor.