Object Tracking Robot

47,507

412

99

About: 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. In the future, I want to start a company that creates new technology. Right now I ...

Intro: 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

All parts (without smartphone) costed $60:

- arduino LINK TO BUY

- smartphone with android LINK TO BUY

- robot chassis LINK TO BUY

- cables to connect it

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

- bluetooth module HC-06 LINK TO BUY

- If you want to do PCB go to step 4

Step 2: 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 = Color.red(pixel);

int blueValue = Color.blue(pixel);

int greenValue = Color.green(pixel);

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

points++;

all_x = all_x + x;

all_y = all_y + y;

}

y++;

}

x++;

y = 0;

}

y = 0;

x = 0;

x_center = all_x / points;

y_center = all_y / points;

Step 3: 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)

Needed parts to make PCB:

- Everything that was mentioned in first step

and

- 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() {
Serial.begin(9600);

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];


if(Serial.available()){

delay(10);

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

}
commandbuffer[i++]='\0';
bluetoothRead = (char*)commandbuffer;
length = bluetoothRead.length();


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

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

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;


Stop();

if(x < 40){
Left();

}
if(x > 140){
Right();

}
if(x < 140 && x > 40){
if(points == 1){
Forward();
}
if(points == 0){
Stop();
}
if(points == 2){
Back();
}
}
}
}
}


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

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

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 :)

Share

Recommendations

  • Optics Contest

    Optics Contest
  • Audio Contest 2018

    Audio Contest 2018
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge

99 Discussions

0
None
ebag1010

Question 4 months ago

Hello, I was also wondering about the connection between the Arduino and the Motor Control. If you could assist in anyway that would be great. Any other information regarding the connection of the compenents would also be appreciated. (I'm not using a PCB) My email is ebag1010@gmail.com, thanks.

0
None
AhlemK

Question 5 months ago on Step 7

please how can i edit the code source on android studio?

0
None
AmnaA16

5 months ago

Hey

What’s the value of R2 ?? In the diagram

0
None
saif102

5 months ago

hello mr Nikus the APK application is not working can you help me to solve this problem because it is very important step for my senior graduation project in order to accomplish it .

0
None
AhlemK

6 months ago

I just realized my project of the end of the year, a robot object follower (red color), I am interested in your project , first, how can i implement the application code in android studio? and the second if i use shield to control the engines how will it be the arduino code?i'm very grateful

1 reply
0
None
BikashK18

7 months ago

Hi! Nikus. You have been an inspiration to me. And I have been trying to use the same method for object detection for a while now; I guess I haven't search hard enough. But, I would be very grateful if I could know how to modify the opencv program to detect bright colors with a predetermined maximum cross-section area so that it could ignore the background. Also, I would like to know where to write the code and how to link with the arduino mega 2560. I would be indebted to you. Please contact me at bikashkangabam2@gmail.com

0
None
YeT7

7 months ago

Hello, I am trying this project and i can't download the android source code. Would you kindly email me the android source code. My email is "yelintun1996@gmail.com". Thank you so much.

0
None
Ryuuaoi

7 months ago

How do you know if the robot is working? I think I have everything set up and the code downloaded but I don't know how to work it. Please help me. Thank you very much!

0
None
Ryuuaoi

Question 7 months ago

Hello, I am trying to do a similar project and was just wondering what the hook-up is with arduino uno and a hb-25 motor control. Can you help me? Thank you so much. My email is rachellinwarren16@gmail.com

0
None
Doni MartG

7 months ago

Hi nikus. i want to know what 7000 mean in android code

int direction = 0;

if(points < 7000){

//forward

direction = 1;

}. thank you

0
None
iozsi

10 months ago

Hello. I noticed that you do not use external quart to mount. Does it work with internal? How did you load the code on atmega? Thank you.

0
None
stark jose

1 year ago

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

Why?

0
None
AmalB14

1 year ago

sir,

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

please please help me

0
None
TirtoW

1 year ago

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

1485235208753-2078287132.jpg
1 reply
0
None
NikusTirtoW

Reply 1 year ago

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

0
None
z_huma

1 year ago

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

1 reply
0
None
Nikusz_huma

Reply 1 year ago

Hi!

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!

0
None
JohnyM7

1 year ago

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 neotrix20@gmail.com

Thanks in advance

0
None
Michelle AnneG

2 years ago

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 :)