This project involves designing a GUI in MATLAB to control a DC motor and LEDs using a parallel port. The GUI allows the user to turn on and off the motor and LEDs by clicking buttons that correspond to ports connected to each device. The MATLAB code includes functions for the GUI interface and callbacks that get the button values, convert them to a decimal output, and send that value to the parallel port to control the devices. The project aims to demonstrate skills in MATLAB programming and understanding how to interface hardware using a parallel port.
1 of 8
More Related Content
ESL report
1. College of Engineering
Course: ESL
CId: 10938
Prepared by
Salman Khaliq Bajwa (3746)
Project Advisor
Engr. Mohazzab
College of Engineering
PAF ¨C Karachi Institute of Economics and Technology
Karachi
1
2. PREFACE
This project is a comprehensive study of the MATLAB, a programming language. It tells us the
use and commands of MATLAB. This project is intended to use in engineering and computer
science. This project utilizes electronic concepts that can be helpful in understanding the
electronic principles and the use of MATLAB. This project deals with the various number
circuits and used in electronic systems. This project provides a very deep understanding of
MATLAB software with standard circuit designing.
ACKNOWLEDGEMENT
I would like to express my gratitude to all those who gave me the possibility to complete this
project. I want to thank my course instructor Mr. Mohazzab Jawaid for giving me permission to
work on this project. Furthermore thanks to my engineering lab staff that gave and confirmed
this permission and encouraged me to go ahead with my project. I am bound to the Honorable
director of engineering for giving me such opportunity to work with our capabilities freely. I am
deeply indebted to Mr. Mohazzab Jawaid whose help, stimulating suggestions and
encouragement helped me in all the time of making this project. My friends from the Department
of engineering supported me in my project. I want to thank them for all their help, support,
interest and valuable hints. Especially I am obliged to my seniors. I also want to thank to our lab
in charge for all his assistance on the ministerial computer. Our teachers was of great help in
difficult times I will like to thanks each and every person, who helped and supported me and
gave time to this project.
2
3. Table of Contents
PREFACE ....................................................................................................................................... 2
1. Objective & Puposes: .................................................................................................................. 4
Objective: ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4
Purpose:¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4
2. Description:¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡..4-5
DC Motor¡¡¡¡¡¡...¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡..4
Parallel Port Interfacing:¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡..4
3. Working¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡..¡.5
4. MATLAB Program Code¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.7-6
5. GUI¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡..8
Conclusion
3
4. 1. Objective & Purpose:
Objective:
To design an application in order to control the DC motor and LEDs using GUI based MATLAB
program through Parallel Port.
Purpose:
To understand and be familiar of the commands of MATLAB software and the need and
importance of this software in industry.
2. Description:
A small description of this project is that we would be interfacing the dc motor and some LEDs
through parallel port using MATLAB software. Most of the coding will be done through
MATLAB. We will turn on and off the dc motor & LEDs. Some information about the ports and
components that I am using in this software is given below;
DC Motor:
A DC motor is an electric motor that runs on direct current (DC) electricity. DC motors are fairly
simple to understand. They are also simple to make and only require a battery or dc supply to
make them run.
Parallel Port Interfacing:
Parallel port is a simple and inexpensive tool for building computer controlled devices and
projects. The simplicity and ease of programming makes parallel port popular in electronics
hobbyist world. The parallel port is often used in Computer controlled robots, Atmel/PIC
programmers, home automation etc. It takes 5 volts. It can send a large amount of data at a time
but when we talk about the larger distances we have to look at the serial port. This is actually the
drawback of parallel port that we cannot use it for large data transmission, but wirelessly we can
do it.
.
4
5. Figure 1- Parallel Port
Figure 3- data transmission
3. Working:
I have made a GUI based project. How it works is that it actually takes the input from the
user and on and offs the DC motor and 3 LEDs. I am going to use four ports; port 1, port 2,
port 3, port 4 and port 5 for that. It is actually a series circuit. Port 2 is for DC motor and Port
3, 4 and 5 are for LEDs.
Step one of this project was to design a GUI for this project and then the second step was to
interface that GUI with my hardware.
5
6. 4. MATLAB Program Code:
function varargout = pin_by_pin(varargin)
%--------------------------------------|
% Programmer: Salman Khaliq Bajwa |
% Course: ESL |
% Id: 3746 |
% CId: 10938 |
% E-mial: damigo88@yahoo.com |
% Project: Parallel Port Interfacing |
%--------------------------------------|
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pin_by_pin_OpeningFcn, ...
'gui_OutputFcn', @pin_by_pin_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before pin_by_pin is made visible.
function pin_by_pin_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to pin_by_pin (see VARARGIN)
%*-*-*-*-*-*-*-*-*-*-*-*-
pp=digitalio('parallel','LPT1');
handles.dato=addline(pp,0:3,'out');
putvalue(handles.dato,0);
%-*-*-*-*-*-*-*-*-*-*-**-
% Choose default command line output for pin_by_pin
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pin_by_pin wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pin_by_pin_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
6
7. % Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pin_2.
function pin_2_Callback(hObject, eventdata, handles)
a=get(handles.pin_2,'Value');
b=get(handles.pin_3,'Value');
c=get(handles.pin_4,'Value');
d=get(handles.pin_5,'Value');
m=[a b c d];
out=binvec2dec(m);
set(handles.text1,'String',out)
putvalue(handles.dato,out);
% --- Executes on button press in pin_4.
function pin_4_Callback(hObject, eventdata, handles)
a=get(handles.pin_2,'Value');
b=get(handles.pin_3,'Value');
c=get(handles.pin_4,'Value');
d=get(handles.pin_5,'Value');
m=[a b c d];
out=binvec2dec(m);
set(handles.text1,'String',out)
putvalue(handles.dato,out);
% --- Executes on button press in pin_3.
function pin_3_Callback(hObject, eventdata, handles)
a=get(handles.pin_2,'Value');
b=get(handles.pin_3,'Value');
c=get(handles.pin_4,'Value');
d=get(handles.pin_5,'Value');
m=[a b c d];
out=binvec2dec(m);
set(handles.text1,'String',out)
putvalue(handles.dato,out);
% --- Executes on button press in pin_5.
function pin_5_Callback(hObject, eventdata, handles)
a=get(handles.pin_2,'Value');
b=get(handles.pin_3,'Value');
c=get(handles.pin_4,'Value');
d=get(handles.pin_5,'Value');
m=[a b c d];
out=binvec2dec(m);
set(handles.text1,'String',out)
putvalue(handles.dato,out);
7
8. 5. GUI of the project:
Figure 3- GUI
Conclusion
I can conclude that this project can be used for various purposes like for the interfacing of
many other things like home appliances, Industries etc. This project helped me a lot in
improving my typing skills and also my understanding the need MATLAB in market.
References:
[1 ]
http://www.mathswork.com
Topic: Parallel Port Interfacing | Visiting Date: 05/Feb/2011
? 1999-2010 mathswork.com Hong Kong Limited and licensors. All rights reserved.
[2]
http://www.wikipedia.com
Topic: Parallel Port | Visiting Date: 11/March/2011
?2002-2011, Wikipedia . All rights reserved.
8