LEGO® MINDSTORMS® Education EV3 Core Set

Object Detection

Design ways to avoid accidents between vehicles and objects in the road.

45-90 min.
Intermed.
Grades 6-8
Object Detection
Teacher Support

Students will:
Extend understanding of the Loop

This lesson works on the following operating systems:
device_logodevice_logodevice_logodevice_logodevice_logo

NGSS
MS-ETS1-1. / MS-ETS1-2. / MS-ETS1-3. /MS-ETS1-4.

CSTA
2-A-2-1 / 2-A-7-2 / 2-A-7-3 / 2-A-7-4 / 2-A-5-5 / 2-A-5-6 / 2-A-3-9 / 2-A-6-10 / 2-C-7-11 / 2-C-4-12 / 2-D-5-16 / 2-I-1-20

Student Worksheet

Download, view or share the student worksheet, either as a an online HTML page or a printable PDF

Share with:

Object Detection

Connect

Ignite a classroom discussion around the following questions:

  • In what driving situations can a car hit an obstacle?
  • What factors are crucial to be aware of in order to avoid collisions with obstacles?
  • What causes traffic jams in high density areas?

Allow the students to select the tool(s) they find most appropriate for capturing and sharing their ideas. Encourage them to document their thoughts using text, videos, images, sketchnotes, or another creative medium.

Construct

Build
Students will construct the Robot Educator base model, and then they will add the Ultrasonic Sensor pointing forward.

Have the students perform the following building check before they program their robots:

  • Are the wires correctly connected from the motors to ports B and C?
  • Are the wheels correctly installed?
  • Are the wheels rotating freely?
  • Are the wires correctly connected from the Ultrasonic Sensor to 4?

Program
Introduce the simple use of the Ultrasonic Sensor.
Demonstrate the Wait Block and how to use it with the Ultrasonic Sensor.
Ask the students how they could make a program to detect any obstacles that might appear while the wheeled robot is moving forward (or backward).
Students will create a program that makes the robot stop at a given point based on a distance measured by the Ultrasonic Sensor.
Allow the students to select the tool(s) they find most appropriate for capturing and sharing their pseudocode. Encourage them to use text, videos, images, sketchnotes, or another creative medium.

POSSIBLE SOLUTION
FILENAME: CODING-05.EV3 (TAB: 1)

DETECT OBJECTS AND STOP

  1. Start the program.
  2. Turn both motors on at speed 50.
  3. Wait for the Ultrasonic Sensor to detect an obstacle at a distance of less than 20 cm.
  4. Turn both motors off.
DOWNLOAD SAMPLE PROGRAM
(8 KB, Requires EV3 Desktop Software)

Note
Refer students to the Robot Educator Tutorials for further assistance.
In the EV3 Software :
Robot Educator > Basics > Stop at Object

Set up
Before assigning the next task, make sure that you have marked the path the robots must follow and that there is enough space to complete the task. It is a good idea to have students work on a big table or on the floor.
Have the students experiment with using the Ultrasonic Sensor to detect different objects. One of the objects can be a cuboid made of LEGO® bricks.

Contemplate

On the road, when a driver sees an object, they slow their car down before coming to a full stop.
Have the students program their robots with the same behavior.
If the Ultrasonic Sensor:

  • Detects an object less than 10 cm away, make the robot stop
  • Detects an object between 10 and 20 cm away, make the robot slow down
  • Does not detect any object, continue to move at full speed

POSSIBLE SOLUTION
FILENAME: CODING-05.EV3 (Tab: 2)

DETECT OBJECTS AND REACT

  1. Start the program.
  2. Turn both motors on at speed 50.
  3. IF the Ultrasonic Sensor detects an obstacle at a distance of less than 10 cm, turn both motors off.
    ELSE
  4. IF the Ultrasonic Sensor detects an obstacle at a distance of less than 20 cm, turn both motors on at speed 10.
    ELSE
  5. Turn both motors on at speed 50.
  6. Repeat steps 3 to 7 forever.
DOWNLOAD SAMPLE CODE
(8 KB, Requires EV3 Desktop Software)

Differentiation option
Bring all of the teams together.
Tell the students to place their robots in a vertical line with varying amounts of space between them (just like cars in a traffic jam).
Have them start their programs at the same time and watch what happens.
• Ask the students to refine their programs so that all of the robots continue driving at the same speed with equal distances between them (like well-flowing traffic on a road).

Share
Allow the students to select the tool(s) they find most appropriate for capturing and sharing their creations, unique thinking, and learning process. Encourage them to use text, videos, images, sketchnotes, or another creative medium.
Discuss the concept of efficiency in programming.
How many variations did the group as a whole come up with? Compare the many possible solutions to the given problem.

Assessment Opportunity
Specific rubrics for assessing computational thinking skills can be found under 'Assessment'.

Continue

Using Text-Based Programming
Have the students explore text-based programming solutions so they can compare different programming languages.

MakeCode - POSSIBLE SOLUTION

Program with Blocks or JavaScript in your web browser using Microsoft MakeCode editor for LEGO® MINDSTORMS® Education EV3.
You can find the Object Detection Activity Here

Swift Playground - POSSIBLE SOLUTION

While true {
ev3.move (leftPort: .b, rightPort: .c, leftPower: 50, rightPower: 50)
While ev3.measureUltrasonicCentimeters (on : .four) < 20
{
ev3.stopMove (leftPort: .b, rightPort: .C)
}
}

ROBOT C: POSSIBLE SOLUTION

#pragma config(Sensor, S4, sonarSensor, sensorEV3 _ Ultrasonic)
#pragma config(Motor, motorB, leftMotor, tmotorEV3 _ Large,
PIDControl, driveLeft, encoder)
#pragma config(Motor, motorC, rightMotor, tmotorEV3 _ Large,
PIDControl, driveRight, encoder)
/*
Create a program that drives the robot forward until the Ultrasound
Sensor sees an object.
The robot then stops.
*/
task main()
{
//Set motor speed at 50% (Drive Forwards).
setMotorSpeed(motorB, 50);
setMotorSpeed(motorC, 50);
while(getUSDistance(sonarSensor) < 20)
{
//Keep going until the Ultrasonic Sensor sees a value less
than 20cm.
}
//Once the Ultrasonic Sensor sees a value less than 20cm.
//Set motor speed to 0% (Stop).
setMotorSpeed(motorB, 0);
setMotorSpeed(motorC, 0);
}
DOWNLOAD SAMPLE CODE
(2 KB, Requires ROBOTC Software)
Warning! This may be dangerous!

The following is a possible solution using the text-based programming language ROBOTC. You may choose to use any other LEGO MINDSTORMS Education EV3 compatible text-based programming languages.
LEGO Education has no ownership of the ROBOTC platform and does not provide any support or guarantee of the quality of the user experience and technology used. All required set up information is provided by ROBOTC at robotc.net. We recommend always to reinstall the official LEGO MINDSTORMS EV3 Brick firmware when you finish using other programming languages.

Guide to reinstalling EV3 Brick

Other Program Solutions

Swift Playground - POSSIBLE SOLUTION

While true {
if ev3.measureUltraSonicCentimeters (on : .four) < 20
{
if ev3.measureUltrasonicCentimeters (on: .four) < 10 
{
ev3.stopMove(leftPort: .b, rightPort: .c)
else 
{
ev3.move(leftPort: .b, rightPort: .c, leftPower: 10,
rightPower: 10)
}
}
else 
{
ev3.move(leftPort: .b, rightPort: .c, leftPower: 50,
rightPower: 50)
}
}

ROBOT C: POSSIBLE SOLUTION

DOWNLOAD SAMPLE CODE
(2 KB, Requires ROBOTC Software)
Teacher Support

Students will:
Extend understanding of the Loop

This lesson works on the following operating systems:
device_logodevice_logodevice_logodevice_logodevice_logo

NGSS
MS-ETS1-1. / MS-ETS1-2. / MS-ETS1-3. /MS-ETS1-4.

CSTA
2-A-2-1 / 2-A-7-2 / 2-A-7-3 / 2-A-7-4 / 2-A-5-5 / 2-A-5-6 / 2-A-3-9 / 2-A-6-10 / 2-C-7-11 / 2-C-4-12 / 2-D-5-16 / 2-I-1-20

Student Material
Student Worksheet

Download, view or share the student worksheet, either as a an online HTML page or a printable PDF

Share with:

The maximum quantity of an item that can purchased in each transaction is 99.

To inquire about purchasing more than 99 of one item, please call 800-362-4308.

To inquire about purchasing more than 99 of one item, please call 800-362-4738.