0% found this document useful (0 votes)
21 views

Unit 03 Tutorial 3 Sensors Touch

Uploaded by

brendsriverasy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Unit 03 Tutorial 3 Sensors Touch

Uploaded by

brendsriverasy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Unit 03 Tutorial 3: Sensors: Touch Sensor

Brighton H.S Engineering


By: Matthew Jourden

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

Loop Name: Touch

Types of ways to control a how


many times a loop may run.
Default is Infinite
4. Go to the Sensors Tab (Yellow) > Drag and Drop the Touch Sensor inside the loop.
We will start with the Touch Sensor before turning on the motors so the machine will not try to move before
the sensors has time to work.

Port # on the EV3 Brick.


Be sure to that the wire is
in the correct port or
change the number here
to the numbered port on
your EV3 Brick

Options for Sensor Display

Measure: Touch Sensor is


Pressed or Released

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

Changed to Text > Connect Sensor Logic


Pixels to Text.

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

Set as Touch Sensor > State > 1


(Pressed)

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.

1. Add the following move commands to your program

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

Reads Counter then adds 1 to Counter and


sets Counter to the new value Reads Counter compares
Counter to see if Counter is
>= to 5. This value gets
passed to the end of the
loop to see if True or False

False: Continues the loop

True: Exits the Loop and


stops motors
3. Notice the program ends immeditly after the touch sensor is pressed.
Result is the loop is occuring so fast that the adding one to the counter gets to 5 faster than a person could release.

Add the following to get the program to last longer


1. True Side of Switch: After sensor is pressed
a. Stop the Motor (Currently in the program)
b. Wait 1 Second
c. Reverese the motors for .5 second.
d. Stop the motors
e. Reset Counter Back to 0 (Zero)
2. False Side:
a. Add a Wait Statement of .25 seconds after Move Forward Commands

Test the New program and see what happens.

You might also like