[![EV3 robot with color sensor](/static/coding/line-detection/ev3-robot-color-sensor-down.jpg)](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-color-sensor-down-driving-base-d30ed30610c3d6647d56e17bc64cf6e2.pdf)
[![IMAGE: Color Squares](/static/coding/line-detection/ev3-color-squares.jpg)](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20squares-0a88dfd98bb2e64b5b8151fc422bae36.pdf)
Autonomous cars need to recognize and respond to traffic lights automatically. Create a program that will make your robot stop at red lights. Make sure your robot is only responding to the color red. Once you have succeeded, program your robot to drive forward again when the light changes from red to green.
Before you program, think about:
* How will you program the robot to detect a color?
* How will you program the robot to stop at a color?
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
## Contemplate
To simulate what could happen if a driver falls asleep while driving, your robot could sound an alarm signal when it crosses the line. This feature is often available in new cars.
Program your robot to perform this function.
Draw a dark line with tape or marker for your robot to cross.
### ~hint
Consider using these blocks in your solution:
```block
motors.largeBC.steer(0, 50)
music.playSoundEffect(sounds.systemGeneralAlert)
```
### ~
### Sample Solution - Line detection in a loop
1. Start motors ``B`` and ``C`` (drive forward with a curve toward the line).
2. Wait for the color sensor to detect the color black.
Program your robot to drive on “autopilot” along a given route. You will need to create a program that recognizes and responds to a dark line (or white line). You will create a line-following program and your robot will need to travel along the line without losing contact with it.
You will need to constantly debug your program in order to make your robot travel as smoothly as possible along the line.
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
### Share
Think about:
* What challenged you?
* Were there any surprises?
* How can you improve your program?
* Can your program be more streamlined? Have you used too many blocks?
* Is there a more efficient way to build your program?
* How can your program be used in real-world scenarios?
Personalize:
* Click on the **JavaScript** tab and experiment with changing the values in the code.
* Add a custom image or sounds from the ``||brick:Brick||`` or ``||music:Music||`` menus.
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.