You are on page 1of 13

2-D PLOTTER

MECHATRONICS LABORATORY PROJECT

Submitted by

GROUP-E2
NAME ROLL NO.
CHANDRAJEET PRATAP SINGH 16ME63R52
PAWAR MITESH ROHIDAS 16ME63R45
RINTU SASMAL 16ME63S02
TANMAY SAHA 16ME61R01
GOLU PATEL 16ME63R63

INDIAN INSTITUTE OF TECHNOLOGY, KHARAGPUR


KHARAGPUR, PASCHIM MEDINIPUR
WEST BENGAL 721302
SESSION 2016-2018
Isometric view

Top view

1
Side view

Front view

2
Components:
Serial No. Item Name Specification Quantity
1 Lead screw Length :65mm
Diameter :3mm 2
Pitch :3mm
2 Stepper motor Phase :2
Wire :4 2
Voltage : 4-9V DC/500 mA
Step angle :180
3 Servo motor Operating voltage: 4.8 V (~5V)
Operating speed : 0.1 s/60 degree 1
Weight : 9 gm.
Stall torque : 1.8 kgf·cm
4 Wooden ply 150mm×120mm×15mm 2
5 Aluminium sheet 5mm×5mm 1
6 Arduino UNO Single broad ATmega168 1
microcontroller
7 Motors driver Model :L293D 2
8 Breadboard 5.5cm×17cm 1
9 Jumper wires Model : 22AWG(with solid tip) 25(approx.)
10 Bolt Length :80mm
Diameter :5mm 8
11 Nut Hexagonal 5mm internal diameter 12
12 Pen holder 1
13 Pen 1

3
Working Principle:-
The assembly of motor and lead screw is mounted on the wooden ply as shown in
figure. The two axis are defining as the horizontal bed as x axis and vertical bed as
y axis.

The servo motor attached moves the horizontal bed in vertical direction giving
engagement and disengagement movement to pen.

Aluminium sheet is attached to horizontal bed and holder is attached to vertical


bed.

1) The image is given to MATLAB code then image processing is done.


MATLAB code create the matrix in the x,y coordinate saved in text file.
2) Arduino reads the x,y points and drives the motors respectively and draw
sketch.

4
MATLAB CODE
ALGORITHM
ARDUINO CODE
ALGORITHM
/* ARDUINO CODE */

#include <Stepper.h>
#include <Servo.h>

Servo servoMotor;

int angle = 0;
int dgre = 20;
int delayServo = 10;
int i = 0;
int maxStep = 250;
int count=0;
int delayStep = 5;
int a, b, l, m, x = 0, y = 0;
int zero = 240;

Stepper stepperMotor1(maxStep, 4,5,6,7);


Stepper stepperMotor2(maxStep, 8,9,11,10);

void setup(){
Serial.begin(9600);
servoMotor.attach(12);
}

void loop(){
while (Serial.available()>0){

setZero();

a=Serial.parseInt();
b=Serial.parseInt();
l=a-x;
m=b-y;

if (Serial.read() == '\n'){
1
if (l==0 && m==0){
for(angle=dgre; angle>0; angle--){
servoMotor.write(angle);
delay(delayServo);
}
}
while (count<abs(l)){
if (l>0){
stepperMotor1.step(1);
}
else {
stepperMotor1.step(-1);
}
count++;
delay(delayStep);
}
count=0;
while (count<abs(m)){
if (m>0){
stepperMotor2.step(1);
}
else {
stepperMotor2.step(-1);
}
count++;
delay(delayStep);
}
count=0;
if ((abs(l)+abs(m))>1){
for(angle=0; angle<dgre; angle++){
servoMotor.write(angle);
delay(delayServo);
}
}
Serial.println(1);
}
x=a;y=b;
Serial.flush();
}
}

2
void setZero(){
while (i<1){
for(angle=dgre; angle>0; angle--){
servoMotor.write(angle);
delay(delayServo);
}
count=0;
while (count<zero){
stepperMotor1.step(-1);
count++;
delay(delayStep);
}
count=0;
while (count<zero){
stepperMotor2.step(-1);
count++;
delay(delayStep);
}
count=0;
i++;
}
}

3
%% MATLAB CODE

function final_arduino(im_read)
tic;

imageMatrix = imread(im_read);
[a,b,c] = size(imageMatrix);
compMatrix = 80*ones(a,b,c);
BnWMatrix = imageMatrix>compMatrix;
BnWMatrix = 255*BnWMatrix;
[a,b,~] = size(BnWMatrix);
image(BnWMatrix);
matrix1 = zeros(a*b,2);
inc = 1;
x = 1; y = 1;

%% Loop until all zeros are covered


for z=1:a*b

%% Finding cooredinates of all zeros


matrix=zeros(a*b,2);
zo=1;
for i=1:a
for j=1:b
if BnWMatrix(i,j,1)==0
matrix(zo,:)=matrix(zo,:)+[i j];
zo=zo+1;
end
end
end
if matrix(1,1)==0
break
end
compMatrix=ones(a*b,2);
compMatrix=matrix>=compMatrix;
[d,~]=size(compMatrix);
f=0;
for i=1:d
if compMatrix(i,1)==1

4
f=f+1;
end
end
matrix=matrix(1:f,:);

%% Finding nearest zero


s=a*b;
for i=1:f
p=(matrix(i,1)-x)^2+(matrix(i,2)-y)^2;
if p<s
k=matrix(i,1);
l=matrix(i,2);
s=p;
end

end

%% Finding next nearest zero


i=1;
while i<=f
for j=1:f
g=matrix(j,1);h=matrix(j,2);
if (g==k&&h==l||g==k-
1&&h==l||h==l&&g==k+1||h==1+l&&g==k||g==k&&h==l-1)
matrix1(inc,:)=matrix1(inc,:)+[g,h];
k=g;l=h;
x=g;y=h;
g1=g;h1=h;
matrix(j,:)=[0,0];
BnWMatrix(k,l,1)=255;
inc=inc+1;
i=0;
break
end
end
i=i+1;
end

%% Add same number after every line


matrix1(inc,:)=matrix1(inc,:)+[g1,h1];
inc=inc+1;
end

5
%% matrix1 size reduction
compMatrix=ones(a*b,2);
compMatrix=matrix1>=compMatrix;
[d,~]=size(compMatrix);
f=0;
for i=1:d-1
if compMatrix(i,1)||compMatrix(i+1,1)==1
f=f+1;
end
end
matrix1=matrix1(1:f,:);len=f;

%% Arduino control
arduino=serial('COM5','BaudRate',9600);
fopen(arduino);
try
for i=1:len
MAT=mat2str(matrix1(i,:));
try
fprintf (arduino , '%s\n' , MAT(2:end-1));
fprintf ('%d ',i);
fprintf ('%s\n', MAT(2:end-1));
y=fscanf(arduino,'%s');
BnWMatrix(matrix1(i,1),matrix1(i,2),3)=255;
BnWMatrix(matrix1(i,1),matrix1(i,2),1:2)=0;
pause(.001)
image(BnWMatrix)
catch ME
fprintf('ERROR: %s\n', ME.message);
break;
end
end
catch ME
fprintf ('ERROR: %s\n', ME.message);
end
fclose(arduino);
if i==len
fprintf 'DONE! GOOD JOB!\n';
else
fprintf 'Some error occurred\n';
end
toc;

You might also like