The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by eng.hd10, 2019-03-23 16:46:22

Ev3 Programming2

Ev3 Programming2

SWITCH BLOCK CHALLENGE 1

Challenge: Write a program 51
that changes the display
based on if the touch sensor
is pressed or not pressed.

If pressed, your EV3 is
happy! Display a smiley
face. If not pressed, the EV3
is sad! Display a sad face.

Hint: You will need to use
the display block, loops and
switch blocks!

© EV3Lessons.com, 2015, (Last edit: 2/26/2015)

CHALLENGE 1 SOLUTION

Display Block

Touch Wait Block
Sensor
Selected

Loop Display Block

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 52

SWITCH BLOCK CHALLENGE 2

Can you write a program that display big
eyeballs if you touch it once and a sad
face if you touch it a second time and
toggles back and forth.

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 53

CHALLENGE 2 SOLUTION

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 54

BEGINNER EV3
PROGRAMMING

LESSON

Topics Covered:
Touch Sensor

LESSON OBJECTIVES

1. Learn how to use the Touch Sensor
2. Learn how to use the Wait For Block
3. Learn the difference between the Wait For Block and the

Sensor Blocks
4. Learn when to use Move Block’s “On” mode

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 56

WHAT IS A SENSOR?

• A sensor lets an EV3 program measure and collect data about
is surroundings

• The EV3 sensors include:

• Color – measures color and darkness
• Gyro – measures rotation of robot
• Ultrasonic – measures distance to nearby surfaces
• Touch – measures contact with surface
• Infrared – measures IR remote’s signals

Image from: http://www.ucalgary.ca/IOSTEM/files/IOSTEM/media_crop/44/public/sensors.jpg 57
© EV3Lessons.com, 2015, (Last edit: 11/01/15)

WHAT IS A TOUCH SENSOR? 58

• Touch Sensor can detect when the sensor’s red button
has been pressed or released

• With this information, you can program an action when
the sensor is:
Currently Pressed
Currently Released
Pressed and Released Just Before (Bumped)

• When might you use this sensor?
• Useful for programming “moving until touch sensor
is pressed/released/bumped”
• For example, if you put a touch sensor on the front
the robot, you can have it stop moving if it runs
into something.
• You can also have your program start or stop
when a touch sensor is pressed.

© EV3Lessons.com, 2015, (Last edit: 11/01/15)

WHAT DOES “BUMPED” MEAN?*

The sensor basically is like a True/False switch
“Bumped” can be tricky. What conditions must be there for the sensor to
read True for Bumped?

Time Action Pressed Released Bumped
False True False
1 Button starts released True False False
False True True
2 Button is pressed in False True False

3 Button is released, and program reads sensor True

4 Button is still released, and the program tests the False
Touch Sensor again
False
5 Button is pressed a second time False False

6 Button is released, but the program does not
read the sensor

200 secs Program reads sensor True True
later… True False

201 Button is still released, and the program tests the
Touch Sensor again

* Based on the Lego EV3 help screen

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 59

HOW DO YOU PROGRAM WITH THE
TOUCH SENSOR?

There is a Touch Sensor Block in the Yellow Tab, but there is a
Wait for Touch in the Orange Tab. What is the difference!!????!

Yellow Sensor Tab: Orange Flow Tab:
Sensor Blocks Wait for Block

• Used to Read • Used to wait
and Compare for a sensor
Sensor Values reading (or
time)

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 60

MOVE ON AND OFF

What would happen if you placed a Move
Steering Block and left the motor “On”?

Would the robot…

1) Move?

2) Move for a little while?

3) Not move at all?

ANS. Not move at all. Rookie Tip: Motor On needs
to be followed by another
block (e.g. Wait Block)

What does Motor Off do?

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 61

CHALLENGE 1

Program your robot to 0 = released
move straight until you 1 = pressed
tap the sensor with your 2 = bumped
hand.

B

Hint: You will combine: Move
C Steering + Wait Block

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 62

CHALLENGE 1 SOLUTION

Add screenshot

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 63

CHALLENGE 2 0 = released
1 = pressed
Program your robot to 2 = bumped
move until it hits the
edge of a wall. Then
back up and turn right
90 degrees.

B

C Hint: You will combine Move
Steering + Turning + Wait
© EV3Lessons.com, 2015, (Last edit: 11/01/15)
Block

64

CHALLENGE 2 SOLUTION

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 65

DISCUSSION

Why did you use MOTOR ON for these challenges?
You want to read the sensor while the motor is on.

Why do we use the WAIT FOR BLOCK in these challenges?
We need to program to wait for the correct reading

What is the difference between PRESSED, RELEASED and
BUMPED?

PRESSED = pushed in, RELEASED = not pushed,
BUMPED = pressed and released recently

What are some situations you might want to use each of these
for?

PRESSED = running into a wall, BUMPED = tapped by hand
RELEASED = no longer touching a wall

© EV3Lessons.com, 2015, (Last edit: 11/01/15) 66

BEGINNER EV3
PROGRAMMING

LESSON

Topics Covered:
Turning

LESSON OBJECTIVES

1. Learn to turn the robot a desired number of degrees
2. Learn the differences between Spin and Pivot Turns
3. Learn how to program two different type of turns
4. Learn to write pseudocode

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 68

PIVOT VS. SPIN TURNS

180 Degree Pivot Turn

B End Position Notice where the robot
ends in both pictures
C Motor C after a 180 degree turn.
Start Position B Moves
In the Spin Turn, the
B robot moves a lot less
and that makes Spin
180 Degree Spin Turn Turns are great for tight
positions. Spin turns tend
Start Position End Position to be a bit faster but also
B C a little less accurate.

C Motors B So when you need to
B and C make turns, you should
decide which turn is best
Move for you!

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 69

HOW TO MAKE PIVOT AND SPIN
TURNS

Steering Value

50 -50 100 -100
B B B B

C C CC
Pivot Turn Right Pivot Turn Left Spin Turn Right Spin Turn Left

Move Steering 70
Block

Change Steering value here

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015)

MAKING A PIVOT TURN FOR 90
DEGREES

B?

C
B
C

Program your robot to turn 90 degrees....Does the 71
robot actually turn 90 degrees if you just pick 90
degrees for distance? Ans. NO! Solution on next

page

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015)

HOW DO YOU MAKE THE ROBOT
TURN 90 DEGREES?

Ans. Try using the port view to measure
the turn and then input the correct
number of degrees.

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 72

TEACHER INSTRUCTIONS

• Split up class into groups as need.
• Give each team a copy of the Turning Challenge Worksheet.
• Challenge Details are on Slide 8
• Discussion Page Slide 9
• Challenge Solution on Slide 10

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 73

TURNING CHALLENGES

Challenge 1 Challenge 2
• Your robot is a baseball player
• Your robot baseball player must
who has to run to all the bases run to second base, turn
and go back to home plate. around and come back to first.
• Can you program your robot to
move forward and then turn left? • Go straight. Turn 180 degrees
• Use a square box or tape and return to the same spot.

Second
Base

B
C

Start and First
End Base
position

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 74

CLASS DISCUSSION GUIDE

Did you try PIVOT and SPIN turns? What did you discover?

Pivot turns were fine for Challenge 1, but for Challenge 2, if we used
Pivot turns, we were farther away from the base.
What situations would one work better than the other?

Spin turns are better for tight turns (places where there is not enough
space) and you stay closer to your original position.
What is PSEUDOCODE? Why do you think programmers find it
useful? (pseudocode is from the worksheet)

Pseudocode allows programmers to write out their code in plain
English before you code in a programming language. It lets you plan
and think before you sit down to code. It lets you share your ideas
with others you are working with in a common language.

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 75

CHALLENGE SOLUTIONS

Challenge 1 Challenge 2

You probably used a You probably used a spin turn
combination of move steering to because it is better for tighter turns
go straight and do pivot turns to and gets you closer to the starting
go around the box. point!

Second
Base

B
C

Start and First
End Base
position

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015) 76

TURNING AN ATTACHMENT
ARM, NOT JUST THE WHEELS

• Attach a medium motor to Port A Medium Motor Block
or a large motor to Port D as Large Motor Block
needed.
77
• Move Steering vs. Motor Block

• For moving your wheels you
should use a Move Steering
Block that syncs both wheel
motors (see intermediate lesson
called Move Blocks to learn about
sync)

• For moving your attachment your
arm, you use either a Medium
Motor Block or a Large Motor
Block because you don’t need to
sync your motors.

Copyright © EV3Lessons.com 2014 (Last edit: 2/26/2015)

BEGINNER EV3
PROGRAMMING

LESSON

Topics Covered:
Ultrasonic Sensor

LESSON OBJECTIVES

1. Learn about the Ultrasonic Sensor
2. Learn how to use Wait Until Ultrasonic Block
3. Learn the difference between the Wait Until Ultrasonic Block

and the Ultrasonic Block

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 79

WHAT IS A SENSOR?

• A sensor lets an EV3 program measure and collect data about
is surroundings

• The EV3 sensors include: Our lessons will
• Color – measures color and darkness cover the 4
sensors in green.

• Gyro – measures rotation of robot

• Ultrasonic – measures distance to nearby surfaces

• Touch – measures contact with surface

• Infrared – measures IR remote’s signals

Image from: http://www.ucalgary.ca/IOSTEM/files/IOSTEM/media_crop/44/public/sensors.jpg 80
© EV3Lessons.com, 2015, (Last edit: 2/26/15)

ULTRASONIC

• An ultrasonic sensor measures distance.

• You use it when you need to make sure you are a certain distance
away from a target.

• The distance can be measured in inches or centimeters.

• To read the ultrasonic sensor, you use the Ultrasonic Block. To use
the ultrasonic to do an action until a distance, you use “Wait Until”

Read Ultrasonic VS. Wait for Ultrasonic

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 81

ULTRASONIC CHALLENGE 1

Challenge: Make the robot move
until it is 5 inches away from the
wall.

Step 1: Make a new program

Step 2: Set move to “on”

Step 3: Set wait block to use the
Ultrasonic

Step 4: Set move block to “off”

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 82

CHALLENGE 1 SOLUTION

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 83

CHALLENGE 2: DOG FOLLOWER

If the robot is closer than 5
inches away from your hand
move backward, otherwise
move forward.

Step 1: Drag a loop from the
orange tab

Step 2: Drag switch inside loop

Step 3: Set switch to Ultrasonic

Step 4: Set move steering block
to ON and place in TRUE

Step 4: Set move steering block
to OFF and place in FALSE

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 84

CHALLENGE 2 SOLUTION

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 85

ROBOTS CAN FOLLOW YOU &
EVEN DANCE WITH THIS CODE!

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 86

BETTER DOG FOLLOWER:

The previous dog follower kept the robot moving always. This
version lets the “dog” rest if it is between 4-6 inches.

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 87

BEGINNER EV3
PROGRAMMING

LESSON

Topics Covered:
Color Sensor

LESSON OBJECTIVES

1. Learn how to use the Color Sensor
2. Learn about Coast and Brake

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 89

WHAT IS A SENSOR?

• A sensor lets an EV3 program measure and collect data about
is surroundings

• The EV3 sensors include: Our lessons will
• Color – measures color and darkness cover the 4
sensors in green.

• Gyro – measures rotation of robot

• Ultrasonic – measures distance to nearby surfaces

• Touch – measures contact with surface

• Infrared – measures IR remote’s signals

Image from: http://www.ucalgary.ca/IOSTEM/files/IOSTEM/media_crop/44/public/sensors.jpg 90
© EV3Lessons.com, 2015, (Last edit: 2/26/15)

WHAT IS THE COLOR SENSOR?

• What are they? Sensors that detect the intensity of light that enters it

• Three modes: Color, Reflected Light Intensity and Ambient Light
Intensity

• Color Mode: Recognizes 7 colors (black, brown, blue, green,
yellow, red, white) and No Color

• Reflected Light: Measures the intensity of the light reflected back
from a lamp that emits a red light. (0=very dark and 100=very light)

• Ambient Light: Measures the strength of the light that enters the
sensor from the environment. (0=very dark and 100=very light)

• USES: 91
• Move until a line
• Follow a line

We will use COLOR MODE in this Lesson

© EV3Lessons.com, 2015, (Last edit: 2/26/2015)

ANOTHER MOVE STEERING TIP:
COAST OR BRAKE?

• Something more about the Move Steering
Block

• You will notice you have an option to COAST
or BRAKE

• Coast will make the motors keep moving.
Brake makes the motors stop immediately.

• Which do you use to stop EXACTLY on a
colored line?

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 92

COLOR SENSOR CHALLENGE

Make the robot move up to
a green line using the color
sensor?
Step 1: Use Wait For Color
Step 2: Use the color
sensor in COLOR MODE
Step 3: Coast or Brake?

Hint: You will use Move
Steering (think about motor
on and off) and Wait for
“Color”

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 93

COLOR SENSOR CHALLENGE
SOLUTION

FINISH

Move Steering Move Steering
Set to “ON” Set to “OFF”
with BRAKE

Wait until Color is Green (#3) START
94
© EV3Lessons.com, 2015, (Last edit: 2/26/2015)

DISCUSSION GUIDE

Can you look for more than one color with the color sensor?

Answer: Yes

What is the difference between
COAST and BRAKE in a Move Steering Block?

Ans. Coast will allow your motors to
spin freely after a move, but Brake will
Immediately stop it

© EV3Lessons.com, 2015, (Last edit: 2/26/2015) 95

BEGINNER
PROGRAMMING

LESSON

Basic Line Follower

LESSON OBJECTIVES

1. Learn how humans and robots follow lines
2. Learn how to get a robot to follow a line using Color Mode on

the EV3 Color Sensor
3. Learn how to follow a line until a sensor is activated
4. Learn how to follow a line for a particular distance
5. Learn how to combine sensors, loops and switches

© 2015 EV3Lessons.com (Last edit: 2/28/2015) 97

TEACHER INSTRUCTIONS

• Slides 4-7 are animated. For students to better understand how a
line follower works and how a human and a robot follow a line, we
recommend that you play the animation

• Give each student/team a copy of the worksheet.
• Challenge 1 begins on slide 10 and Challenge 2 on Slide 13
• Discussion Guide is on Slide 16
• More advanced students might be interested in other line followers

on EV3Lessons.com

© 2015 EV3Lessons.com (Last edit: 2/28/2015) 98

FOLLOW THE MIDDLE? 99

Humans want to follow the line in the
middle.
Let’s have the robot do the same thing
using the Color Sensor
What type of questions can we ask using
this sensor

• Are you on line or not?

© 2015 EV3Lessons.com (Last edit: 2/28/2015)

1. If we are on black, keep 100
going straight

2. If we are on white, turn
left to get back to the
line

Seems to work fine here…

© 2015 EV3Lessons.com (Last edit: 2/28/2015)


Click to View FlipBook Version