Unit 03 Tutorial 3 Sensors Touch
Unit 03 Tutorial 3 Sensors Touch
Robots have a variety of sensors that help the machine sense the world around it. We will be looking at four different
types of sensors
a. Touch Sensor: uses a pressure switch that is attached to the robot and will carry out a command set when
depressed by an obstacle. (I.E Moving robot sensors depresses when a wall to a maze comes in contact with it
and the robot will stop)
b. Ultrasonic Sensor: uses sounds waves to determine what is front of a robot; similar to radar
c. Color Sensor: uses light refraction to sense colors to carry out a series of commands. (I.E having a movable
robot follow a path or have a robotic arm sort colored objects)
d. Acceleration/Tilt Sensor: Supplies data on how fast a robot is moving or if the robot on an even axis
e. Gyro: Compares angles or rate of the sensor
1. Add the Touch Sensor to Lego Base Robot. See Build Manual in the Lego Core Set Kit for details or Build
Instructions Touch Sensor File on Website
2. Open Lego Mindstorms Education EV3 programming software > Start a New Program > Save Program > Name
Tutorial3 Sensor Touch
3. Typically a looped program will need to be used in order for the program use the sensor multiple times
a. Drag from the Flow Tab (Orange) > Loop code block and attach to start command
Compare: Allows
user choose between
Released, Pressed or
Bumped
5. Go to Action Tab (Green) > Drag and Drop Display code block to the right of the Sensor display
Display Type
1. Wired: From Sensor
2. Project Images
3. Lego Images
Type of Output
1. Text
Options Based on Type
2. Shapes
of Output
3. Image
4. Reset Screen
6. Change the Display Features as follows and Drag the Logic Statement from the Touch Sensor code block to the
Text Option on the Display Code Block.
Changed to Wired
7. Upload Program to the EV3 Brick > Test Program by pressing on the Touch Sensor. The Screen on the EV3
should display a 0 or 1 (0 not pressed, 1 pressed). Logic statements will only produce numbers so that the
data gathered could be used in other mathematical formulas to make your robot do certain things.
8. Note we can check the same data by turning on the robot. Navigate to Port View on the Lego Brick > Select
the port the ultrasonic sensor is linked too. You can change the units by pressing the center button to change
the units.
Making the Robot Move: Touch Sensor
9. Delete the Touch Sensor and Display from in the Loop (DO NOT DELETE THE LOOP) > Go to Flow Tab (Orange)
> Drag the Switch code Block and place it in the loop > Set Switch to Touch Sensor-Compare-State
Switch Code Block is an If/Then or True/False Statement that can be controlled in a number of ways from
sensor readings to mathematical data. The top half (Check Mark) is the True side of the statement and the
bottom half (X Mark) is the False side of the statement.
True Side of
the Statement
False Side of
Choose how you want the If the Statement
Statement to read using a
variety of options
0. Released
1. Pressed
2. Bumped
10. Go to Flow Tab (Orange) > Place in the loop as the first code block > Place the Touch Sensor and Display in the
True and False part of the Switch. See Below
NOTE: This will be the base program for your Programming Assignment
Port Number
Compare States
0. Released
1. Pressed
2. Bumped
Set as 1 (Pressed)
11. Upload and Run the Program. Play with the sensor to see it works. Note this program is in an infinite loop so
you will need to manually stop the program by pressing the Grey Button (Top Left Corner) on the EV3 Brick to
cancel the program.
12. Assignment: Printout before the Touch Value the following word(s). NOTE the value 0 or 1 will come from the
sensor. (Hint: use x and y coordinates to move the sensor value up/down or left/right
a. Released = 0
b. Pressed = 1
Stops program
Variable Creation
In this section we will create a variable that we will use to exit the loop.
2. Creating a variable
a. Click on Data Operations (Red Tab) > Click on Variable Icon (looks like a suitcase)
b. Select White Box in Top right corner > Click on Add Variable > call it COUNTER > Ok
Variables can either be read or written
Read: Allows user to use the value the variable currently equals. Read Icon looks like an open book.
Write: Allows the user to assign or overwrite a value to that variable. Write icon looks like a pencil
c. Place Counter Variable in the following locations along with the mathematical formulas
d. Upload program and test settings
Turns Off
Motors
Set
Counter
to 0