In this Lesson Part I, students will use the Color Sensor to make their wheeled robot move more autonomously in order to simulate how an autonomous car might respond to traffic lights. In Part II, the students’ mission is to program your robot to complete a point turn to an exact angle by using the Gyro Sensor.
Program 1: Red Light Detection
- Start the program.
- Start motors B and C (drive forward).
- Wait for the Color Sensor to detect the color red.
- Stop the motors.
Program 2: Turn your robot clockwise for 45 degrees
Rotating using a wheel is not very precise. If you try to turn your robot in the dust or on a slippery surface, it may not reach the right angle. What the Gyro Sensor does is to help you make much more precise movements.
- Move Tank
- Wait – Gyro Sensor – Compare Angle – Type [3] (Greater Than or Equal), Degrees [45]
- Move Tank – Off
Program 3: Red and Green Light Detection Loop
The “Loop” block will be used.
- Start the program.
- Start motors B and C (drive forward).
- Wait for the Color Sensor to detect the color red.
- Stop the motors.
- Wait for the Color Sensor to detect the color green.
- Repeat steps 2 to 5 forever.
Program 4: Line Following in Loop (Optional)
The students will create an automated, driverless vehicle that can follow a line. They will explore how an automated vehicle might be guided along a road or track. The “switch” block will be used, which works very similar to the “time” block who can control almost all sensors. The program will work best using black or blue tape on a very light (or white) surface.
- Start the program.
- Start motors B and C (drive forward with a curve toward the line).
- Wait for the Color Sensor to detect the color black.
- Start motors B and C (drive forward with a curve away from the line).
- Wait for the Color Sensor to detect the color white.
- Repeat steps 2 to 5 forever.