NXT Sensors - Adventures in Color Detection
I was recently playing with the T-56 Robotic Arm (from the Mindstorms Kit). My son (he's 5) built about 65% of the robot.
We created the default program… it grabs a ball, and if it is red, it turns and drops it on the ground. If it is blue, it puts the ball back on the stand.
My son wanted to try some other colors with it. So we started with the Red and Blue ball, and added a Green ball, a Yellow ball and an
On to the Adventure!
TIP: Check your light source first, since different amounts of light will give you a different reading.
If possible, try and use colors that are farther apart on the color spectrum. Close colors often have a close light value, and even that can vary slightly if your object is moving or the reading is not taken in the same light every time.
We used the colored balls and came up with the following readings:
- Blue = 21
- Red = 57
- Green = 47
- Yellow = 60
- Orange = 53
As you can see, many of the colors are close in their readings on the NXT Light Sensor. This makes determining the colors a bit tricky. Furthermore, the NXT Light Sensor uses a red LED to illuminate the object when it takes a reading. This frequently made the yellow ball register as red. And the red ball was sometimes identified as orange.
When we finished, we used the blue, green, yellow and orange balls. The program would pick up a ball and say the color. If it was yellow, it would turn to the 2nd stand, say “Watch Out!” and drop the ball. Any other color and the arm would just say “Whoops!” and drop the ball on the original stand.
Nothing super fancy, but my son liked it. He kept running it over and over and just changing the balls.
I plan on trying a different programming environment soon. The LEGO stuff works good for the simple projects, but after 4 color choices, a couple of sound effects and moving the motors… I ran out of space on the NXT brick. :(