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:

Touch Sensor

touch

-> The touch sensor in EV3 is a small device that detects physical contact, like when you push a button.

-> The touch sensor helping robots interact with the world around them and making them smarter and safer!

A way to know if touch sensor is pressed or released:

ev3-connected-touch

If it shows zero (0), it's released.

If it shows one (1), it's pressed.

Wait until "Pressed"->Start

Touch-Wait-Until
1TouchSensor

1- Press

2- Robot begin moving

1-wait-until-pressed-move

1- Wait [robot don't do anything] Until [Touch sensor is "pressed"]

2- Robot moves BACKWARD for 500 degrees at the speed of 20%.


Wait until "Pressed"->Stop

Touch-Wait-Until
2TouchSensor

Notice that it does the opposite from the last one

1- Robot "start moving"

2- stop when sensor is "pressed"

2-wait-until-pressed-stop

1- Wait [wheels move backward at speed of 20% repeatedly] Until [touch sensor is "pressed"]

2- Stop moving.


"set movement motors" block above the "movement" block

3-1-repeat-until-pressed

Notice that there are 2 "set movement motor" blocks

Robot moving:

This is the "set movement motor"

set-movement

For Repeat Until "pressed"

Touch-Repeat-until
Speed up x4 (3)

⬅️ These 2 codes are the same ➡️

It's better to put one of this pink block AT THE BEGINNING


"set movement motor" at the beginning

3-repeat-until-pressed

This is much more simple (that's what programmers do, make the codes more simple).

1- Repeat [Robot make a big turn toward left]

2- Until [Touch sensor is "pressed"]

3- Robot moves forward for 400 degrees at the speed of 50%.

Repeat Until Touch sensor is "Pressed"

4TouchSensor

1- Repeat Robot moves backward forever at the speed of 40%

2- Until [Touch sensor is "pressed"]

3- Must add the "stop moving" since we put "start moving" block

4- Move forward for 150 degrees at speed of 30%

5- Make a left spin turn of 300 degrees at the speed of 30%.

6- Move forward for 300 degrees at speed of 30%. Toward the yellow container

7- Motor A move clockwise (up) 200 degrees at the speed of 20%

4-repeat-until-pressed-challenge

Purpose: Robot lift the yellow container


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

Time for a quiz!

Question goes here

Challenge for you

touchSensor-you

Hint:

-> Use "forever" loop

-> The degree I used it's 150. The speed is 50%.

-> Don't use too much degree, or the motor might be stuck.

5-you-touch

1- When touch sensor is [pressed], motor A go 150 degrees clockwise (up).

2- When touch sensor is [released], motor A go 150 degrees counterclockwise (down).

-> Notice that I need wait until block. But you can explore and use loops inside loop (I might talk about this later on).