MINDSTORMS EV3 Core Set

Switch

Use the Switch block to make dynamic sensor-based decisions.

90-120 min.
Intermed.
Years 7-9 or Key Stage 3
switch-connect

Build It

Build the Driving Base model and the Color Sensor Down Module.

ev3-robot-driving-base
ev3-robot-color-sensor-down

Test It

Recreate the program shown, then download and run to test.

The sample program ‘01’ has been provided on the canvas.

Hint
The Port View App on the EV3 Brick can also be used to view real-time sensor readings.

Switch_main

Program Summary

Start
Loop – Unlimited
Switch – Colour Sensor – Compare Reflected Light
Intensity[Less Than, 50]
If True: Large Motor C – Off
If True: Large Motor B – On
If False: Large Motor B – Off
If False: Large Motor C – On

Setting a Threshold

A threshold sets the upper and lower limits of a sensor and uses them to find the average, which then becomes the threshold. On the following pages you will set the threshold of the Colour Sensor’s sensitivity to light.

switch-exp1

First, make sure that the Driving Base is connected via USB and then move the Colour Sensor over the dark line.

switch-exp2

Next, open the Hardware Page and note down the value shown on Port 3. This is the minimum value (x).

switch-exp3

Now move the Colour Sensor away from the dark line.

switch-exp4

Note down the value shown on Port 3. This is the maximum value (y).

switch-exp5

To set the threshold, calculate the equation (x+y)/2 and enter the result in the Switch block (your value may differ from the example shown).

switch-exp6

Next, download the program.

switch-exp7

Modify It

Now it’s your turn! Test if your Driving Base works when following a lighter-coloured line! If not, try setting the threshold again.

Troubleshooting
At some point, the sensor light reflecting off the line will exceed the threshold, causing the Driving Base to drive in a circle. If this occurs, change the threshold Value.

Hint
If the difference between the x and y values is too small, the line will not be detected. If this occurs, try recalibrating the sensor.

What is next?

ModifyIt_0

Teacher Support

Students will:
Use the Switch block to make dynamic sensor-based decisions.

LEGO® MINDSTORMS Education EV3 Core Set
LEGO® MINDSTORMS Education EV3 Lab or EV3 Programming