Tip:
Highlight text to annotate it
X
We want the Color Sensor to find the edge of the line by going from white to black...
We can do this by stopping one motor, and having the other motor going forwards
Start up Lego MindStorms EV3
Left-click on "File"
Left-click on "New Project"
Make sure the green rectangle is raised
Drag the "Move Tank" command up to the Command line
To make the Robot turn, we will set one of the motor speeds to zero, and...
and the other motor to our favourite testing speed of fifty percent.
We do not know how many wheel rotations will be needed for the color sensor to find the edge of the black line, so...
So we will set Rotations to "On"
One motor is stopped, and the other motor stays "On" at fifty percent
These motor speeds will turn the Robot around...
But we can not download this to our EV3 to test, because...
because this command will take only a tiny fraction of a second to run, and...
and our Robot will not move!
We need to put a "Loop" around our motor command.
Make sure the orange rectangle is raised, and...
and drag a "Loop" to the command line.
move our motor commands inside the Loop.
The Loop will cause the EV3 to keep running the motor command continuously
It will keep obeying the motor command until you turn the EV3 off.
BUT we wanted the motors to stop when black was reached.
How can we do that?
To make the color sensor work, make sure the orange rectangle is raised, and...
and drag the "Switch" to the command line.
There is not much room, so close the "Document your Work" window.
Left-click on the "Pan" option and use the "hand" cursor to drag your work into the middle of the screen.
Then left-click on the "Select" option to get the Arrow cursor back.
The Switch is set up to use the touch sensor, we do not want to use the touch sensor.
We want to change the Switch to use the "Color Sensor" option,
the "Compare" option, and...
and the "Reflected Light Intensity" option; left-click.
The "switch" now does different things if the Color Sensor reading is big (white) or small (black)
We usually use the > "Greater" or "Greater or Equal to" options
and we have to work out a Color Sensor value that separates white and black.
To do this we click twice on the right button to get to "Port View"
then click on the centre button to get the Sensor Readings view, and...
and click on the right button three times to get to the Color Sensor reflected reading from EV3 sensor port 4.
To read the black value, put the color sensor over the black line, and...
and read the reflected light value on the EV3 screen (four percent). Yours will be different.
To read the white value, put the color sensor over the white background, and...
and read the color sensor reading of seventy-two percent. Yours will be different.
To calculate the light value to put in the switch...
calculate the average of the black and white color sensor readings, that is...
(4+72)/2 = 38; type 38 instead of the default 50 (Your readings will be different.)
Your values will be different, because the light in every room is different - you will need to calculate this value each robot session.
In my room, if the color sensor reading is greater than 38, the color sensor is over the white part of the arena. so...
So, when it is on the white, we want the Robot to turn around. So...
So we can drag the motor commands we already have, up into the "white" (greater than 38) portion of the Switch.
So when the robot is over white, the EV3 keeps going around the motor command loop, as long as the color sensor reading is greater than 38.
Eventually the black will be reached, and the EV3 will go to the lower Switch command line - which is empty.
Let us download this to our Robot EV3 to test our commands.
What we want to happen is that our Robot will swing around towards the black line, like this...
What actually happens is that our Robot turns in the opposite direction!
Because this video is getting long, we will show you how to fix this in our next video tutorial...