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!

Add the Touch sensor to the robot by:

IMG-2017

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
touch (1)

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
touch (2)

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
touch (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%.


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

Time for a quiz!

Question goes here

Challenge for you

touch

Hint:

-> Use "forever" loop

-> 1st: use counter-clockwise

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

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

TOUCH-CHALLENGE-YOU

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

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

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