Introduction: Object Tracking Robot

Picture of Object Tracking Robot

Few weeks ago I thought to make robot that can track object with android phone. At the beginning I searched about it in google. I found some articles but none had source code of android app. My first thought it's "it too hard for me" and I gave up. But I could not stand that I can't make something that I want. So I tried again and after week of hard work with android code I finished my project.

Please if you like my project, vote for me in move it contest. Thanks!

Step 1: Parts

Picture of Parts

All parts (without smartphone) costed $60:

- arduino

- smartphone with android

- robot chassis

- cables to connect it

- H bridge for DC motors (I use pololu TB6612FNG)

- bluetooth module HC-06

- If you want to do PCB go to step 4

Step 2: How Does It Work?

Picture of How Does It Work?

The best way to make it, it's to use android phone with special app which check view from camera recognize position of red color and sends it to arduino over bluetooth. App uses openCV library to image processing. It calculate arithmetic average to check where is red color. Below I added piece of android code to see how it work:

bitmap = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(mRgba, bitmap);

int x = 0;

int y = 0;

int all_x = 0;

int all_y = 0;

while(x < 176) {

while(y < 144){

int pixel = bitmap.getPixel(x, y);

int redValue =;

int blueValue =;

int greenValue =;

if(redValue > 200 && blueValue < 70 && greenValue < 70){


all_x = all_x + x;

all_y = all_y + y;





y = 0;


y = 0;

x = 0;

x_center = all_x / points;

y_center = all_y / points;

Step 3: Connection

Picture of Connection

Above you can find schema with connection. In next step I added .sch and .brd file from eagle.

I added some jumper wires on the top of the H bridge to do PCB.

Step 4: PCB (optional)

Picture of PCB (optional)

Needed parts to make PCB:

- Everything that was mentioned in first step


- Atmega 8 or 128 or 328

-resistor 1,2 K Ohm

- LED diode (no matter which color)

- linear stabilizer with 5V output

- some female headers

- everything to do PCB read here

- Driller, soldering, etc.

Step 5: Program for Arduino

Arduino code is very basic. It gets data from serial and change it to numbers.

String bluetoothRead, Str_x, Str_y, Str_p;
int x ;
int y ;
int points;
int length;

int pwmMotorA=11;
int pwmMotorB=10;
int ForwardA=8;
int BackA=9;
int ForwardB=6;
int BackB=7;

void setup() {

pinMode(pwmMotorA, OUTPUT);
pinMode(ForwardA, OUTPUT);

pinMode(BackA, OUTPUT);
pinMode(pwmMotorA, OUTPUT);

pinMode(ForwardB, OUTPUT);
pinMode(BackB, OUTPUT);

analogWrite(pwmMotorA, 140);
analogWrite(pwmMotorB, 140);


void loop() {
int i=0;
char commandbuffer[200];



while( Serial.available() && i< 199) {
commandbuffer[i++] =;

bluetoothRead = (char*)commandbuffer;
length = bluetoothRead.length();

if(bluetoothRead.substring(0, 1).equals("x")){

int i=1;
while(bluetoothRead.substring(i, i+1) != ("y")){

Str_x = bluetoothRead.substring(1, i);
x = Str_x.toInt();

Str_y = bluetoothRead.substring(i+1, length -1);
y = Str_y.toInt();

Str_p = bluetoothRead.substring(length - 1, length);
points = Str_p.toInt();

i = 1;


if(x < 40){

if(x > 140){

if(x < 140 && x > 40){
if(points == 1){
if(points == 0){
if(points == 2){

void Left(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, HIGH);

digitalWrite(ForwardB, HIGH);
digitalWrite(BackB, LOW);


void Right(){

digitalWrite(ForwardA, HIGH);
digitalWrite(BackA, LOW);

digitalWrite(ForwardB, LOW);
digitalWrite(BackB, HIGH);


void Forward(){
digitalWrite(ForwardA, HIGH);
digitalWrite(BackA, LOW);

digitalWrite(ForwardB, HIGH);
digitalWrite(BackB, LOW);

void Back(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, HIGH);

digitalWrite(ForwardB, LOW);
digitalWrite(BackB, HIGH);

void Stop(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, LOW);

digitalWrite(ForwardB, LOW);
digitalWrite(BackB, LOW);

Step 6: Android App

Picture of Android App

Instruction how to install app:

1. the first step is download FollowBot.apk file

2.Send apk file to your phone

3.Open file manager and find FollowBot.apk file

4.Click on it and click install (if you have enabled the option to install applications outside the google play you need to turn it on)

5.You have finished the installation, you can run the application

Step 7: Android App (source Code)

Bellow I added source code of my app. This app uses simple bluetooth communication to send data to arduino. OpenCV library is very simply, at the beginning I had some problems with use it but I read about it on internet and easily understood everything. If you have problems with understanding the code, leave comment or send PM.

Step 8: Conclusion

Picture of Conclusion

So at the end I can say, that my project works great and that my first thought: "it's too hard for me" was very, very bad.

Any comments welcome. If you have problems, leave a comment and I will try to help you.

Sorry for my English :)


stark jose (author)2017-09-11

Sir I did everything as you said but the app isn't working


AmalB14 (author)2017-04-06


can you please explain logic of how the car is turning using arduino program i can understand the logic

please please help me

TirtoW (author)2017-01-23

Thanks Nicholas , it's chase red object , need bright red or enough light for camera to recognize and follow ..when I move the red object , my robot make cirlcle move, like trying to find the object . I was using promini and powering all boards with 5v ubec & 2s lipo

Nikus (author)TirtoW2017-03-08

Congratulations! It's nice to that somebody made my project. Thanks a lot for picture!

z_huma (author)2017-03-08

hi Nikus, can i track a shoe so it can follow a human being..
hoping for your reply.

Nikus (author)z_huma2017-03-08


Yes, you can if your shoes are red or orange. You can also always change color to follow in code of app. Thanks for comment!

JohnyM7 (author)2016-11-25

its a verry cool project....can it be modified to send data over wifi ... i'm tryng to make it work on a nodemcu esp8266 .. and i cant make it work...or if it can send data on local web srver. can u help me... my email is

Thanks in advance

Michelle AnneG (author)2016-10-08

hi Mr. nikus i was wondering why you put x < 140 && x > 40 for forward .

I hope I can get a reply from you thank you :)

Nikus (author)Michelle AnneG2016-10-08

Hi, to keep some distance from object if there are too many red pixels robot need to go back if there are less it need to go forward.

Michelle AnneG (author)Nikus2016-10-12

Hi mr. Nikus thank you for your reply :). I am using this for my project in school and i have one problem i hope you can help me . My professor wants to run this android app in my phone but it doesn't work . How can I run this app in my samsung prime lollipop processor. I badly needed your answer I might get failed if I haven't accomplish it :( . I hope I can get another reply thank you very much :)

Nikus (author)Michelle AnneG2016-10-12

it's possible that this app woudn't work on lolipop and above because of old opencv library. I haven't time for fixing this app and this opencv library for android is let's say not so good to implement. I will see what I can do I thinking about new app made in unity but I can't promise anything. So if you can try with older smartphone (jelly bean works perfectly)

Michelle AnneG (author)Nikus2016-10-12

Thank you for your another reply mr. Nikus :). I highly appreciate your help . I was thinking of re-making your app I will use a higher version of openCV I would like to ask permission if you let me re-do it. :)

Nikus (author)Michelle AnneG2016-10-14

Hi! Yes of course, you can! But I want to ask you something:

1. When you will finish this app and it will work can you send it to me? And if you agreed I will add it to this project

2. Don't call me mr please. I am feeling old when somebody call me like that :)

Good luck!

Michelle AnneG (author)Nikus2016-10-31

Nikus sorry to disturb you again but I would like to ask what is the purpose of "points" there ? And how can you get it ?
I'm looking forward for your reply thank you very much :)

Nikus (author)Michelle AnneG2016-11-03

We need to know how many points are red for calculating average all red pixel positions in the image. We count that with arithmetic average.

all red x position/points = average red position

all red y position/points = average red position

I hope this is clear if not post a comment and I will try to explain that in other way

Michelle AnneG (author)Nikus2016-11-07

Yes I get it thank you very much . Your project helps me a lot :)

Michelle AnneG (author)Nikus2016-10-15

oh I'm sorry I realized I'm older than you LOL yes sure if I can do it I will send it you thank you very much :)

LuisO3 (author)Michelle AnneG2016-10-08

'cause is like say the program, hey this is the center, so follooowwww that redd ballll xD LOOOL saludos

LuisO3 (author)2016-11-05

Nikus pls. upgrade the app for android to make use this on lollipop or marshmallow PLS PLS PLS PLS.. i need it :(... i can give you a coffee cup :)=

LuisO3 (author)2016-10-08

Hi, bro, the android app doesn't work in Note 5 (android 6.0.2) can you upgrade the app pls, this is problem with compatibilitie i think. tanks for this great proyect, my son's LOVE IT

AhmetK1 (author)2016-10-06

hi nikus nice project

can you send me the application apk with file "gradle".

this is my mail:

Ekstravagansa (author)2016-07-28

hi nikus, can u help me to solve this problem?

Syaifudin10 (author)2016-07-26

Hi Nikus, your robot very cool

can you send me the application apk with file the application apk, so that i can understand the application in eclipse. I'm newbie

this's my email

Thanks Nikus.

HassanS58 (author)2016-06-15

hi nikus nice project

can you send me the application apk with file "gradle".

this is my mail or

MechEngineerMike (author)2015-06-07

Cute! I'd love to set this up to chase my dog around haha. Seriously though, I would have been intimidated by the phone interface part. Good job!

Nikus (author)MechEngineerMike2015-06-08

Thank you! :)

jeffriwahyu (author)Nikus2016-05-29

Sir i have problem with your Followbot.apk. it's not responding with my phone while i connect to HC-05

DwisnantoP (author)2016-05-23

Great Job, I try your project, but i have problems to resolution camera smartphone, how to change/edit resolution code in this project??? i hope your answer..

Nikus (author)DwisnantoP2016-05-24


Thanks, you can change resolution right here:

mOpenCvCameraView.setMaxFrameSize(176, 144);

You can find it in OnCreate method in cameraactivity. 176 is width and 144 is height.

DwisnantoP (author)Nikus2016-05-25

sorry, i cant get thats file code.... please your help me, where i can get that's file code???? (File name)

Nikus (author)DwisnantoP2016-05-25

Firstly you need to learn something about android programming and then you can start to edit this code. You need to download eclipse/android studio load my project, edit files and export new apk.

DwisnantoP (author)Nikus2016-05-25

Thanks, i will try this.

DwisnantoP (author)DwisnantoP2016-05-25

whats's version android your aplication followbot.apk??

DwisnantoP (author)DwisnantoP2016-05-27

what's your version open cv for to creat and build apk?

BuiS2 (author)2016-03-24

Can you help me? why in your project has this line "import com.example.ball3.R;" ??

BuiS2 (author)2016-03-24

Can you give projcet in eclipse using openCV library?

Thanks much in advance.

Venkateshwar RaoH (author)2016-03-15

Great Work !

I am planning to use Uno, Arduino motor shield for this. I do have other components that you mentioned. Can you please help me with the connections and code changes ?

Thanks much in advance.


KelvinL3 (author)2016-03-11

awesome project, really nice.

Hai , i would like to ask for some suggestion from you on how to detect a small insect, for example cockroaches and spiders. I plan to build a automated insect trap robots using arduino, however i am a beginner in robotics, hope you can give some tips on me.

Thank you in advance

From: Kelvin

me email:

rsoni13 (author)2016-02-01

can me to make..this....

rsoni13 (author)2016-02-01

hey its nice...

HercieFaeC (author)2016-01-21

Hi ! I just wanna ask u about the connection of arduino board and the ATMEGA8 because its not shown in the schematic diagram u posted.

(waiting for ur response) THANKS :)

pgurudatt (author)2015-12-29

Hey where do u stay in Poland? do u stay in warsaw?? where are the local shops here?

Nikus (author)pgurudatt2015-12-29

No I'm from Bytom. But Warsaw is the capital so I hope you will find there some shops.

JaccoV (author)2015-11-06

Very nice tutorial. Missing some parts about OpenCV. Maybe some explanation about it. But it is very clear.

mddy (author)2015-11-02

Can i use Arduino UNO (Atmega 328) direct ??
i know i do this but after that what is the procedure with connection and i also want to know what is this at the right side of IC in green cooler is this moter draver ??

L298N, HC-09 Arduino UNO
please response me as soon as possible...

JaccoV (author)mddy2015-11-06

You can use the components in your picture. Its not very difficult to setup. Contact me.

sebaolifre (author)2015-10-01

Hey I need some help with project. i'll pay good ... ? i want to make a rc plane that has a object recognition and following that object (car, other rc plane, ...)

whatever you need i'll provide

JaccoV (author)sebaolifre2015-11-06

I can help you with this for free.

JaccoV (author)sebaolifre2015-11-06

I can help you with this for free.

PauloC20 (author)2015-10-14

How do I put the Open cv Source code in the Android app ?

About This Instructable




Bio: Hi, my name is Nikodem Bartnik. I live in Poland, I'm 18 years old. I like to program and create robots, devices and things ... More »
More by Nikus:Very Simple Line Follower for BeginnersDuktig - Personal AssistantUseful 3D Prints: Bathroom
Add instructable to: