POR-6 (robot programing and simulation for color identification)
The document outlines a project for color identification using Arduino, detailing the setup and code necessary to read RGB values from a color sensor. It includes instructions for calibrating the sensor and defining colors based on specific RGB thresholds. The project also involves displaying the detected color on an LCD and controlling an LED accordingly.
POR-6 (robot programing and simulation for color identification)
The document outlines a project for color identification using Arduino, detailing the setup and code necessary to read RGB values from a color sensor. It includes instructions for calibrating the sensor and defining colors based on specific RGB thresholds. The project also involves displaying the detected color on an LCD and controlling an LED accordingly.
Objective:- Rob
. Ot Pro,
grammi .
Arduino Code: ming and simulation for colour identification
The first thing to define is the
so fie
Pins SO and SU are used for hat een Hing as defined at the table showed above
sensor readings for various fr caling the output frequency is useful to optimize the
SI. both in HIGH ( 100%) “Meney counters or microcontrollers. We will set SO and
digital Write(s0, HIGH),
digitatWritets HIGH).
Next thing to do is to s
we use the control ning i Color to be read by the photodiode (Red, Green, or Blue).
setting the $2 and $3. in S3 for that. As the photodiodes are connected in parallel,
LOW and HIGH in different co,
showed at above table,
binations al ows you to select different photodiodes, as
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
red = pulseln(outPin, LOW);
Reading RED component of color digital Write(s2, HIGH);
digital Write(s3, HIGH);
gm
eln(outPin, LOW);
Reading GREEN component of color digital Write(s2, LOW);
digitalWrite(s3, HIGH);
blu = pulseIn(outPin, LOW): Reading BLUE component of color
On the final code, we wil read a few times each one of the RGB components and take an
average, $0 we can reduce the error ifone of the readings is bad
Once we have the 3 components (RGB), we must define what color is that. The way to do
itis to previously calibrate the projet. You can use a known colored test paper or object
and read the 3 components generated
void getColor()
Department of Mechanical Engineer
Faculty of Engineering
Medi-Caps University
1—_________ __| Experiment no -
| RAICO34 and simula Page 2 of 4
| for colour identification
readRGB();
if (red > 8 && red < 18 && gm >9K& gm<19 && blu> 8 && blu < 16) col
"WHITE"; i
<
else if (red > 80 && red < 125 && gm > 90 &K gin < 125 &K& blu > 80 KK blu
color ="BLACK"; set
lu
else if (red > 12 && red < 30 && gin > 40 && gm < 70 && blu > 33 &&
color .
= "RED";
& blu < 85)
else if (red > 50 && ted <95 && gin > 35 & grn < 70 KK blu > 45 &
color
="GREEN":
blu < 38)
else if (red > 10 && red < 20 && gin > 10&K gm < 25 && blu> 20 && blu
color
= "YELLOW" .
P(red > 65 && red < 125 && gin > 65 && gm < 115 && blu > 32 && blu < 65)
BLUE";
else color = "NO_COLOR";
Here 6 colours are predefined: White, Black, Red, Green, Yellow, and Blue. As the
ambient light goes down, the parameters tend to go higher. rete:
Inside the loop(), it is defined to display the readings at LCD each 1 second
https://mjrobot.org/arduino-color-detection/
In simple we can do this method using Arduino and the Tinkercad simulation tool
First set up the circuit on Tinkercad by placing an RGB color sensor and an LED on the
breadboard, conneetng them tothe Arduino a shown inthe following diagram
Next open the Arduino IDE and upload the following code to the Arduino board Arduino
Code
// Libraries #include
#include
#include
GR Department of Mechanical Engineering
Faculty of Engineering
fi
sey) Medi-Caps Ui Iniversity[RA3CO34: Pri
re ‘COM: Principles of Rope
Experiment Title: Roker” boties Laboratagy ——"Tceceumeut nov
ory [Experiment no-5 |
for colour ident Togram
L See als Page 3 of 4
/ Initialize the LCD
‘Adafruit_RGBL
CDShield ted = A dat
Fitna it RGBLCDShield(;
dati |
Adafruit_ColorSensor colorsensor = Adaf
cau lafruit_ColorSensor();
(Initialize the LCD led.beging16, 2)
led.setBacklight(255, 255, 255), :
//Initialize the color sensor
colorSensor.begin();
void loop() {
/ Read the color from the sensor wint16_t red, green, blue;
colorSensor.getColor(&red, &green, &blue);
1/ Convert the color to a string and display it on the LCD char colorString[ 16];
sprintf(colorString, "#9%402x7402x%02x", red / 256, green / 256, blue / 256); led.clear():
Jed.setCursor(0, 0); Ied.print("Color: "); led print(colorString);
// Control the LED based on the color if (red > blue && red > green) {
i) Red a
analogWrite(3, 255):
analogWrite(5. 0):
analogWrite(6, 0);
| else if (green > red &&e green > blue) {
1/ Green analogWrite(3, 0):
analogWrite(5, 255):
analogWrite(6, 0):
} else {
Faculty of Engineering
Medi-Caps University| RA3CO34: Principles of Robotics Laboratory Experiment Noles
Experiment Title: Robot Programming and simulation | Page 4 of 4
for colour identification
// Blue analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(6, 255);
t
// Delay for a short time
delay(100);
t
Results:
Hence we have done the robot
programming and simulation for colour
identification