loading

the objective of this instructable is to bridge the gap between image processing and robot manipulation . yes , they are two different field but we can combine them to do some amazing things.this instructable is just a basic process of interfacing two different fields . it illustrates how to communicate between a computer application to an hardware .

Step 1: Components Needed

1.arduino

uno (or some other microcontroller board)

2. MATLAB software

3.webcam

4.l293d board

5.things needed for building a bot(chassis,wheels,motors,caster wheel,wires,battery)

i am just going to cover how to get information about the position of the object and how to follow it . since details about building bots are available every ware on internet..................... i am going to leave that part to u

Step 2: Code

i have attached both MATLAB and ARDUINO code in this slide . just download it and follow the next step

Step 3: Arduino Setup

this is just simple step. open the code in arduino ide and click upload .. that's it .. (i will explain how this codes work in further steps don't worry )

PINOUTS

right side positive =11

right side negative = 10

left side positive = 9

left side negative = 6

all these pins are pwm enabled . you can modify this same code if u wnt to add any kind of control algorithms like PID,FUZZY,NEURAL etc

these pins should go to the driver board because arduino cannot supply enough current for driving motors from your usb port .

positive and negative are chosen in a manner if i connect 5v to positive and 0 to negative the bot will move forward

Step 4: Matlab Setup

same as arduino . open this M file in matlab and select your current directory in which you have your Mfile as the working directory . after connecting your webcam and arduino (set your comport of arduino ) click run .. you should see it working . if some problem occurs with communication then check your serial port . if some problem states about image , then it is your webcam change the number ......... check code explanation slide for details

Step 5: Code Explanation

MATLAB

INITIALIZATION BLOCK

- in this block of code we initialize the webcam ,serial port communication and the video itself

- vid = videoinput('winvideo',1); if you are using two are more webcam simultaneously in your computer at a time , then you nave to pay attention to the number (1) in that line . change this number if you have any trouble in getting the video feed from your webcam (1,2,3.....)

- s = serial('COM68','BaudRate',9600); change (COM68 ) to appropriate COM number of your arduino uno board

since we are going to communicate with arduino through serial ... this is mandatory

BEGINNING

- since the project is intended to explain things about image processing . i kept while(i<=300) which will stop the process after 300 iteration . but , if you want to extend it for long go with while(1==1)

- data = getsnapshot(vid); this line gets a snapshot from the video feed and stores it in a variable called date for doing some math on it ( ya .. there is a lot of math coming .. be ready !!!!!!!!!!)

- diff_im = imsubtract(data(:,:,1), rgb2gray(data)); this finds out the portion of red color from the image and subtract it from the rest of the image to form a mask

- diff_im = im2bw(diff_im,0.18); this convert the normal image to binary (0,1) image

- bw = bwlabel(diff_im, 8);

stats = regionprops(bw, 'all');

it forms a boundary around the mask and lable them with identification number and gather informations about it

INFO GATHERING BLOCK

- for object = 1:length(stats)

obj_found=1; bb = stats(object).BoundingBox; bc = stats(object).Centroid; ar=stats(object).Area; rectangle('Position',bb,'EdgeColor','r','LineWidth',2) plot(bc(1),bc(2), '-m+')

gathers different information adout the red object like (BOUNDINGBOX,CENTER ,AREA )

DISTANCE and SIDE FINDING

_ this block deals with the math of finding the distance and side or orientation of the object which it is looking .. math .....................

go thorough this block once are twice to understand what it does

basically ir finds the area to calculate the distance and center to find right and left side

Step 6: Code Explanation

ARDUINO

this is simple ... setup the pins , wait for serial commands . on receiving a valid command , arduino sends pulse to motors to move the bot. this movement will cause the cam mounted on top of the bot to move and position the object in center ....

Step 7: Conclusion

the purpose of this instructables is not to teach the entire thing attached to image processing , just to kick start the interest in us to start exploring this vast discipline

<p>can u tell me the procedure how toconnect the webcam with arduino indirectly????</p>
<p>hey man respond</p>
<p>hi sorry for late replay</p><p>you cant connect webcam directly to arduino . if you are using any single board computer like raspberry pi, beaglebone black .... you can directly connect it and use opencv for image processing</p>
<p>how to connect the web cam to the robot</p>
Hi, can i have images on how to set up Arduino with the webcam, how do you do the wiring between the Arduino and the webcam

About This Instructable

7,007views

30favorites

More by ysingh7:Raspberry Pi Rover (simple) Using Rpi , Arduino object tracking bot using image processing Self Aiming and Engaging gun 
Add instructable to: