The dual RGB color sensor can provide multiple types of data, including the analog output that indicates light intensity, the digital output that indicates the line and background states, and calculated parameter values for motor control, which ensures sufficient flexibility while simplifying your application process. Based on the data output, teachers can explain the knowledge and working principles from different aspects.
The dual RGB color sensor provides the adaptive map learning function. It automatically sets the thresholds after learning the colors of a background and to-be-followed line. The firmware of the sensor includes a line-following algorithm and can directly output parameter values for controlling the rotational speed of motors, which makes high-speed line following easier.
- Press: No functionis defined.
- Double-press: When the button is double-pressed, the dual RGB color sensor starts to learn the background and line for line following.
Place the light sensors on the background of the line-following track map and double-press the button. When you see the LEDs indicating the line-following state blink quickly, sway the sensors from side to side above the background and line until the LEDs stop blinking. It takes about 2.5 seconds. The parameter values obtained are automatically stored. If the learning fails, the LEDs blink slowly, and you need to start the learning again.
- Long-press: When the button is long-pressed for two to three seconds, the dual RGB color sensor switches the color of the fill lights in the order of red, green, and blue. Generally, you don't need to change the color. The color is set automatically after the learning is complete.
Each group of color sensor consists of a light sensor and RGB LED.
In the real world, when you see an object in red, it indicates that the object absorbs more of the other light than the red light. Therefore, if you use a fill light to shine red light on an object, the redder the object is, the more light it reflects, and the greater the output value of the light sensor is. In this way, you can obtain the red intensity of the object. Similarly, you can change the color of the fill lights to obtain the green and blue intensity of the object and thus determine the color of the object.
Environmental interference and detection errors
In the physical world, you may find environmental interference and detection errors almost everywhere. If a color sensor needs to determine the color of an object based on the intensity of the light (shone by a fill light and reflected by the object) it detects, detection errors may be caused because the ambient light is also detected.
Pay attention to the detection errors. When you use two dual RGB color sensors to detect the color of an object in the same environment, the detection results may be different. But in general, the difference is small.
In practice, engineers use algorithms or some special design to avoid environmental interference and detection errors. For example, you can use a 3D printout to block the ambient light from reaching the object to be detected and the dual RGB color sensor; alternatively, you can use an algorithm: to record the ambient light intensity when the fill lights are turned off, and immediately record the intensity when the fill lights are turned on; and then calculate the difference between these two intensity values. This difference can be determined as the intensity of filling light reflected by the object. In the algorithm, the ambient light intensity is considered almost unchanged in a very short time.
For detection errors, you can also use an algorithm to classify multiple close values as one color.
- Color sensors are used to design an assembly line for parts sorting.
- Detection range: 5–15 (mm) from the object to be detected
- Operating current: 70 mA