Spring 2017 BiPed – Color Sensor Experiment
By: Abraham Falcon (Electronics and Control)
Approved by: Alexander Clavel (Project Manager)
Table of Contents
Introduction
The electronics and control engineer job is to find the right equipment and test it for its project functionality. To make sure the biped can participate in the game it must have a color sensor to detect the red dots placed on the floor. This experiment was done to see if the adafruit color sensor can sense red and to discover what the best range of detection is. As per the requirements of our project, this test was able to verify that we were indeed able to detect dots as well able to detect the dots at the specified distance of 2mm.
Equipment
Material | Quality |
Arduino Uno (any family of Arduino) | 1 |
USB Printer Cable | 1 |
Breadboard | 1 |
Male to Male Jumper Wires | 4 |
Color Paper (Red)
(Any objects that is red in color) |
1 |
Table 1
Arduino Code
The code below is from adafruit which can be located in the reference section of this post. The purpose of the following code is to be able to give feedback on the raw data of the colors. We were able to test this by placing different colors under the sensor and observing the given data.
#include <Wire.h>
#include “Adafruit_TCS34725.h”
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
void setup()
{
Serial.begin(9600);
}
void loop()
{
uint16_t r, g, b, c, colorTemp, lux;
delay(25);
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
Serial.print(“Lux: “); Serial.print(lux, DEC); Serial.print(” – “);
Serial.print(“R: “); Serial.print(r, DEC); Serial.print(” “);
Serial.print(“G: “); Serial.print(g, DEC); Serial.print(” “);
Serial.print(“B: “); Serial.print(b, DEC); Serial.print(” “);
Serial.print(“C: “); Serial.print(c, DEC); Serial.print(” “);
Serial.println(” “);
}
This code using the raw data from previous code from Adafruit will now check for red color since it is part of the requirements for the BiPed.
#include <Wire.h>
#include “Adafruit_TCS34725.h”
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
void setup()
{
Serial.begin(9600);
}
void loop()
{
uint16_t r, g, b, c, colorTemp, lux;
delay(25);
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
float ColorAverage, RED, GREEN, BLUE;
ColorAverage = (r + g + b) / 3;
RED = r / ColorAverage;
GREEN = g / ColorAverage;
BLUE = b / ColorAverage;
if (RED > 1.4 && GREEN < 0.9 && BLUE < 0.9)
{
Serial.println(“RED Detected”);
}
}
Experiment
To perform the experiment, the color sensor was placed on the breadboard for easy connection. The color sensor itself has four connections and the Arduino was powered by the computer through USB connection. The four connections that are being used are SDA, SCL, Vin and GND. Vin and GND are connected respectively to the Arduino for 3.3 volts and ground. Below is how the color sensor is connected to the Arduino to the computer.
Figure 1
Figure 2 shows the mini breadboard we were using to test the actual sensing of the color red. There were various other objects of different sizes and colors that were used to see whether or not the sensor is was picking only red or if there were any errors of any kind. We did not want the sensor to pick up a bright orange when what we really wanted was red. We were able to verify that it only detected red and on any other color would not light up the LED counter.
Figure 2
To conduct this test, the red mini breadboard was placed on top of the sensor to detect red and to see how this color sensor performs. Figure 3 shows the set up and how the test was actually performed. This was the first step to show that the components were performing the way we wanted it. Once we had verified that it was picking up red and only counting the red objects we then moved on to trying to find the optimal distance.
Figure 3
Figure 4
Figure 4 shows the test that was done to find out the operational range of the color sensor. The setup was very basic in the way that the color sensor was connected to the Arduino and placed side ways. A tape measure was placed along side it to indicate distance. The red mini bread board was then placed at varying distances. We initially put the sensor an inch away from the red object, but nothing was detected. From there we continuously moved the red object an eighth of an inch closer and closer until the red color was detected. The resulting distance happened to be about half an inch. This distance is well over our required detection distance of 2mm.
Analysis/Data
Table of Results
Color Sensor | Operating Voltage (Volts) | Operating Range for Biped (Inch) |
Adafruit RGB Color Sensor | 3.3 V | 0.5 in |
Table 2
Raw Color Data
Figure 5
Figure 5 shows the raw data for the colors, which are red, green, and blue. This sensor detects and uses this raw data as a reference code to be implemented to detect red for biped function. The raw data shown is sensing red green and blue, but the point was to take account of the red values. To do this we took the red, green, and blue raw values to a sum which will be called the average. So we then used the total raw values and then divided the specific color raw values to get the ratio of those colors from the sensor raw data. Using this ratio, we can make conditions where it reads only red when these conditions are true. In the section of Arduino codes, the code for reading red is provided. This code will help detect red and to be use for biped main code.
Arduino Serial Monitor Test of Detection
Figure 6
Using the previous codes to detect red the red mini breadboard was detected and shown on the Arduino serial monitor. This code is successful for detecting red and will be used for biped main code.
Conclusion
Performing this color sensor experiment we can see that this sensor will operate successfully for the biped to participate in the game. This sensor will help the biped be able to read red dots placed on the floor. It also shows that the color sensor will perform well and beyond the range of what is actually required. In conclusion the tests were successful and showed that the mission is achievable.