Red Color Recognition based Arduino control(Using MATLAB and Arduino)

Written by: admin@makezilla

Picture of Red Color Recognition based Arduino control(Using MATLAB and Arduino)vlcsnap-2015-04-06-22h37m34s206.png

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

Picture of 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)

Picture of Red color recognition and serial communication(MATLAB)bw_red_detect.pngserial_tracking_img.jpgvideo_proper_img.jpgserial_com_img.jpgcolor recogn_img.jpg

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.

http://www.instructables.com/files/orig/F8Q/FJS5/I85QNLZA/F8QFJS5I85QNLZA.m

Step 3: Results and Basic information on how to execute above steps

threshold_value.png

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!

Leave a Reply