🦾 EV3 102: #06 - EV3 Sensors: Touch

By Matt Richardson
Last updated over 1 year ago
22 Questions
This course includes resources provided by the following:
  • LEGO Education
  • CS-STEM Network from Carnegie Mellon University
  • EV3-Scratch documentation provided by Raphael Holzer
  • Joe Olayvar & Evelyn Lindberg in association with the Washington State Library
🌏 Click here to access the LEGO Education website.
📑 Click here to access the EV3-Scratch documentation.
🎓 Click here to access the online EV3 course from CS2N.
📕 Click here to access the LEGO Mindstorms EV3 Programming Basics document in its entirety.
▶️ Click here to access the entire LEGO Mindstorms EV3 YouTube playlist from the Washington State Library.
The Sensors lessons introduce the Touch, Ultrasonic, Gyro, and Color Sensors. You will gain an understanding of the appropriate sensors to use to accomplish different tasks.

⬇️ Install It

Before continuing, ensure that your computer has the EV3 Classroom app installed.

🔧 Build It

Before you continue, ensure that you have completed the following builds:

Color Cube (aka Cuboid)

Base Unit (aka Driving Base)

➡️ Sense, Perceive, Plan, Act

🎓 Learn It

Carefully read and/or watch the instructional media and respond to the related questions.
If robots only do what they're told, how is it that one program can make the robot do different things every time it's run? This robot is designed to stop at a specific distance from the wall. If it starts close to the wall, that’s a short distance.

If it starts far from the wall, it’s longer.

The robot can tell when it reaches the wall using the Ultrasonic Sensor.  And in both cases, that’s how the robot knows when to stop. This type of behavior is what makes a robot a robot.


Sense, Perceive, Plan, Act

Sensors provide information about the world.  The program uses that information to figure out when to stop. And then the robot acts accordingly. Sense, Perceive, Plan, Act (SPPA) summarizes the four critical capabilities that every robot must have in order to operate effectively: SENSE: A robot needs the ability to sense important things about its environment, like the presence of obstacles or navigation aids.

PERCEIVE: Perception answers the question “What am I looking at?” This requires more than raw sensor data -- the robot needs to make sense of that data. Is the robot looking at the object it wants to pick up, or a wall in its way? Perhaps it needs to combine information from a few sensors to figure that out. Interpreting raw sensor data into useful understandings about the environment is called perception. Perception allows a robot to act in a way that is appropriate and safe within the environment.

PLAN: Based on its understanding of the world around it, the robot then needs to respond appropriately. Sometimes the strategy can be written in advance, like turning left at the first wall. Other times, the robot needs to figure out the right combination of moves on the spot. In either case, the robot will follow the program written by the human programmer that tells it what to do next, or how to figure that out for itself.

ACT: Finally, a robot must carry out the actions that the plan calls for. Robots will do exactly what you tell them to do. That may not be the same as what you meant! It is important to be very precise when telling robots what to do.
1.

Discuss: Is a smartphone considered a robot? Why or why not?


2.

  • Discuss: Think of another robot you use in your daily life.  How does it meet each component of SPPA?


3.

Which of the four robot components allows a robot to comprehend what they are looking at?

4.

True or False: If given precise programming, robots will do exactly what you tell them to do.

👆 Introduction with Touch Sensor

5.

Why are sensors important to robots?

6.

What is the advantage of Sensor Control over Sequential Commands?

⏱ Wait for Touch

In this lesson, you will program the robot to wait until its Touch Sensor is pressed before moving.


Robot Configuration: Touch Sensor Drive Base

For this chapter, the Touch Sensor Driving Base is required to complete the next sections of this chapter.

Touch Sensor Configuration


Touch Sensor Driving Base Build Instructions: https://drive.google.com/file/d/1wd4h4o8DigHtkspGUB4229av-zTBIVcn/view?usp=share_link


Step 1: Plug in Touch Sensor

Ensure that the Touch Sensor is plugged into port 1 on the robot.


Step 2: Start New Project

Create a new project and program.


Step 3: Add Move Forward Block

Add a “Move [forward] for 1 [rotations]” block to the program. This block will make the robot go 1 rotation when it runs.


Step 4: Add Wait Until Block

Now click on the light blue “Sensors” palette, and add a Touch Sensor “wait until” Block above the “Move” block.


Step 5: Add Exit Block

Drag a “stop [and exit program]” block from the Control palette, and place it at the bottom of the stack.


Step 6: Rename Project

Rename the program as “WaitTouch”.


Step 7: Download and Run Project

The robot waits for the Touch Sensor to be pressed, and then continues on to the Move command.
7.

What is the function of the “wait until pressed” block?

8.

In the program below, the robot waits before it moves because…

🚦 Try it! Already Pressed
What happens if you’re already holding down the Touch Sensor’s button when you start running the program?


What happens?

  • The robot moves immediately. The Wait Block detects that the sensor is “Pressed” and passes control to the Move Block.
  • “Pressed” simply means “the button is in the pressed position”; it does not matter how or when it was pressed in!

💡 Did You Know? EV3 Buttons

The 5 buttons on the front of the EV3 (not counting the Cancel button) can be used as Touch Sensors!
Try using the “wait until [center] button [pressed]” Sensor Block and setting the button selection to different buttons and running your program.

Once it’s running, press the middle button on the front of the EV3!


What happens?

  • The Wait Block now waits for the middle button on the EV3 to be pressed. The robot then moves.

💡 Did You Know? How the Touch Sensor Works


When the Touch Sensor is pressed, it closes an electrical circuit, allowing current to flow.

If the Touch Sensor is released, the circuit is broken and no current flows.

The flow (or lack) of current is detected by the EV3, allowing it to determine whether the Touch Sensor is pressed.

🧠 Making Sense of Systems

Simple programs follow a simple rule: run commands in order from top to bottom and one at a time.

More complex programs might contain “Wait Until” blocks that hold program flow at that spot until the condition is true. Conditions are statements made for the robot to evaluate something as either true or false. This Wait Until block in the program below checks if the Touch Sensor is pressed.  The condition will be true if it is pressed, and false when it is not pressed.  In this program, the robot will not move forward until the Touch Sensor has been pressed.

Programs pay attention to one block at a time.  Their attention ‘flows’ from block to block.  Blocks in a sequence pass the flow down the line.  Wait Until blocks hold the flow of the program at that point, and when the condition is true, the flow of the program continues.

Making a Mental Model

This mental idea of how the system works is called a “model.” It’s like a tiny version in your head of how the real system operates.

This model explains sequence and Wait Until in a single idea, which helps everything make more sense.

It also helps you better predict what a new program will do since you know how it will work as a system.  By having a mental model of how program flow works, you can learn to develop complex programs more easily.

Practice

1.  Examine the program below.  Describe what the robot will do, or, how the program will flow, after the program has started.
2.  Examine the program below.  Describe how the program will flow after the program has started.

Discuss

Consider the questions below, and then share your thoughts.
  • What are the benefits of creating mental models? Why does it help with understanding program flow? What else could you use mental models for?
  • Why is program flow an important concept to understand as a programmer?
9.

Discuss: What are the benefits of creating mental models? Why does it help with understanding program flow? What else could you use mental models for?


10.

Discuss: Why is program flow an important concept to understand as a programmer?


➡️ Forward until Touch

Introduction: Forward until Touch

In this section, you will program the robot to move until its Touch Sensor is pressed. To do this, you will turn the robot’s motors on, leave them on while Waiting for the Touch Sensor to be pressed, then Stop them.


Step 1: Create New Project

Create a new project and program.


Step 2: Add Move Block

Begin by putting in a “start moving [straight]” Block. This Block simply commands the motors to turn on and stay on until another command tells them to change.


Step 3: Add Wait Until Pressed Block

Next, add a Touch Sensor “wait until [pressed]” block.


Step 4: Add Stop Moving Block

To have the robot stop its motors, add a “stop moving” block.


Step 5: Add Exit Block

Drag a “stop [and exit program]” block from the Control palette, and place it at the bottom of the stack.


Step 6: Rename Project

Rename the program as “ForwardTouch”.


Step 7: Download and Run Project

The motors turn on, the robot waits for the Touch Sensor to be pressed, and then turns the motors off.


🚦 Try it! Forward Until Release

The Touch Sensor “wait until” block can wait for the sensor to be "Released" as well as "Pressed".

What happens if you set it to “not released” and run it with an empty box holding down the sensor?

Note: When setting up the robot, have the obstacle placed firmly against the Touch Sensor so that it keeps it pressed in, as shown above.
11.

True or False: The ‘released’ option in the wait until block can only be used when the robot is in reverse.

🔀 Pseudocode

Big challenges are made up of small challenges. Try breaking it down into smaller pieces. Once you know how to solve parts of the problem, you can build on them and combine them to create your final solution. In programming, you can figure out a plan of what you want the robot to do, break it down into smaller parts, and build your program up from those pieces.


🔁 Iterative Process and Pseudocoding

What is the best way to develop a plan for your robot? Well, what is the best way to build a building? Is it best to build it all at once? While this may seem convenient, this method is prone to failure and makes it really hard to pinpoint where the failure took place. When you try to put too many parts together at once, the complexity of the system is too great.  Too many little things can go wrong and it would be harder to find where the problem lies.

A better way would be to use an iterative process! You can start by building the foundation, test it to see if it is stable, then add the first floor, test it, and add another floor.  It is important to test each after iteration to make sure there are not any problems. You can build the entire structure from the ground up, testing at each level to know that it’s stable.  If something goes wrong, it is easy to know where the problem is because only one small part is added at a time.

This same methodology applies equally as well to programming. Take one small step and figure out how to solve it. Add it to the whole, and test the step. The best way to build a complex program is not all at once, but rather iteratively. This approach allows you to know that you’re building on a solid foundation of code! If something does go wrong, you know where to start looking to find the error.  In general, pseudocode is used to outline a program before translating it into code. Your programs get more complicated as you learn different robot behaviors and use sensors.  Therefore, your pseudocode will become more detailed. But how detailed should it be? Let’s take a quick look at this example activity…

First, it is important to break the steps down iteratively. This example shows the steps on how to catch a fish.  The steps in the first column started off somewhat vague.  But you can see that each column becomes more detailed. By the last column, the steps are very thorough with an iterative design and include specific details such as exact measurements, location, and directions.  Notice how multiple arrows are drawn from a single step in the “original” left column and branch out to the more detailed steps in the center and right columns. These arrows represent the expansion of the original, simple step into steps with more detail. Breaking down, or decomposing, your original steps to be more detailed, and again to be even more detailed, will help make a large task or problem much easier to accomplish! Try this activity on your own!
12.

✍️ Pseudocoding Activity: Everyday Task

Complete the following activity on the Formative canvas:

1.  Select one of the following tasks.
  • Feed your pet
  • Take and post a selfie
  • Catch a fish using a rod and reel
  • Take a bus/subway/train to meet up with your friends
  • Add two 2-digit numbers by hand
2. In the first column, write down the steps you would need to do, to do the task you picked.

3. In the second column…
  • Break those steps down into more detail, like you’re explaining them to someone who has never done that task before.
  • Draw lines connecting each detailed step back to the instruction it came from in the left column.
4. In the third column…
  • Break those steps down into even more detail, like you’re explaining them to a 2nd-grader. 
  • Draw lines connecting them to the steps in the middle column they came from.

13.

✍️ Pseudocoding Activity: 🚜 Orchard Challenge

Complete the following activity on the Formative canvas:

Use the same Pseudocoding Chart to write pseudocode for the Orchard Challenge from the Movement Unit!

2. In the first column, write down the steps you would need to do, to do the task you picked.

3. In the second column…
  • Break those steps down into more detail, like you’re explaining them to someone who has never done that task before.
  • Draw lines connecting each detailed step back to the instruction it came from in the left column.
4. In the third column…
  • Break those steps down into even more detail, like you’re explaining them to a 2nd-grader. 
  • Draw lines connecting them to the steps in the middle column they came from.

14.

Discuss: In what ways do you find pseudocoding helpful?


15.

Discuss: Do you think everyone’s pseudocode will look the same if trying to complete the same challenge? Why or why not?


🏆 Mini-Challenge:


🧹 Vacuum

Using a Touch Sensor, program the robot to touch all four walls of a room!
Using a 4’x4' table (with walls), have the robot start by facing toward a wall. Using a touch sensor, program the robot to move forward and touch ALL four walls.

🌐 A virtual version of this challenge is available HERE.
17.

📸 Document It: Capture a screenshot (or multiple screenshots) of your completed program and upload or paste it onto the Formative canvas.

18.

⬆️ Upload It: Upload your completed program.

🏆 Challenge:


🦾 Arm Position



Challenge Overview

For this challenge, construct an arm with the Touch Sensor attached so that when the arm is fully upright the button on the Touch Sensor is pushed in. This might require adding an axle and another part to increase its "surface area".
Place the robot on a surface, and an object approximately 5 rotations length away from the robot. Starting with the arm in the ‘down’ position, program the robot to raise its arm until the touch sensor is pushed in, move forward 5 rotations, lower the arm around the object, and then bring the object back to the starting location.


Challenge Details

Rules and Procedures:
  1. The robot’s arm will be moved to a random position before running.
  2. You must use the parts available to you to modify the Touch Sensor’s mounting so that it can detect when the EV3’s arm is in the “up” position.
  3. Try to do this with as few changes as possible.
  4. When the “Up” button on the front of the EV3 is pressed, the robot must raise its arm to the “Up” position (1), move forward five rotations to the cargo (2), and bring it back to the original starting position (3).

Hints:
  • The trigger area on the Touch Sensor is small. You will probably need to build a “bumper” or “extender” on the end of the Touch Sensor to make it detect the arm more reliably.
  • The EV3 core set includes two Touch Sensors. You can use one sensor for detecting the arm in the “Up” position, and the other to detect the box.
  • You can also make a test run, then calculate “how many times as far” you need to move or turn to get the amount of movement you want, compared to a test run.
🌐 A virtual version of this challenge is available HERE.
20.

📸 Document It: Capture a screenshot (or multiple screenshots) of your completed program and upload or paste it onto the Formative canvas.

21.

⬆️ Upload It: Upload your completed program.

22.

🧠 Retrieval Practice:
Summarize the content of this lesson. What topics, ideas, and vocabulary were introduced?