Switch
Use the Switch block to make dynamic sensor-based decisions.
Build It
Build the Driving Base model and the Color Sensor Down Module.
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.
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.
First, make sure that the Driving Base is connected via USB and then move the Colour Sensor over the dark line.
Next, open the Hardware Page and note down the value shown on Port 3. This is the minimum value (x).
Now move the Colour Sensor away from the dark line.
Note down the value shown on Port 3. This is the maximum value (y).
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).
Next, download the program.
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?
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