Introduction: Red Color Recognition Based Arduino Control(Using MATLAB and Arduino)

In this tutorial,we will demonstrate how to use color recognition to control any actuator connected to any digital pin of arduino uno,we have considered LED as an actuator in this tutorial which is connected to pin 13 of UNO. In this video we have drawn a symbol of Pi in red color which will be reconised.

This tutorial have two parts:

First Step: Programing Arduino UNO for recieving serial data from MATLAB

Second Step: Red color recognition and serial communication(MATLAB/ Image processing)

.

Step 1: Program Arduino UNO for Recieving Serial Data From MATLAB

First part is Arduino programming.

For establishing proper serial communication between arduino and MATLAB , we need to first program arduino for recieving serial data as it will act as reciever of serial command. We have assigned 2 values for different cases, whenever arduino will recieve value 100 it willl turn ON the LED and 101 will turn OFF the LED(You can also assign your desired value). Make sure to assign similar values while programming serial communication in MATLAB(will be discussed in step 2). Upload the program which is mentioned below:

const int ledpin=13;int recValue;

void setup()

{

Serial.begin(9600);

pinMode(13, OUTPUT);

}

void loop()

{

if(Serial.available()>0)

{

recValue=Serial.read();

if (recValue == 100) // If use will send value 100 from MATLAB then LED will turn ON

{ digitalWrite(ledpin, HIGH); }

if(recValue == 101) // If use will send value 101 from MATLAB then LED will turn OFF

{ digitalWrite(ledpin, LOW); }

}

}

Step 2: Red Color Recognition and Serial Communication(MATLAB)

First is, red color recognition and serial communication.

We will start with red color recognition, we have developed a real time red color tracking, which will trigger the LED to toggle as per conditions. Conditions which we have assigned are ,whenever there will be presence of one or more than one red colored object in the frame the LED wll turn ON otherwise LED will remain OFF. Color recognition algorithm also contains program for sending serial command to arduino as a if conditions. Basic algorithm for red color recognition and serial communication to send command to arduino uno is explaned in above images: The results of tracking of Pi drawn on white paper in RGB as well as Binary is also shown in above images: Red color recognition algorithm along with serial command sending to arduino uno code is attached as file below, open and execute this file in MATLAB.

Step 3: Results and Basic Information on How to Execute Above Steps

First upload the program mentioned in first step of this tutorial on arduino uno.

Second, open and execute the .m file attached in step 2.

Things to keep in mind.

1.Threshold value in MATLAB program may vary as per lighting conditions, if program did'nt work as mentioned try to tinker with theshold value for refrence see imae in this step.

2.Make sure to select correct COM port for serial communication.

3.Keep in mind to match the serial data value mentioned in MATLAB program and arduino program.

Results:

The video attached in this step demonstrates real-time red color tracking and binary result of red colored object tracking.

Thank you!

Automation Contest

Participated in the
Automation Contest

Pi/e Day Contest

Participated in the
Pi/e Day Contest

Coded Creations

Participated in the
Coded Creations