final report on gui based device control using matlab

64
GRAPHICAL USER INTERFACE (G .U. I) BASED DEVICE CONTROLLER USING MATLAB MAJOR PROJECT REPORT Submitted in partial fulfillment of the Requirement for the award of the degree of BACHELOR OF TECHNOLOGY IN ELECTRICAL AND ELECTRONICS ENGINEERING (UNDER THE GUIDANCE OF Dr. Y. R. SOOD) BY Vandana Sharma (11273) Rohit Pandey (11236) Palak Sinha (11234) Rajan Chauhan (10225)

Upload: palak-sinha

Post on 17-Jul-2015

1.000 views

Category:

Engineering


2 download

TRANSCRIPT

Page 1: Final  report  on  gui based device control using matlab

GRAPHICAL USER INTERFACE (G .U. I) BASED DEVICE

CONTROLLER USING MATLAB

MAJOR PROJECT REPORT

Submitted in partial fulfillment of the

Requirement for the award of the degree of

BACHELOR OF TECHNOLOGY

IN

ELECTRICAL AND ELECTRONICS ENGINEERING

(UNDER THE GUIDANCE OF Dr. Y. R. SOOD)

BY

Vandana Sharma (11273)

Rohit Pandey (11236)

Palak Sinha (11234)

Rajan Chauhan (10225)

Page 2: Final  report  on  gui based device control using matlab

DEPARTMENT OF ELECTRICAL & ELECTRICAL ENGINEERING

NATIONAL INSTITUTE OF TECHNOLOGY, HAMIRPUR (H.P)

CANDIDATE’S DECLARATION

I hereby certify that the work which is being presented in the major project titled “GUI

Based Device Controller Using MATLAB” in partial fulfillment of the requirements for

the award of the Degree of Bachelor of Technology and submitted in the Electrical and

Electronics Department, National Institute of Technology Hamirpur, is an authentic

record of my own work carried out during a period from August 2014 to DEC 2014

under the supervision of Dr. Y.R. SOOD, Professor, Electrical and Electronics

Department , National Institute of Technology, Hamirpur.

The matter presented in this project report has not been submitted by me for the award of

any other degree of this or any other Institute / University .

VANDANA SHARMA (11273)

ROHIT PANDEY (11236)

PALAK SINHA (11234)

RAJAN CHAUHAN (10225)

This is to certify that the above statement made by the candidates is correct to the best of

my Knowledge.

Dr. Y.R. SOOD

Professor

Project Supervisor

Prof. Ashwani Chandel

HEAD OF DEPARTMENT

ELECTRICAL ENGINEERING DEPARTMENT

National Institute Of Technology Hamirpur, HP

Page 3: Final  report  on  gui based device control using matlab

ACKNOWLEDGEMENT

“Preservance ,inspiration and motivation have always played a key role in any venture .

It is not just the brain that matters most , but that which guides them . The character, the

heart , generous qualities and progressive forces. The metamorphosis took endless hours

of toil , had its moments of frustation , but in the end everything seemed to have sense”.

At this level of understanding it is often difficult to understand the wide spectrum of

knowledge without proper guidance and advice. Hence, we take this opportunity to

express our heartfelt gratitude to our project guide “DR .Y.R. SOOD” who had faith in us

and allowed us to work on this project .We would like to thank him for his immense

interest ,valuable guidance, constant inspiration and kind co-operation throughout the

period of word undertaken, which has been instruemnted in the success of our project .

We also acknowledge our profound sense of gratitude to all the teachers who have

been instruemental for providing us the technical knowledge and moral support to

complete the project with full understanding .We thank our friends and family for their

moral support to carve out this project and above all GOD for removing all hurdles in

the way .

VANDANA SHARMA (11273)

ROHIT PANDEY (11236)

PALAK SINHA (11234)

RAJAN CHAUHAN (10225)

Page 4: Final  report  on  gui based device control using matlab

ABSTRACT

Within the ambit of wireless technology ,apperance of the remote control based devices

and appliances have become the order of the day. It reduces human affords and

increases the efficiency. Every sector needs the automation, ranging from home to

industries. Automation Systems perform by allowing a number of to communicate with a

central controller which in turn communicates all information to the user or the owner of

the system as per the instructions and the structure of the system.The application of

such automation systems could be in areas such as heating ,lighting , defence , energy

management audio and vedio systems , health monitoring and entertainment .

Keeping all these facts in mind , this project propose a system which based on GUI

controlling through a PC (personal computer ) or LAPTOP. This project propose

automation of appliances like fan , bulb , motor , fire sensor. To automate these

appliances , we can use the different wireless communication media like infrared ,

Bluetooth , Radio Frequency , RFID , GSM, DTMF and GUI-MATLAB and

implemented with the help of microcontroller – 89c51 to compare the robustness and

effeciency of the output . To automate the industries

appliances we have to programme the CPU-89S52 In Embedded C . Being an emerging

area of research, a review of the most recent literature and implementation has been

carried out. Home Automation refers to the use of the computer and information

technology to control home appliances and features ( such as windows or lightning )

. Systems can range from simple remote control of lightning through to complex

computer /micro –controller based networks with varying degrees of intelligence

and automation . Home automation is adopted for reasons of ease , security and

energy efficiency .In modern construction in industrialized nations , most homes have

been wired for electrical power , telephones , TV Outlets (cable or antennas ) and a

doorbell . Many household tasks were automated by the development of

specialized appliances . For instances , automatic washing machines were

developed to reduce the manual labor of cleaning clothes , and the water heaters

reduced the labor necessary for bathing. Other traditional household tasks , like food

preservation and preparation have been automated in large extent by moving them

Page 5: Final  report  on  gui based device control using matlab

into factory settings , with the development of pre made , prepackaged foods and in

some countries , such as the UNITED STATES , increased reliance on commercial

food preparation services , such as fast food restuarants . Volume production and

the factory setting allows forms of automation that would be impractical or too

costly in a home setting . Standardize foods enable possible futher automation of handling

the food within the home. The use of gaseous or liquid fuels, and later the use of

electricity enabled increased automation in heating , reducing the labour necessary to

manually refuel heaters and stoves . Development of thermostats allowed more

automated control of heating and ater cooling . As the number of controllable

devices in the home rises , interconnection and communication becomes a useful and

desired feature. For example, a furnace can send an alert message when it needs

cleaning , or a refrigerator when it needs service . Rooms will become

“intelligent” and will send signals to the controller when someone enters . If no one

is supposed to be at home and the alarm system is set , the system is set , the

system could call the owner , or the neighbors , or an emergency number. In simple

installations, domotics may be as straightforward as turning on the lights when a

person enters the room. In advanced installations , rooms can sense not only the

presense of a person inside but know who that person is and perhaps set appropriate

lightining, temperature , music levels or television channels , taking into account

the day of the week , the time of day and other factors . This Project is an

implementation of the MATLAB –ARDUINO serial port communication .This project

will also include an introduction of what an Arduino is - it’s basic design . The pins

that are there on the board etc , Following this we have covered topics on Arduino Setup,

issues faced while installing an Arduino. It’s hardware and software aspects , issues

faced while installing an Arduino , how we have troubles hooted the problems etc .

The final portion of this report includes MATLAB ARDUINO INTERFACING and

serial port communication. The communication is established using the serial ports

that are present on the Arduino Board .

Introduction

Page 6: Final  report  on  gui based device control using matlab

A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can

make programs easier to use by providing them with a consistent appearance and with

intuitive controls like pushbuttons, list boxes, sliders, menus, and so forth. The GUI

should behave in an understandable and predictable manner, so that a user knows what to

expect when he or she performs an action. For example, when a mouse click occurs on a

pushbutton, the GUI should initiate the action described on the label of the button. This

chapter introduces the basic elements of the MATLAB GUIs. The chapter does not

contain a complete description of components or GUI features, but it does provide the

basics required to create functional GUIs for your programs.

How a Graphical User Interface Works

A graphical user interface provides the user with a familiar environment in which to

work. This environment contains pushbuttons, toggle buttons, lists, menus, text boxes,

and so forth, all of which are already familiar to the user, so that he or she can

concentrate on using the application rather than on the mechanics involved in doing

things. However, GUIs are harder for the programmer because a GUI-based program

must be prepared for mouse clicks (or possibly keyboard input) for any GUI element at

any time. Such inputs are known as events, and a program that responds to events is said

to be event driven. The three principal elements required to create a MATLAB Graphical

User Interface are

1. Components. Each item on a MATLAB GUI (pushbuttons, labels, edit boxes, etc is a

graphical component. The types of components include graphical controls(pushbuttons,

edit boxes, lists, sliders, etc.), static elements (frames and text strings), menus, and

axes. Graphical controls and static elements are created by the function ui control, and

menus are created by the functions ui menu and ui context menu. Axes, which are used

to display graphical data, are created by the function axes.

2. Figures. The components of a GUI must be arranged within a figure, which is a

window on the computer screen. In the past, figures have been created automatically

whenever we have plotted data. However, empty figures can be created with the

Page 7: Final  report  on  gui based device control using matlab

function figure and can be used to hold any combination of components.

3. Callbacks. Finally, there must be some way to perform an action if a user clicks a

mouse on a button or types information on a keyboard. A mouse click or a key press is

an event, and the MATLAB program must respond to each event if the program is to

perform its function. For example, if a user clicks on a button, that event must cause

the MATLAB code that implements the function of the button to be executed. The

code executed in response to an event is known as a call back. There must be a call

back to implement the function of each graphical component on the GUI. The basic

GUI elements are summarized in Table 1.1, and sample elements are shown in Figure.

We will be studying examples of these elements and then build working GUIs

from them.

Creating And Displaying A Graphical User Interface

MATLAB GUIs are created using a tool called guide, the GUI Development

Environment. This tool allows a programmer to layout the GUI, selecting and aligning

the GUI components to be placed in it. Once the components are in place, the

programmer can edit their properties: name, color, size, font, text to display, and so forth.

When guide saves the GUI, it creates working program including skeleton functions that

the programmer can modify to implement the behavior of the GUI. When guide is

executed, it creates the Layout Editor, shown in Figure 1.2. The large white area with

grid lines is the layout area, where a programmer can layout the GUI. The Layout Editor

window has a palate of GUI components along the left side of the layout area. A user can

create any number of GUI components by first clicking on the desired component, and

then dragging its outline in the layout area. The top of the window has a toolbar with a

series of useful tools that allow the user to distribute and align GUI components, modify

the properties of GUI components, add menus to GUIs, and so on. The basic steps

required to create a MATLAB GUI are:

1. Decide what elements are required for the GUI and what the function of each element

will be. Make a rough layout of the components by hand on a piece of paper.

Page 8: Final  report  on  gui based device control using matlab

Figure 1.1 A Figure Window showing examples of MA TLAB GUI elements From top

to bottom and left to right, the elements are: (1) a pushbutton; (2) a toggle button in the

‘on' state; (3) two radio buttons surrounded by a frame; (4) a check box; (5) a text field

and an edit box; (6) a slider; (7) a set of axes; and (8) a list box.

Page 9: Final  report  on  gui based device control using matlab

2.Use a MATLAB tool called guide (GUI Development Environment) to layout the

components on a figure. The size of the figure and the alignment and spacing of

Page 10: Final  report  on  gui based device control using matlab

components on the figure can be adjusted using the tools built into guide.

3. Use a MATLAB tool called the Property Inspector (built into guide) to give each

component a name (a "tag") and to set the characteristics of each component, such as

its color, the text it displays, and so on.

4. Save the figure to a file. When the figure is saved, two files will be created on disk

with the same name but different extents. The fig file contains the actual GUI that you

have created, and the M-file contains the code to load the figure and skeleton call

backs for each GUI element.

5. Write code to implement the behavior associated with each callback function.

As an example of these steps, let's consider a simple GUI that contains a single

Push button and a single text string. Each time that the pushbutton is clicked, the text

string will be updated to show the total number of clicks since the GUI started.

Page 11: Final  report  on  gui based device control using matlab

Figure 1.3 Rough layout for a GUI containing a single pushbutton and a single label field.

Step 1: The design of this Gm is very simple. It contains a single pushbutton and a single

text field. The callback from the pushbutton will cause the number displayed in the text

field to increase by one each time that the button is pressed. A rough sketch of the GUI is

shown in Figure 1.3.

Step 2: To layout the components on the GUI, run the MATLAB function guide. When

guide is executed, it creates the window shown in Figure 1.2

Figure 1.4 The completed GUI layout within the guide window

First, we must set the size of the layout area, which will become the size the final GUI.

We do this by dragging the small square on the lower right corner of the layout area until

Page 12: Final  report  on  gui based device control using matlab

it has the desired size and shape. Then, click on the "pushbutton" button in the list of GUI

components, and create the shape of the pushbutton in the layout area. Finally, click on

the "text" button in the list GUI components, and create the shape of the text field in the

layout area. The resulting figure after these steps is shown in Figure 1.4. We could now

adjust the alignment of these two elements using the Alignment Tool, if desired.

Step 3: To set the properties of the pushbutton, click on the button in the layout area and

then select "Property Inspector" from the toolbar. Alternatively, right-click on the button

and select "Inspect Properties" from the popup menu. The Property Inspector window

shown in Figure 1.5 will appear. Note this window lists every property available for the

pushbutton and allows us set each value using a GUI interface. The Property Inspector

performs the same function as the get and set functions, but in a much more convenient

form.

For the pushbutton, we may set many properties such as color, size, font, text alignment,

and so on. However, we must set two properties: the String property, which contains the

text to be displayed, and the Tag property, which is the name of the pushbutton. In this

case, the String property will be set to 'click Here', and the Tag property will be set to

MyFirstButton. For the text field, we must set two properties: the String property, which

contains the text to be displayed, and the Tag property, which is the name of the text

field. This name will be needed by the callback function to locate and update the text

field. In this case, the String property will be set to 'Total clicks: 0', and the Tag property

defaulted to 'MyFirstText'. The layout area after these steps is shown in Figure 1.6. It is

possible to set the properties of the figure itself by clicking on a clear spot in the Layout

Editor, and then using the Property Inspector to examine and set the figure's properties.

Although not required, it is a good idea to set the figure's Name property. The string in

the Name property will be displayed in the title bar of the resulting GUI when it is

executed.

Page 13: Final  report  on  gui based device control using matlab

Figure 1.5 The Property Inspector showing the properties of the pushbutton. Note that the

String is set to 'Click Here', and the Tag is set to 'MyFirstButton'.

Step 4: We will now save the layout area under the name MyFirstGUI. Select the

"File/SaveAs" menu item, type the name MyFirstGUI as the file name, and click "Save".

This action will automatically create two files, MyFirstGUI.fig and MyFirstGUI.m. The

figure file contains the actual GUI that we have created. The M-file contains code that

loads the figure file and creates the GUI, plus a skeleton callback function for each active

GUI component.

At this point, we have a complete Gm, but one that does not yet do the job it was

designed to do. You can start this Gm by typing MyFirstGUI in the Command Window,

as shown in Figure 1.7. If the button is clicked on this GUI, the following message will

appear in the Command Window: MyFirstButton Callback not implemented yet. A

portion of the M-file automatically created by guide is shown in Figure 1.8. This file

contains function MyFirstGUI, plus dummy sub functions implementing the callbacks for

Page 14: Final  report  on  gui based device control using matlab

each active GUI component. If function MyFirstGUI is called without arguments, then

the function displays the Gm contained in file.

Figure 1.6 The design area after the properties of the pushbutton and the text field have

been modified.

MyFirstGUI.fig. If function MyFirstGUI is called with arguments, then the function

assumes that the first arguments the name of a sub function, and it calls that function

using feval, passing the other arguments on to that function. Each callback function

handles events from a single GUI component. If a mouse click (or keyboard input for

Edit Fields) occurs on the GUI component, then the component's callback function will

be automatically called by MATLAB. The name of the callback function will be the

value in the Tag property of the GUI component plus the characters "_Callback". Thus,

the callback function for MyFirstButton will be named MyFirstButton_Callback. M-files

created by guide contain callbacks for each active GUI component, but these callbacks

simply display a message saying that the function of the callback has not been

implemented yet.

Page 15: Final  report  on  gui based device control using matlab

Step 5: Now, we need to implement the callback sub function for the pushbutton. This

function will include a persistent variable that can be used to count the number of clicks

that have occurred. When a click occurs on the pushbutton, MATLAB will call the

function MyFirstGUI with MyFirstButton_callback as the first argument. Then function

MyFirstGUI will call sub function MyFirstButton_callback, as shownin Figure 1.9. This

function should increase the count of clicks by one, create a new text string containing

the count, and store the new string in the String property of the text field MyFirstText.

Figure 1.7 Typing MyFirstGUI in the Command Window starts the GUI

Page 16: Final  report  on  gui based device control using matlab

.

Figure 1.8 The M-file forMyFirstGUI, automatically created by guide.

A function to perform this step is shown below:

Page 17: Final  report  on  gui based device control using matlab

Figure 1.9 Event handling in program MyFirstGUI.

When a user clicks on the button with the mouse, the function MyFirstGUI is cal1ed

automatically with the argument MyFirstButton_callback. Function MyFirstGUI in turn

calls sub function. MyFirstButton_Callback. This function increments count, and then

saves the new count in the text field on the GUI.

Figure 1.10 The resulting program after three button pushes.

Page 18: Final  report  on  gui based device control using matlab

Note that this function declares a persistent variable count and initializes it to zero. Each

time that the function is called, it increments count by 1 and creates a new string

containing the count. Then, the function updates the string displayed in the text field

MyFirstText. The resulting program is executed by typing MyFirstGUI in the Command

Window. When the user clicks on the button, MATLAB automatically calls function

MyFirstGUI with MYFirstButton_Callback as the first argument, and function

MyFirstGUI calls sub function MyFirstButton_Callback. This function increments

variable count by one and updates the value displayed in the text field. The resulting GUI

after three button pushes is shown in Figure 1.10.

Good Programming Practice

Store GUI application data in the handles structure, so that it will automatically be

available to any callback function.

If you modify any of the GUI application data in the handles structure, be sure to save the

structure with a call to guidata before exiting the function where the modifications

occurred.

Graphical user Interface Components

This section summarizes the basic characteristics of common graphical user interface

components. It describes how to create and use each component, as well as the types of

events each component can generate. The components discussed in this section are

• Text Fields

• Edit Boxes

• Frames

• Pushbuttons

• Toggle Buttons

• Checkboxes

• Radio Buttons

• Popup Menus

• List Boxes

• Slide

Page 19: Final  report  on  gui based device control using matlab

Text Fields

A text-field is a graphical object that displays a text string. You can specify how the text

is aligned in the display area by setting the horizontal alignment property. By default, text

fields are horizontally centered. A text field is created by creating a uicontrol whose style

property is 'edit'. A text field may be added to a GUI by using the text tool in the Layout

Editor. Text fields do not create callbacks, but the value displayed in the text field can be

updated in a callback function by changing the text field's String property.

Edit Boxes

An edit box is a graphical object that allows a user to enter a text string. The edit box

generates a callback when the user presses the Enter key after typing a string into the

box. An edit box is created by creating a uicontrol whose style property is 'edit'. An

edit box may be added to a GUI by using the edit box tool in the Layout Editor. Figure

l.l1a shows a simple GUI containing an edit box named, ‘Edit Box’ and a text field

named 'TextBox' .When a user types a string into the edit box, it automatically calls

the function EditBox_Callback, which is shown in Figure 1.11b. This function locates

the edit box using the handles structure and recovers the string typed by the user.

Then, it locates the text field and displays the string in the text field. Figure 1.12 shows

this GUI just after it has started and after the user has typed the word "Hello" in the edit

box.

3. Frames

A frame is a graphical object that displays a rectangle on the GUI. You can use frames

to draw boxes around groups of logically related objects. For example, a frame is used

to group the radio buttons together on Figure 1.1. A frame is created by creating a

uicontrol whose style property is 'frame'. A frame maybe added to a GUI by using the

frame tool in the Layout Editor. Frames do not generate callbacks.

4. Pushbuttons

A pushbutton is a component that a user can click on to trigger a specific action. The

Page 20: Final  report  on  gui based device control using matlab

pushbutton generates a callback when the user clicks the mouse on it. A pushbutton is

created by creating a uicontrol whose style property is 'pushbutton'. A pushbutton may

be added to a GUI by using the pushbutton tool in the Layout Editor. Function

MyFirstGUI in Figure 1.10 illustrated the use of pushbuttons.

Figure 1.11 (a) Layout of a simple GUI with an edit box and a text field. (b) The callback

functions for this GUI.

Page 21: Final  report  on  gui based device control using matlab

Figure 1.12 (a) The GUI produced by program test edit. (b) The GUI after a user types

Hello into the edit box and presses Enter.

5. Toggle Buttons

A toggle button is a type of button that has two states: on (depressed) and off (not

depressed). A toggle button switches between these two states whenever the mouse clicks

on it, and it generates a callback each time. The 'Value' property of the toggle button is

set to max (usually 1) when the button is on, and min (usually 0) when the button is off.

A toggle button is created by creating a uicontrol whose style property is toggle button. A

toggle button may be added to a GUI by using the toggle button tool in the Layout Editor.

Figure 1.13a shows a simple GUI containing a toggle button named 'ToggleButton' and a

text field named' TextBox'. When a user clicks on the toggle button, it automatically calls

the function ToggleButton Callback, which is shown in Figure 1.13b. This function

locates the toggle button using the handles structure and recovers its state from the' Value'

property. Then, the function locates the text field and displays the state in the text field.

Page 22: Final  report  on  gui based device control using matlab

Figure 1.14 shows this GUI just after it has started, and after the user has clicked on the

toggle button for the first time.

6. Checkboxes and radio buttons

Checkboxes and radio buttons are essentially identical to toggle buttons except that they

have different shapes. Like toggle buttons, checkboxes and radio buttons have two states:

on and off. They switch between these two states whenever the mouse clicks on them,

generating a callback each time. The 'Value' property of the checkbox or radio button is

set to max (usually 1) when they are on, and min (usually 0) when they are off. Both

checkboxes and radio buttons are illustrated in Figure 1.1.

A checkbox is created by creating a uicontrol whose style property is 'checkbox', and a

radio button is created by creating a uicontrol whose style property is 'radiobutton'. A

checkbox may be added to a GUI by using the checkbox tool in the Layout Editor, and a

radio button may be added to a GUI by using the radio button tool in the Layout Editor.

Checkboxes are traditionally used to display on/off options, and groups of radio buttons

are traditionally used to select among mutually exclusive options. Figure 1.l5a shows an

example of how to create a group of mutually exclusive options with radio buttons. The

GUI in this figure creates three radio buttons, labeled "Option 1," "Option 2," and

"Option 3." Each radio button uses the same callback function, but with a separate

parameter. The corresponding callback functions are shown in Figure l.l5b. When the

user clicks on a radio button, the corresponding callback function is executed.That

function sets the text box to display the current option, turns on that radio button, and

turns off all other radio buttons. Note that the GUI uses a frame to group the radio buttons

together, making it obvious that they are a set. Figure 1.16 shows this GUI after Option 2

has been selected.

Page 23: Final  report  on  gui based device control using matlab

Figure 1.13 (a) Layout of a simple GUI with a toggle button and a text field. (b) The call

back function for this GUI.

Figure 1.14 (a) The GUI produced by program testto gglebutton when the toggle button

is off. (b) The GUI when the toggle button is on.

7. Popup menus

Page 24: Final  report  on  gui based device control using matlab

Popup menus are graphical objects that allow a user to select one of a mutually exclusive

list of options. The list of options that the user can select among is specified by a cell

array of strings, and the 'Value' property indicates which of the strings is currently

selected. A popup menu may be added to a GUI by using the popup menu tool in the

Layout Editor. Figure 1.14a shows an example of a popup menu. The GUI in this figure

creates a popup menu with five options, labeled "Option I," "Option 2," and so forth. The

corresponding callback function is shown in Figure 1.14b. The call back function

recovers the selected option by checking the' Value' parameter of the popup menu, and

creates and displays a string containing that value in the text field. Figure 1.15 shows this

Gm after Option 4 has been selected.

8. List Boxes

List boxes are graphical objects that display many lines of text and allow a user to select

one or more of those lines. If there are more lines of text than can fit in the list box, a

scroll bar will be created to allow the user to scroll up and down within the list box. The

lines of text that the user can select among are specified by a cell array of strings, and the'

Value' property indicates which of the strings are currently selected. A list box is created

by creating a uicontrol whose style property is 'listbox'. A list box may be added to a GUI

by using the listbox tool in the Layout Editor. List boxes can be used to select a single

item from a selection of possible choices. In normal GUI usage, a single mouse click on a

list item selects that item but does not cause an action to occur. Instead, the action waits

on some external trigger, such as a pushbutton. However, a mouse double-click causes an

action to happen immediately. Single-click and double-click events can be distinguished

using the Selection Type property of the figure in which the clicks occurred. A single

mouse click will place the string 'normal' in the Selection Type property, and a double

mouse click will place the string' open' in the Selection Type property.

Page 25: Final  report  on  gui based device control using matlab

Figure 1.14 (a) Layout of a simple GUI with a popup menu and a text field to display the

current selection. (b) The callback functions for this GUI.

Figure 1.15 The GUI produced by program test popup.

It is also possible for a list box to allow multiple selections from the list. If the difference

between the max and min properties of the list box is greater than one, then multiple

selections is allowed. Otherwise, only one item may be selected from the list.

This function will check the figure producing the callback (using function gebf) to see if

the selecting action was a single-click or a double-click. If it was a single-click, the

Page 26: Final  report  on  gui based device control using matlab

function does nothing. If it was a double-click, then the function gets the selected value

from the listbox, and writes an appropriate string into the text field. If the pushbutton is

selected, then functionButton1_Callbaekwill be executed. This function gets the selected

value from the listbox, and writes an appropriate string into the text field.

9. Sliders

Sliders are graphical objects that allow a user to select values from a continuous range

between a specified minimum value and a specified maximum value by moving a bar

with a mouse. The 'Value' property of the slider is set to a value between min and max

depending on the position of the slider.

A slider is created by creating a uicontrol whose style property is 'slider'. A slider may be

added to a GUI by using the slider tool in the Layout Editor.

MICROCONTROLLERS

Microcontrollers are used in the industrial world to control many types of equipments

ranging from customers to specialized devices . Furthermore , there is a growing need

for offline support of a computers main processor . The demand will grow as

more eqipment uses more intelligence . One of the most popular is MOTOROLA

68HC11 MICROCONTROLLER is relatively easy to work with , yet they have most

of the features essential for a complete control system .Thus student of control

automation can use them to work with control systems at the component level.The

intersted person can also use them as tools to understand and experiment with the

computer and data communications systems. As time passed engineers have developed a

better microcontroller to perform the specific task. For example, : ATMEL8051 family ,

ATMEL 8052 family , ATmega AVR family , TI-MSP430 , ARM family and many

more. These all controllers are present in the market for development such types of

specific task . As per the application we need to choose one of them. The crtiteria for

choosing the microcontroller are by their features , cost and power consumption, area ,

Page 27: Final  report  on  gui based device control using matlab

available memory inside the chip etc. Controller 89S52 from ATMEL 8052 Family .

It has 8 KB of on chip ROM and 256 bytes of RAM , 32 I/O PINS and easy to

program .

Industrial Automation meant for a system which monitor the input points (sensors and

signals generated by the GSM , BLUETOOTH , RF TRANSMITTER , RFID , DTMF)

and respond as per their described behaviour after crossin a threshold limit set by the

user.So far many scientists have done lots of research in the field of automation. For

example :There is automation using IR SENSOR . In addition some of them have

improved their communication medium to robust and effeicient their system. Morever,

due to the advancement in computer era , it facilitates the development of electronic

devices such as digital camera, digital images have been widely used in many era.

Therefore security is also an important issue.

ARDUINO

Arduino is a tool for making computers that can sense and control more of the physical

world than your desktop computer . It’s an open - source physical computing platform

based on a simple microcontroller board and a development enviornment for

writing software for the board . Arduino can be used to develop interactive objects

, taking inputs from a variety of switches or sensors and controlling a variety of

lights , motors , and other physical outputs . Arduino projects can be stand – alone , or

they can communicate with softwares running on your computer ( eg Flash , Processing

, MaxMSP ) . The boards can be assembled by hand or purchased preassembled , the

open source IDE can be downloaded for free .

The Arduino programming language is an implementation of Wiring , a similar physical

computing platform which is based on the Processing multimedia programming

enviornment .

There are many other microcontrollers and microcontroller platforms , available for

physical computing. Parallax Basic Stamp , Netmedia’s BX-24 , PHIDGETS , MIT’s

Handyboard and many other offer similar functionality. All of these tools take the

messy details of microcontroller programming and wrap it up in an easy to use package .

Page 28: Final  report  on  gui based device control using matlab

Arduino also simplifies the process of working with microcontrollers, but it offers some

advantage for teachers, students and interested amateurs over other systems.

INEXPENSIVE : Arduino boards are relatively inexpensive compared to other

microcontroller platforms . The least expensive version of the Arduino module can be

assembled by hand and even the pre-assembled Arduino modules cost less than $ 50.

Cross-Platform : The Arduino software runs on the Windows , Macintosh OSX and

Linux operating systems. Most microcontroller systems are limited to Windows .

Simple, clear programming enviornment : The Arduino programming enviornment is

easy -to–use for beginners, yet flexible enough for advanced users to take advantage of

as well. For teachers, it’s conveniently based on the Processing programming

enviornment , so students learning to program in that enviornment will be familiar

with the look and feel of Arduino .

Open source and extensible software : The Aurdino software is published as open

source tools , available for extension by experienced programmers . The language can

be expanded through C++ libraries and people wanting to understand the technical

details can make the leap from Arduino to the AVR C PROGRAMMING

language on which it’s based . Similarly you can add AVR - C CODE directly

into your Arduino programs if you want to .

Open source and extensible hardware : The Arduino is based on Atmel’s

ATMEGA8 and ATMEGA168 MICROCONTROLLERS . The plans for the

modules are published under a creative Common license , so experienced circuit

designers can make their own version of the module , extending it and improving

it . Even relatively inexperienced users can build the breadboard version of the

module in order to understand how it works and save money .

Setting up an Arduino:

Page 29: Final  report  on  gui based device control using matlab

To setup an Arduino we need the board, a cable to connect plug A and B. Cable is used to

interface/connect between PC and Arduino. Connect it to PC. COM port (Communication

port is the name of the serial port interfacing on the common PC’s. After plugging in the

Arduino gets connected to COM port. A software called arduinocc is downloaded (open

source software). It is the IDE (Integrated Development Environment).

PIN Configurations:

The Arduino Digital Pins can be configured as either input/output pins. By default they

are input pins.

PinMode(pin, mode)

There are pin modes. The number of pin whose mode is to be changed is represented by

pin. Mode can be input, output or input pull-up.

Checking if the Arduino works:

Page 30: Final  report  on  gui based device control using matlab

After setting up, the debugging LED is made to blink by writing the following code:

int led = 13;

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:

Serial Port communication:

The concept of serial communication is simple, in serial communication data is sent one

bit at a time. Although this is slower than parallel communication, which allows the

transmission of an entire byte at once, it is simpler and can be used over longer distances.

Possible troubleshooting for issues that may arise:

Issues are:

1. Right clicking on COM Port and updating drivers did not work.

2. Incompatibility of the software. It did not function at all.

3. The board was not able to connect to the PC.

Troubleshooting:

1.The issue was troubles hooted when the unzipped folder was put on desktop.

2. Following quite a few instructions found on a supportive blog and the official Arduino

Forum proved helpful to solve the rest of the issues.

void loop() {

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second }

Page 31: Final  report  on  gui based device control using matlab

MATLAB code to generate a pulse:

clc; clear all; close all;

t=-5:0.0001:5;

D=input('Enter the Ton percentage');

y=square(t,D);

plot(t,y);

% This code shows a pulse on the MATLAB plotter window

But a problem with the code is that I was not able to change the frequency of the pulse.

How did I solve this problem?

I have used a Simulink block called pulse generator. I can vary the sampling time of the

pulse using this block. The below is the block diagram of a pulse generator. It can be

found in the Simulink Library.

Pulse generator block:

Pulse generator output graph:

Page 32: Final  report  on  gui based device control using matlab

The Pulse Generator block generates square wave pulses at regular intervals. The block's

waveform parameters, Amplitude, Pulse Width, Period, and Phase delay, determine the

shape of the output waveform. The above diagram shows how each parameter affects the

waveform.

The Pulse Generator can emit scalar, vector, or matrix signals of any real data type. To

cause the block to emit a scalar signal, use scalars to specify the waveform parameters.

To cause the block to emit a vector or matrix signal, use vectors or matrices, respectively,

to specify the waveform parameters. Each element of the waveform parameters affects

the corresponding element of the output signal. For example, the first element

of a vector amplitude parameter determines the amplitude of the first element of a vector

output pulse. All the waveform parameters must have the same dimensions after scalar

expansion. The data type of the output is the same as the data type of the

Amplitude parameter.

Use the Pulse type parameter to specify whether the block's output is time-based or

sample-based. If you select sample-based, the block computes its outputs at fixed

intervals that you specify. If you select time-based, Simulink software computes the

block's outputs only at times when the output actually changes. This choice can result in

fewer computations for computing the block's output over the simulation time period.

A time-based configuration using parameters Pulse Width and Period that results in a

constant output signal is not supported. Simulink returns an error if these parameters

satisfy either of the following conditions:

If you select time-based as the block's pulse type, you must specify the pulse's phase

delay and period in units of seconds. If you specify sample-based, you must specify the

block's sample time in seconds, using the Sample time parameter, then specify the block's

phase delay and period as integer multiples of the sample time. For example, suppose that

Page 33: Final  report  on  gui based device control using matlab

you specify a sample time of 0.5 second and want the pulse to repeat every two seconds.

In this case, you would specify 4 as the value of the block's Period parameter.

Tweaking with the properties of a pulse generator:

To tweak with the properties of a pulse generator the following information can be used:

Pulse type- The pulse type for this block: time-based or sample-based. The default is

time-based.

Time- It specifies whether to use simulation time or an external signal as the source of

values for the output pulse's time variable. If you specify an external source, the block

displays an input port for connecting the source. The output pulse differs as follows:

If you select Use simulation time, the block generates an output pulse where the time

variable equals the simulation time.If you select Use external signal, the block generates

an output pulse where the time variable equals the value from the input port, which can

differ from the simulation time.

Amplitude:

It is the pulse amplitude. The default is 1.

Period:

The pulse period specified in seconds if the pulse type is time-based or as number of

sample times if the pulse type is sample-based. The default is 10 seconds.

Pulse Width:

The duty cycle specified as the percentage of the pulse period that the signal is on if time-

based or as number of sample times if sample-based. The default is 5 percent.

Phase delay:

The delay before the pulse is generated specified in seconds if the pulse type is time-

based or as number of sample times if the pulse type is sample-based. The default

is 0 seconds.

Sample time:

It is the length of the sample time for this block in seconds. This parameter appears only

if the block's pulse type is sample-based. See Specify Sample Time in the Simulink User's

Guide for more information.

Page 34: Final  report  on  gui based device control using matlab

MATLAB and ARDUINO Interfacing:

This is the function:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.

These pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.

How to Communicate:

The Arduino Duemilanove has a number of facilities for communicating with a computer,

another Arduino, or other microcontrollers. The ATmega168 and ATmega328 provide

UART TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1

(TX). An FTDI FT232RL on the board channels this serial communication over USB and

the FTDI drivers (included with Windows version of the Arduino software) provide a

virtual com port to software on the computer. The Arduino software includes a serial

monitor which allows simple textual data to be sent to and from the Arduino board. The

RX and TX LEDs on the board will flash when data is being transmitted via the FTDI

chip and USB connection to the computer (but not for serial communication on pins 0 and

1). A SoftwareSerial library allows for serial communication on any of the Duemilanove's

digital pins. The ATmega168 and ATmega328 also support I2C (TWI) and SPI

communication. The Arduino software includes a Wire library to simplify use of

the I2C bus; see the documentation for details. For SPI communication, use the SPI

library.

SoftwareSerial Library:

The Arduino hardware has a built-in support for serial communication on pins 0 and 1

(which also goes to the computer via the USB connection). The native serial support

happens via a piece of hardware (built into the chip) called a UART. This hardware

allows the Atmega chip to receive serial communication even while working on other

tasks, as long as there room in the 64 byte serial buffer. The SoftwareSerial library has

been developed to allow serial communication on other digital pins of the

Arduino, using software to replicate the functionality (hence the name "SoftwareSerial").

It is possible to have multiple software serial ports with speeds up to 115200 bps. A

parameter enables inverted signaling for devices which require that protocol. The version

Page 35: Final  report  on  gui based device control using matlab

of SoftwareSerial included in 1.0 and later is based on the NewSoftSerial library by Mikal

Hart.

MATLAB support package for Arduino:

In serial port communication information transfers one bit at a time. MATLAB Support

Package for Arduino (also referred to as "ArduinoIO Package") allows you to

communicate with an Arduino Uno or Duemilanove over a serial port. It consists of a

MATLAB API on the host computer and a server program that runs on the Arduino.

Together, they allow you to access Arduino analog I/O, digital I/O, operate servo

motors, read encoders, and even handle dc and stepper motors using the adafruit motor

shield, all from the MATLAB command line.

Setting Up serial port object:

>> s = serial (’COM1’);

Serial Port Object : Serial-COM1

Communication Settings

Port: COM1

BaudRate: 9600

Terminator: ’LF’

Communication State

Status: closed

RecordStatus: off

Read/Write State

TransferStatus: idle

BytesAvailable: 0

ValuesReceived: 0

ValuesSent: 0

Baud rate:

Page 36: Final  report  on  gui based device control using matlab

>> set(s, ’BaudRate’, 4800);

>> s.BaudRate = 4800;

The above progam helps us to establish a serial communication between matlab and

arduino.

Our project:

There is an arduino support package which works with Matlab. The code is written below

that links arduino with Matlab and further we are able to control the output that is

explained further.

/* Analog and Digital Input and Output Server for MATLAB */

/* Giampiero Campa, Copyright 2012 The MathWorks, Inc */

/* This file is meant to be used with the MATLAB arduino IO

package, however, it can be used from the IDE environment

(or any other serial terminal) by typing commands like:

0e0 : assigns digital pin #4 (e) as input

0f1 : assigns digital pin #5 (f) as output

0n1 : assigns digital pin #13 (n) as output

1c : reads digital pin #2 (c)

1e : reads digital pin #4 (e)

2n0 : sets digital pin #13 (n) low

2n1 : sets digital pin #13 (n) high

2f1 : sets digital pin #5 (f) high

2f0 : sets digital pin #5 (f) low

4j2 : sets digital pin #9 (j) to 50=ascii(2) over 255

4jz : sets digital pin #9 (j) to 122=ascii(z) over 255

3a : reads analog pin #0 (a)

Page 37: Final  report  on  gui based device control using matlab

3f : reads analog pin #5 (f)

5j : reads status (attached/detached) of servo on pin #9

5k : reads status (attached/detached) of servo on pin #10

6j1 : attaches servo on pin #9

8jz : moves servo on pin #9 of 122 degrees (122=ascii(z))

7j : reads angle of servo on pin #9

6j0 : detaches servo on pin #9

E0cd : attaches encoder #0 (0) on pins 2 (c) and 3 (d)

E1st : attaches encoder #1 on pins 18 (s) and 19 (t)

E2vu : attaches encoder #2 on pins 21 (v) and 20 (u)

G0 : gets 0 position of encoder #0

I0u : sets debounce delay to 20 (2ms) for encoder #0

H1 : resets position of encoder #1

F2 : detaches encoder #2

R0 : sets analog reference to DEFAULT

R1 : sets analog reference to INTERNAL

R2 : sets analog reference to EXTERNAL

X3 : roundtrip example case returning the input (ascii(3))

99 : returns script type (0 adio.pde ... 3 motor.pde ) */

#include <Servo.h>

/* define internal for the MEGA as 1.1V (as as for the 328) */

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

#define INTERNAL INTERNAL1V1

#endif

Page 38: Final  report  on  gui based device control using matlab

/* define encoder structure */

typedef struct { int pinA; int pinB; int pos; int del;} Encoder;

volatile Encoder Enc[3] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}};

/* create servo vector */

Servo servo[70];

void setup() {

/* initialize serial */

Serial.begin(115200);

}

void loop() {

/* variables declaration and initialization */

static int s = -1; /* state */

static int pin = 13; /* generic pin number */

static int enc = 0; /* generic encoder number */

int val = 0; /* generic value read from serial */

int agv = 0; /* generic analog value */

int dgv = 0; /* generic digital value */

/* The following instruction constantly checks if anything

is available on the serial port. Nothing gets executed in

the loop if nothing is available to be read, but as soon

as anything becomes available, then the part coded after

the if statement (that is the real stuff) gets executed */

Page 39: Final  report  on  gui based device control using matlab

if (Serial.available() >0) {

/* whatever is available from the serial is read here */

val = Serial.read();

/* This part basically implements a state machine that

reads the serial port and makes just one transition

to a new state, depending on both the previous state

and the command that is read from the serial port.

Some commands need additional inputs from the serial

port, so they need 2 or 3 state transitions (each one

happening as soon as anything new is available from

the serial port) to be fully executed. After a command

is fully executed the state returns to its initial

value s=-1 */

switch (s) {

/* s=-1 means NOTHING RECEIVED YET ******************* */

case -1:

/* calculate next state */

if (val>47 && val<90) {

/* the first received value indicates the mode

49 is ascii for 1, ... 90 is ascii for Z

s=0 is change-pin mode;

s=10 is DI; s=20 is DO; s=30 is AI; s=40 is AO;

s=50 is servo status; s=60 is aervo attach/detach;

s=70 is servo read; s=80 is servo write;

Page 40: Final  report  on  gui based device control using matlab

s=90 is query script type (1 basic, 2 motor);

s=210 is encoder attach; s=220 is encoder detach;

s=230 is get encoder position; s=240 is encoder reset;

s=250 is set encoder debounce delay;

s=340 is change analog reference;

s=400 example echo returning the input argument;

*/

s=10*(val-48);

}

/* the following statements are needed to handle

unexpected first values coming from the serial (if

the value is unrecognized then it defaults to s=-1) */

if ((s>90 && s<210) || (s>250 && s!=340 && s!=400)) {

s=-1;

}

/* the break statements gets out of the switch-case, so

/* we go back and wait for new serial data */

break; /* s=-1 (initial state) taken care of */

/* s=0 or 1 means CHANGE PIN MODE */

case 0:

/* the second received value indicates the pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

s=1; /* next we will need to get 0 or 1 from serial */

Page 41: Final  report  on  gui based device control using matlab

}

else {

s=-1; /* if value is not a pin then return to -1 */

}

break; /* s=0 taken care of */

case 1:

/* the third received value indicates the value 0 or 1 */

if (val>47 && val<50) {

/* set pin mode */

if (val==48) {

pinMode(pin,INPUT);

}

else {

pinMode(pin,OUTPUT);

}

}

s=-1; /* we are done with CHANGE PIN so go to -1 */

break; /* s=1 taken care of */

/* s=10 means DIGITAL INPUT ************************** */

case 10:

/* the second received value indicates the pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

dgv=digitalRead(pin); /* perform Digital Input */

Page 42: Final  report  on  gui based device control using matlab

Serial.println(dgv); /* send value via serial */

}

s=-1; /* we are done with DI so next state is -1 */

break; /* s=10 taken care of */

/* s=20 or 21 means DIGITAL OUTPUT ******************* */

case 20:

/* the second received value indicates the pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

s=21; /* next we will need to get 0 or 1 from serial */

}

else {

s=-1; /* if value is not a pin then return to -1 */

}

break; /* s=20 taken care of */

case 21:

/* the third received value indicates the value 0 or 1 */

if (val>47 && val<50) {

dgv=val-48; /* calculate value */

digitalWrite(pin,dgv); /* perform Digital Output */

}

s=-1; /* we are done with DO so next state is -1 */

break; /* s=21 taken care of */

Page 43: Final  report  on  gui based device control using matlab

/* s=30 means ANALOG INPUT *************************** */

case 30:

/* the second received value indicates the pin

from abs('a')=97, pin 0, to abs('p')=112, pin 15 */

if (val>96 && val<113) {

pin=val-97; /* calculate pin */

agv=analogRead(pin); /* perform Analog Input */

Serial.println(agv); /* send value via serial */

}

s=-1; /* we are done with AI so next state is -1 */

break; /* s=30 taken care of */

/* s=40 or 41 means ANALOG OUTPUT ******************** */

case 40:

/* the second received value indicates the pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

s=41; /* next we will need to get value from serial */

}

else {

s=-1; /* if value is not a pin then return to -1 */

}

break; /* s=40 taken care of */

Page 44: Final  report  on  gui based device control using matlab

case 41:

/* the third received value indicates the analog value */

analogWrite(pin,val); /* perform Analog Output */

s=-1; /* we are done with AO so next state is -1 */

break; /* s=41 taken care of */

/* s=50 means SERVO STATUS (ATTACHED/DETACHED) ******* */

case 50:

/* the second value indicates the servo attachment pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

dgv=servo[pin].attached(); /* read status */

Serial.println(dgv); /* send value via serial */

}

s=-1; /* we are done with servo status so return to -1*/

break; /* s=50 taken care of */

/* s=60 or 61 means SERVO ATTACH/DETACH ************** */

case 60:

/* the second value indicates the servo attachment pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

s=61; /* next we will need to get 0 or 1 from serial */

Page 45: Final  report  on  gui based device control using matlab

}

else {

s=-1; /* if value is not a servo then return to -1 */

}

break; /* s=60 taken care of */

case 61:

/* the third received value indicates the value 0 or 1

0 for detach and 1 for attach */

if (val>47 && val<50) {

dgv=val-48; /* calculate value */

if (dgv) servo[pin].attach(pin); /* attach servo */

else servo[pin].detach(); /* detach servo */

}

s=-1; /* we are done with servo attach/detach so -1 */

break; /* s=61 taken care of */

/* s=70 means SERVO READ ***************************** */

case 70:

/* the second value indicates the servo attachment pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

agv=servo[pin].read(); /* read value */

Serial.println(agv); /* send value via serial */

}

s=-1; /* we are done with servo read so go to -1 next */

Page 46: Final  report  on  gui based device control using matlab

break; /* s=70 taken care of */

/* s=80 or 81 means SERVO WRITE ******************** */

case 80:

/* the second value indicates the servo attachment pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

s=81; /* next we will need to get value from serial */

}

else {

s=-1; /* if value is not a servo then return to -1 */

}

break; /* s=80 taken care of */

case 81:

/* the third received value indicates the servo angle */

servo[pin].write(val); /* write value */

s=-1; /* we are done with servo write so go to -1 next*/

break; /* s=81 taken care of */

/* s=90 means Query Script Type:

(0 adio, 1 adioenc, 2 adiosrv, 3 motor) */

case 90:

Page 47: Final  report  on  gui based device control using matlab

if (val==57) {

/* if string sent is 99 send script type via serial */

Serial.println(2);

}

s=-1; /* we are done with this so next state is -1 */

break; /* s=90 taken care of */

/* s=210 to 212 means ENCODER ATTACH ***************** */

case 210:

/* the second value indicates the encoder number:

either 0, 1 or 2 */

if (val>47 && val<51) {

enc=val-48; /* calculate encoder number */

s=211; /* next we need the first attachment pin */

}

else {

s=-1; /* if value is not an encoder then return to -1*/

}

break; /* s=210 taken care of */

case 211:

/* the third received value indicates the first pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

Enc[enc].pinA=pin; /* set pin A */

s=212; /* next we need the second attachment pin */

Page 48: Final  report  on  gui based device control using matlab

}

else {

s=-1; /* if value is not a servo then return to -1 */

}

break; /* s=211 taken care of */

case 212:

/* the fourth received value indicates the second pin

from abs('c')=99, pin 2, to abs('¦')=166, pin 69 */

if (val>98 && val<167) {

pin=val-97; /* calculate pin */

Enc[enc].pinB=pin; /* set pin B */

/* set encoder pins as inputs */

pinMode(Enc[enc].pinA, INPUT);

pinMode(Enc[enc].pinB, INPUT);

/* turn on pullup resistors */

digitalWrite(Enc[enc].pinA, HIGH);

digitalWrite(Enc[enc].pinB, HIGH);

/* attach interrupts */

switch(enc) {

case 0:

attachInterrupt(getIntNum(Enc[0].pinA), isrPinAEn0, CHANGE);

attachInterrupt(getIntNum(Enc[0].pinB), isrPinBEn0, CHANGE);

break;

case 1:

attachInterrupt(getIntNum(Enc[1].pinA), isrPinAEn1, CHANGE);

attachInterrupt(getIntNum(Enc[1].pinB), isrPinBEn1, CHANGE);

Page 49: Final  report  on  gui based device control using matlab

break;

case 2:

attachInterrupt(getIntNum(Enc[2].pinA), isrPinAEn2, CHANGE);

attachInterrupt(getIntNum(Enc[2].pinB), isrPinBEn2, CHANGE);

break;

}

}

s=-1; /* we are done with encoder attach so -1 */

break; /* s=212 taken care of */

/* s=220 means ENCODER DETACH *********************** */

case 220:

/* the second value indicates the encoder number:

either 0, 1 or 2 */

if (val>47 && val<51) {

enc=val-48; /* calculate encoder number */

/* detach interrupts */

detachInterrupt(getIntNum(Enc[enc].pinA));

detachInterrupt(getIntNum(Enc[enc].pinB));

}

s=-1; /* we are done with encoder detach so -1 */

break; /* s=220 taken care of */

/* s=230 means GET ENCODER POSITION ****************** */

case 230:

/* the second value indicates the encoder number:

Page 50: Final  report  on  gui based device control using matlab

either 0, 1 or 2 */

if (val>47 && val<51) {

enc=val-48; /* calculate encoder number */

/* send the value back */

Serial.println(Enc[enc].pos);

}

s=-1; /* we are done with encoder detach so -1 */

break; /* s=230 taken care of */

/* s=240 means RESET ENCODER POSITION **************** */

case 240:

/* the second value indicates the encoder number:

either 0, 1 or 2 */

if (val>47 && val<51) {

enc=val-48; /* calculate encoder number */

/* reset position */

Enc[enc].pos=0;

}

s=-1; /* we are done with encoder detach so -1 */

break; /* s=240 taken care of */

/* s=250 and 251 mean SET ENCODER DEBOUNCE DELAY ***** */

case 250:

/* the second value indicates the encoder number:

either 0, 1 or 2 */

if (val>47 && val<51) {

enc=val-48; /* calculate encoder number */

Page 51: Final  report  on  gui based device control using matlab

s=251; /* next we need the first attachment pin */

}

else {

s=-1; /* if value is not an encoder then return to -1*/

}

break; /* s=250 taken care of */

case 251:

/* the third received value indicates the debounce

delay value in units of approximately 0.1 ms each

from abs('a')=97, 0 units, to abs('¦')=166, 69 units*/

if (val>96 && val<167) {

Enc[enc].del=val-97; /* set debounce delay */

}

s=-1; /* we are done with this so next state is -1 */

break; /* s=251 taken care of */

/* s=340 or 341 means ANALOG REFERENCE *************** */

case 340:

/* the second received value indicates the reference,

which is encoded as is 0,1,2 for DEFAULT, INTERNAL

and EXTERNAL, respectively. Note that this function

is ignored for boards not featuring AVR or PIC32 */

#if defined(__AVR__) || defined(__PIC32MX__)

switch (val) {

Page 52: Final  report  on  gui based device control using matlab

case 48:

analogReference(DEFAULT);

break;

case 49:

analogReference(INTERNAL);

break;

case 50:

analogReference(EXTERNAL);

break;

default: /* unrecognized, no action */

break;

}

#endif

s=-1; /* we are done with this so next state is -1 */

break; /* s=341 taken care of */

/* s=400 roundtrip example function (returns the input)*/

case 400:

/* the second value (val) can really be anything here */

/* This is an auxiliary function that returns the ASCII

value of its first argument. It is provided as an

Page 53: Final  report  on  gui based device control using matlab

example for people that want to add their own code */

/* your own code goes here instead of the serial print */

Serial.println(val);

s=-1; /* we are done with the aux function so -1 */

break; /* s=400 taken care of */

/* ******* UNRECOGNIZED STATE, go back to s=-1 ******* */

default:

/* we should never get here but if we do it means we

are in an unexpected state so whatever is the second

received value we get out of here and back to s=-1 */

s=-1; /* go back to the initial state, break unneeded */

} /* end switch on state s */

} /* end if serial available */

} /* end loop statement */

/* auxiliary function to handle encoder attachment */

Page 54: Final  report  on  gui based device control using matlab

int getIntNum(int pin) {

/* returns the interrupt number for a given interrupt pin

see http://arduino.cc/it/Reference/AttachInterrupt */

switch(pin) {

case 2:

return 0;

case 3:

return 1;

case 21:

return 2;

case 20:

return 3;

case 19:

return 4;

case 18:

return 5;

default:

return -1;

}

}

/* auxiliary debouncing function */

void debounce(int del) {

int k;

for (k=0;k<del;k++) {

/* can't use delay in the ISR so need to waste some time

perfoming operations, this uses roughly 0.1ms on uno */

k = k +0.0 +0.0 -0.0 +3.0 -3.0;

}

}

Page 55: Final  report  on  gui based device control using matlab

/* Interrupt Service Routine: change on pin A for Encoder 0 */

void isrPinAEn0(){

/* read pin B right away */

int drB = digitalRead(Enc[0].pinB);

/* possibly wait before reading pin A, then read it */

debounce(Enc[0].del);

int drA = digitalRead(Enc[0].pinA);

/* this updates the counter */

if (drA == HIGH) { /* low->high on A? */

if (drB == LOW) { /* check pin B */

Enc[0].pos++; /* going clockwise: increment */

} else {

Enc[0].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on A */

if (drB == HIGH) { /* check pin B */

Enc[0].pos++; /* going clockwise: increment */

} else {

Enc[0].pos--; /* going counterclockwise: decrement */

}

} /* end counter update */

Page 56: Final  report  on  gui based device control using matlab

} /* end ISR pin A Encoder 0 */

/* Interrupt Service Routine: change on pin B for Encoder 0 */

void isrPinBEn0(){

/* read pin A right away */

int drA = digitalRead(Enc[0].pinA);

/* possibly wait before reading pin B, then read it */

debounce(Enc[0].del);

int drB = digitalRead(Enc[0].pinB);

/* this updates the counter */

if (drB == HIGH) { /* low->high on B? */

if (drA == HIGH) { /* check pin A */

Enc[0].pos++; /* going clockwise: increment */

} else {

Enc[0].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on B */

if (drA == LOW) { /* check pin A */

Enc[0].pos++; /* going clockwise: increment */

} else {

Enc[0].pos--; /* going counterclockwise: decrement */

}

Page 57: Final  report  on  gui based device control using matlab

} /* end counter update */

} /* end ISR pin B Encoder 0 */

/* Interrupt Service Routine: change on pin A for Encoder 1 */

void isrPinAEn1(){

/* read pin B right away */

int drB = digitalRead(Enc[1].pinB);

/* possibly wait before reading pin A, then read it */

debounce(Enc[1].del);

int drA = digitalRead(Enc[1].pinA);

/* this updates the counter */

if (drA == HIGH) { /* low->high on A? */

if (drB == LOW) { /* check pin B */

Enc[1].pos++; /* going clockwise: increment */

} else {

Enc[1].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on A */

if (drB == HIGH) { /* check pin B */

Enc[1].pos++; /* going clockwise: increment */

} else {

Enc[1].pos--; /* going counterclockwise: decrement */

}

Page 58: Final  report  on  gui based device control using matlab

} /* end counter update */

} /* end ISR pin A Encoder 1 */

/* Interrupt Service Routine: change on pin B for Encoder 1 */

void isrPinBEn1(){

/* read pin A right away */

int drA = digitalRead(Enc[1].pinA);

/* possibly wait before reading pin B, then read it */

debounce(Enc[1].del);

int drB = digitalRead(Enc[1].pinB);

/* this updates the counter */

if (drB == HIGH) { /* low->high on B? */

if (drA == HIGH) { /* check pin A */

Enc[1].pos++; /* going clockwise: increment */

} else {

Enc[1].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on B */

if (drA == LOW) { /* check pin A */

Enc[1].pos++; /* going clockwise: increment */

} else {

Enc[1].pos--; /* going counterclockwise: decrement */

Page 59: Final  report  on  gui based device control using matlab

}

} /* end counter update */

} /* end ISR pin B Encoder 1 */

/* Interrupt Service Routine: change on pin A for Encoder 2 */

void isrPinAEn2(){

/* read pin B right away */

int drB = digitalRead(Enc[2].pinB);

/* possibly wait before reading pin A, then read it */

debounce(Enc[2].del);

int drA = digitalRead(Enc[2].pinA);

/* this updates the counter */

if (drA == HIGH) { /* low->high on A? */

if (drB == LOW) { /* check pin B */

Enc[2].pos++; /* going clockwise: increment */

} else {

Enc[2].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on A */

if (drB == HIGH) { /* check pin B */

Enc[2].pos++; /* going clockwise: increment */

} else {

Page 60: Final  report  on  gui based device control using matlab

Enc[2].pos--; /* going counterclockwise: decrement */

}

} /* end counter update */

} /* end ISR pin A Encoder 2 */

/* Interrupt Service Routine: change on pin B for Encoder 2 */

void isrPinBEn2(){

/* read pin A right away */

int drA = digitalRead(Enc[2].pinA);

/* possibly wait before reading pin B, then read it */

debounce(Enc[2].del);

int drB = digitalRead(Enc[2].pinB);

/* this updates the counter */

if (drB == HIGH) { /* low->high on B? */

if (drA == HIGH) { /* check pin A */

Enc[2].pos++; /* going clockwise: increment */

} else {

Enc[2].pos--; /* going counterclockwise: decrement */

}

} else { /* must be high to low on B */

if (drA == LOW) { /* check pin A */

Enc[2].pos++; /* going clockwise: increment */

Page 61: Final  report  on  gui based device control using matlab

} else {

Enc[2].pos--; /* going counterclockwise: decrement */

}

} /* end counter update */

} /* end ISR pin B Encoder 2 */

As the program is uploaded in Arduino we open the Matlab window and go for the

instrument tool box. As we find the GUI tool we use it to create push buttons so as to

control the leds connected to the arduino. As the progam is uploaded in matlab command

window we need to make declaration for the controller whose program is described as

below:

clear all;

global a;

a= arduino(‘com 1’);

a= pinMode(4,’output’);

a= pinMode(8,’output’)

The name of push buttons can be changed by changing string name.

In simple control of two leds , two pushbuttons are being created in the gui tool then the

codes to be written to control the output of arduino through pushbutton is given as

For pushbutton 1

a=digitalwrite(4,0);

a=digitalwrite(8,1);

For pushbutton 2

a=digitalwrite(4,1);

a=digitalwrite(8,0);

Page 62: Final  report  on  gui based device control using matlab

By executing this program a GUI is created for arduino such that by clicking on the

pushbuttons we can control our leds.

Conclusion and Future Scope of Work:

The above project is a simple demonstration of the real time home automation system that

we wish to control using microcontrollers. In this project we have demonstrated to link

the Matlab to control arduino output. Here only pushbuttons are to be used by the user so

no need to write the program again and again once the declaration has been done.

This project doesn’t need exceptional coding skills for arduino and matlab. A simple

knowledge to both can work help the user fulfill his basic home and office tasks. Now this

can be extended for home automation, industrial automation, vehicle automation and

numerous fields using gsm module/ bluetooth/ android application/ dtmf .

For eg if we use gsm module we can connect with arduino via transmitter and receiver

pins then by programming the gsm module using AT commands we can control the basic

home appliances just by dialing the phone no. associated with the gsm module .

References:

[1]O.González, M. Rodríguez, A. Ayala, J. Hernández & S. Rodríguez, “Application of

PIC and microcontrollers in the measurement and control of parameters in industry” in

International Journal of Electrical Engineering Education, 41/3, 2004, pp. 266-274.

[2]M.R. Frankowiak, R.I. Grosvenor, and P.W. Prickett, “Microcontroller- Based Process

Monitoring Using Petri-Nets”, EURASIP Journal on Embedded Systems, vol. 2009,

Article ID 282708, 2009.

[3]S. R. D. Kalingamudali et al., “Remote Controlling and Monitoring System to Control

Electric Circuitry through SMS using a Microcontroller”, Industrial and Information

Page 63: Final  report  on  gui based device control using matlab

Systems, First International Conference on Industrial and Information Systems:

Peradeniya, Sri Lanka, 8-11 August, 2006. pp. 378-382.

[4]M. L. Glaze, “The Design and Implementation of a GUI-Based Control Allocation

Toolbox in the MATLAB® Environment”, Msc. Thesis, Virginia Polytechnic Institute

and State University, Blacksburg, 85 p. 2008.

[5] A. Delgado, R. Picking and V. Grout, “Remote-Controlled Home Automation

Systems with Different”,Centre for Applied Internet Research (CAIR), 2006.

[6] A. Alkar and U. Buhur, “An Internet Based Wireless Home Automation System for

Multifuntional Devices”,2005.

[7] N. Sriskanthan, F.Tan and A. Karande, “Bluetooth based home automation system”

ELSEVIER - Microprocessors and Microsystems, Vol. 26, pp. 281-289, 2002.

[8] R. Piyare and M. Tazil, “BLUETOOTH BASED HOME AUTOMATION SYSTEM

USING CELL PHONE”, IEEE International Symposium on Consumer Electronics, Vol.

15, 2011.

[9] I. Petrov, S. Seru, and S. Petrov, “HOME AUTOMATION SYSTEM”, School of

Engineering Science, 2011.

[10] A. Jadhav, and P. Gadhari, “Interactive Voice Response (IVR) and GSM Based

Control System”. Proceedings of the National Conference "NCNTE-2012". Mumbai.

2012

[11] S. Neng, et al., “ integrated, flexible, and Internet-based control architecture for

home automation system in the internet era”. Proceedings ICRA `02. IEEE International

Conference on Robotics and Automation, Vol. 2,pp.1101-1106, 2002.

[12] E. Yavuz, et al., “Safe and Secure PIC Based Remote Control Application for

Intelligent Home”. International Journal of Computer Science and Network Security,

Vol. 7, No. 5, May 2007.

[13] B. Koyuncu, “PC remote control of appliances by using telephone lines”. IEEE

Transaction on Consumer Electronics, Vol. 41, No. 1, pp.201-209, 1995

[14]M. AL-Rousan, et al., “Java-Based Home Automation System”. IEEE Transaction on

Consumer Electronics,Vol. 50, No. 2, May 2004.

[15]B. Myers, et al., “Taking handheld devices to the next level”. IEEE Computer

Society, December, pp. 36-45,2004.

Page 64: Final  report  on  gui based device control using matlab

AAs the