# EV3 basics course. Color Sensor. Stop on third line without Wait block (part 3) ProPreview

Use the color sensor to count the lines and stop on the third line. We do not use the wait block for this.

• #149
• 24 Oct 2015
• 7:06

The algorithm is simple. Just detect a sequence of blacks and whites and in this way count the lines. Without the wait block we do not depend on rotations or seconds and thus we do not depend on the size of the wheels. on the robot constructions and other. This program could work for any robot.

### Previous tutorials

Instructions for building the EasyBot are available at:

### Color sensor stops at third line

Program for detecting the lines without using a wait block.

### Follow Line With Two Light Sensors

- Follow black line using two light sensors.

### Color sensor stops at third line

Program for detecting the lines without using a wait block.

### English

Previously we did stop at the second line using a hack with the wait block. Now we would like first to remove the hack and second to stop at the third black line.

What should actually happen here is not to move forward, detect a line, stop, move forward, wait for a couple of ms, until we are no longer on the black line and then start detecting the black line. This logic is flawed and we must find another logic for our program. What would be the logic?

Again, detecting a line. Move forward, detect a line, stop, then we'll move forward with the Tank block, just on, but we are moving forward until we detect the white table. So it's a color sensor and we are waiting for a color and this color must be white, it should not be a black color, it should be a white color because the table is white. After we detect white this means that the sensor is no longer on the black line and we can stop with the Tank block. Like this.

This will move the robot over the black line and then over the table. The next step is to start looking for the second line. So we'll take this 3 blocks, we'll copy them

we have the same 3 blocks and we'll do the same program again. Like this. Just connect them.

This will move the robot to the second black line. Then after detecting the second black line, again I'll copy and paste these 3 blocks we'll move the sensor over the table after the second black line. We'll repeat this for the third line, copy and paste.

Running.

That's strange. The program should be working. It seems logical, but it's not actually working.

So you saw that it seems to detect some of the black lines but not all of them.

I'll need to get back to the computer so that we can explore what might be wrong with this program.

The logic of the program is working, but some of the values of the program are not correct. Now we didn't said much about the way the color sensor works, we just chose some values here. So for black it was 1 and we decided that for white it would be 6 and we are here waiting for the white table, but it seems that the table is not actually white and the sensor detects a table not white, it is not white it's kind of yellowish, very bright yellow, but it's not white, so if we are now over the black line you can see

right here in the lower right corner that when we are over black, so the sensor is over the black line, the sensor returns a value of 1 so it is OK we know that 1 is equal to black but if I now move the robot over the table you can see that the value is actually 7. This means that the sensor detects a color, this color is the color of the table and for this color it returns a number 7 and what we've done in all the blocks that we are waiting for the table is to select a color that is equal to 6. Now in the next videos I'll enter in more details about how are these colors formed and what does it mean to have a certain color and how are the values related to each other, but for now let's just select 7 here as a color that we are waiting not 6 because the table is not white but actually 7 and for the third block - 7.

What we had here as a program is that we haven't configured the correct value for the colors that we are waiting, for our robot to detect. Let's check if this program is working. Download and run our program.

And we have implemented a program that stops the robot at the third black line.

What I would like to do next is to improve this program because truthfully it's kind of ugly.