# Color Sensors and Loops

By combining color sensors with loops, a greater understanding of color sensor may be achieved.                &#x20;

Main program flow: Robot begins on starting blue, needs to move off the line to start and then it look for blue  or

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeYZ31ODsjNAx_xwTOAaBXzS8pQStz282sGiw0EmCpxJerBeU3FNDTx9SLuPW0tnR7LygL5ugp4xloShdiT6yS5P4UlqIkUZ76-sbwXg6-N3YjHIP7O5tHOUdfhYSFz2PrfQdTKeQcCnjqiuxErx71VOyg?key=KxOzS226JyqPxk_1PhEW2w)![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdFojDOm9XWgV75Rbr2kfXj3aGsFe73muVnTKtsjALPZd7Fdw50W-SRfEF8ZH1ee8d7S3VcsKs5GedEtxYjzCvOrhmeFy9XZwaGdn07jgt9zApqCX2hkv0O-hPBMtRNP3QWbh7z4B3u2wnaJ_-E6LBzoRWt?key=KxOzS226JyqPxk_1PhEW2w)

If while blue sensor is < 50" means it hasn't hit blue yet, but once blue is greater than 50, the statement is false, so it moves on to the next task.\\

&#x20;So overall it's not identifying blue in the loop, it's identifying while there's not blue, wait.&#x20;

Color Sensors use RGB values

while blue sensor is on blue (>50) the sensor moves forward off the blue. ( the sensor reads blue)  and while it is on gray (<50) it keeps going and when it sees blue it is false\
\
![](https://1633469732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv8hfOD2FAX4jGYqMD1k9%2Fuploads%2FO7fSN43actGtjRoYawhN%2Fimage.png?alt=media\&token=5512af67-2e2c-4778-b75a-0dc1951d66f1)\\

Why is this sensor detecting White

White RGB code = Red 255 Green 255 Blue 255 \\

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdjF-ZYM3yT8jyB55EUQxKfStQsB7wqco9UACTIKL6nw_gLmX2eSNXI-Ii-pB50pZP9zFU6Zj_QdTelUz4FVw4W2m7GOKirHIx-8rERcPU-air4s-2483nbsqdLGuHBSm6WAQnNFDjW8KIx-K08YlRLZ3c?key=KxOzS226JyqPxk_1PhEW2w)\\

The color sensor is trying to find red which has a RGB -R number around the >150&#x20;

IF the sensor does not detect a red value greater than 100- the statement is true- the robot/code does not continue to the next line.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdNdjL5GchZGLDwiZIimBfDSn_bFftSfR9peHdKRvwHSAstOaxN6Ku0H4JxJqMiOT9E7jhbxnBAIRdYxCisgG0s642KoTSVnls08RkuPGDgiq_xuinYo_5HukYcpt4vSxg-dNegeIpfvQzDPTvk5FJTuRrP?key=KxOzS226JyqPxk_1PhEW2w)

The robot moves until the red color sensor goes higher than 100--or the robot moves as long as the statement is true.   The sensor is not detecting a red value/number greater than R100.   When the robot crosses the red tape,  the Red ensor number goes above 100  and the statement is false, when this statement is false the robot goes to the next line of code,

For more information:

FTC Color Sensor Tutorial Using a Color Sensor Part 1 <https://www.youtube.com/watch?v=iQufRF1HFRc>&#x20;

&#x20; Or Using a Color Sensor Part 2  start 1:11

<https://www.youtube.com/watch?v=uSEEO3_JVTI>&#x20;

FTC Sim Color Sensor <https://www.youtube.com/watch?v=70sV821oa5o>&#x20;
