Sensors

Sensors in EV3 are very important because they help the robot "see" and "feel" its surroundings in order for EV3 to make smart decisions based on what it senses.

There are 5 type of sensors:

Color Sensor

The robot can read 8 colors (including "No color")

-> Detecting Objects: help EV3 detect objects of different colors.

-> Making Decisions: With the color sensor, EV3 can make decisions based on colors. For example, it can stop when it sees a red stop sign or move forward when it sees a green light.

-> Following Lines: use the color sensor to follow lines on the ground.

A way to know what color the sensor is reading:

ev3-connected-color

-> You can look at the color sensor displayed in your computer/laptop/ipad once you connected the robot.

-> As you can see, every motor and sensor is displayed when the ev3 brick has a green dot.

Shapes of color input

color-hexagon color-circle color-rectangle

You can find 3 type of shapes for the sensors.

-> The hexagon shape it's for loops (you use it for "control" blocks)

-> The circle it's operators (we are going to see "operators" soon!)

-> The rectangle it's an entire block just like the "Movement" and "Motors"

If "yellow"

yellow
1ColorSensor

Notice that the yellow container is there when the program starts.

1-Color-if-Yellow

If [color sensor read "yellow"] Then [motor A moves 200 degrees clockwise (up) at the speed of 50%]


Repeat Until "Blue"

blue
Sensor-blue

This video/gif it's in x2 speed.

2-Color-Blue-Repeat-Until

1- Repeat [wheels move straight (forward) at speed of 20% repeatedly] Until [color sensor read "blue"]

2- Condition is met. Stop moving.


Wait Until "Black"

black
wait-until-blue

Notice that robot turns forever until the condition it's met.

3-color-Black-wait-Until

1- Robot Wait [Wheels start moving 60 degrees left (since it's negative speed)]Until [color sensor read "black"]

2- Condition is met. Stop moving.

3- "Stop and Exit program"


If-Else "No color"

NoColor
Any color

Notice that robot make 2 type of desicions.

4-color-no-Color-If-Else

-> If [color sensor reads "No color"] Then [wheels move 600 degrees FORWARD at the speed of 50%]

-> Else [color sensor reads "any color" (in this case "red")] Then [wheels move 600 degrees BACKWARD at the speed of 50%]

-> Condition is met. Stop moving.


Key-Takeaways: Why is color sensor important for programming?

Time for a quiz!

Question goes here

Challenge for you: Red Green Light

5-1-Color-you
sensor-color-you

Hint:

-> Once sensor read "green": go backward speed of 40%

-> Once senor read "yellow": go backward speed of 15%

-> Once sensor read "red": robot stop moving

Hint 2:

There's no set degree, meaning that robot go backward forever until a condition it's met.

5-Color-you

Notice that you need to "start moving" blocks instead of "move for" blocks.

I tried "wait until" block. But you can also use "color sensor" rectangle block.

If you don't understand, go back to review control.