Two things are responsible for the colors as we know them - light and our eyes.
For instance the sunlight, which we call white, actually combines all colors. This can be observed using glass triangular prism, as shown below:
Simplified, the difference between the different colors is the amount of energy, the corresponding light ray has. On the table below are shown the different types of light.
The so-called gamma rays "have" the greatest amount of energy, while the radio waves - the least. In the middle, where there are multiple color stripes, we have the light we can see and hence it is called visible light. From the visible light spectrum, the violet light has the greatest amount of energy and the red has the lowest.
We see different objects in different color, depending on what light they absorb and what they reflect. For example, the objects we call black actually absorb all of the light and therefore they absorb a lot of energy. On the other hand, white objects reflect all of the light and absorb far less energy. That is why in the summer we feel hotter wearing black clothes, than wearing white ones.
How do we see colors?
So far we have learned what different colors are. But how do we differentiate them? There are three types of cone cells in our eyes. Each type is sensitive to either red, green or blue light. Each cell sends signals to the brain about the intensity of the light it has detected. Having the information about the amount of red, green and blue in each light ray, our brain is able to "see" different colors.
And how do robots see colors?
Instead of eyes, robots have sensors. Just like people, robots use three types of sensors. Each type detects the intensity of red, green and blue light. Combining the information from the three sensors, the robot can conclude what color it "sees".
LEGO EV3 Color Sensor
The LEGO Color sensor consists of two main parts - a diode which emits light and color sensors which measure the intensity of the reflected light.