Introduction: Color Sensor Modern Robotics
This Color Sensor is an RGB Color Sensor that can be found at Modern Robotics. It works by detecting certain amounts of color that can be found from natural light source or by a light that reflects the color into the sensor. The color sensor is an I2C device and can be used in First Tech Challenge with the Core Device Interface Module
Step 1: Parts of Color Sensor
On the body:
- The Light: This can be turned on or off depending on the need of the sensor. If the sensor needs to be able to read a color through a certain opaque object, it should be turned off. For instance, in the FTC 2016-17 Challenge, Velocity Vortex, a white beacon would light up with either red or blue LEDs from the inside. If the light was on, the light would reflect white back onto the color sensor and not the red or blue. The light should be turned on if it wants to see a full colored object such as a red or blue colored ball.
- The Sensor: The sensor has two different modes. These modes are active and passive mode. Active mode is when the light is turned on and reflects color back while the passive mode is when the light is off and reads only the external light and color that is being seen by the sensor.
- Red: The red wire is the +5 Voltage wire for FTC but is usually either +5 V or +3.3 V while some other Voltages can be permitted.
- Yellow: The SDA or SDL wire, Serial Data Line.
- White: The SCL wire, Serial Clock Line
- Black: Ground wire
Step 2: Software
I use Android Studio for this program as I use the Modern Robotics sensor for the FIRST Tech Challenge challenges each year.
This instructable will be showing how to program a Modern Robotics sensor in Android Studio who uses a version of Java but it would be similar in other programming languages.
Step 3: Naming Your Sensor
So once you get your color sensor, you first have to put it into the public class in order for the program to recognize that the color sensor is there. I have named it "sensorColor" but this name can be anything that you desire.
*In my program, I use two servos to test how the sensor works. These sensors are not necessary if you only wish to see the telemetry.
Now that you have named the sensor in your program, you have to name the sensor in the hardware map. The hardware map is where you will name and access the sensor other than the program. For instance, in FTC, the hardware map is where you name all of the different sensors, motors, and other various things on your robot for the robot to recognize it from the code.
Step 4: Converting From RGB to HSV
You then have to convert your color sensor value of RGB to HSV.
If the sensor reads it as RGB (Red, Green, Blue), it reads the three colors from 0 to 255 with each number creating a different combination of colors that the colors can create if mixed.
If the sensor reads it as HSV (Hue, Saturation, Value) with the Hue value from 0 to 360 and the saturation and value being from 0 to 1. These values allow you to determine the color of an object with a color wheel with the Hue value, the saturation being the intensity of the color that the Hue sees, and the value being how bright the color or light is.
Converting the colors to HSV from RGB is important because it allows you to compare how the same colors can be seen in different lightings and different variations of the color being shown. RGB only allows you to see the color that is being shown (basically the Hue).
You can do this such as shown in the code.
The red, green, and blue values can then be added to the telemetry so you can see what values the color sensor is reading.
*I understand that my code has an error with "telemetry.addData("Green") ", it should say "sensorColor.green(), instead of blue.
Step 5: Testing the Sensor
Once you have your color sensor set up in the telemetry and named in the code, you can test and program the color sensor.
You can do this by finding a certain value of different colors by combining the different values of red, green, and blue.
You can then make an if, else statement to test it such as my code or some other types of ways to test it. When testing the different if, else statements, you can make the values go in between two colors such as it has to be lower than the value of 1 red and be greater than the value of 4 blue. This can be used as an or statement as well.
Step 6: Active Vs. Passive
Active mode means that the color sensor currently has the light on.
Passive mode means that the color sensor currently has the light off.
To turn the LED off and on, you have to type "color_sensor.enableLed(true); " for it to be on and "color_sensor.enableLed(false);" for it to be turned off.
The color sensor should automatically default to the active mode.
Step 7: Contact
If any questions occur while trying to get the color sensor to work, feel free to email me at email@example.com