0% found this document useful (0 votes)
122 views108 pages

Remote Home Automation Through Internet

research paper

Uploaded by

amlakie tazeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views108 pages

Remote Home Automation Through Internet

research paper

Uploaded by

amlakie tazeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 108

REMOTE CONTROL HOME

AUTOMATION THROUH INTERNET

Submitted by:
Anum Javed 2007-Elect-185
Noshaba Nasir 2007-Elect-188

Supervised by: Dr. Zubair A. Khan

Department of Electrical Engineering


University of Engineering and Technology Lahore
REMOTE CONTROL HOME
AUTOMATION THROUH INTERNET

Submitted to the faculty of the Electrical Engineering Department


of the University of Engineering and Technology Lahore
in partial fulfillment of the requirements for the Degree of
Bachelor of Science
in
Electrical Engineering.

-------------------------- ----------------------------
Internal Examiner External Examiner

------------------------------
Director
Undergraduate Studies

Department of Electrical Engineering


University of Engineering and Technology Lahore

i
Declaration
We declare that the work contained in this thesis is my own, except
where explicitly stated otherwise. In addition this work has not
been submitted to obtain another degree or professional
qualification.

Signed:__________________ Signed:_____________________

Date:___________________ Date:_______________________

ii
Acknowledgments

First of all, We thank to ALLAH for giving us strength and ability to complete our final
year project. I am sincerely grateful to our advisor Dr. Zubair A Khan for his
cooperation and help.
We would also like to express our gratefulness to Sir Sohail (KICS) who helped us in
debugging hardware of our project.

iii
Dedicated to our Teachers and our Parents…

iv
TABLE OF CONTENTS
Acknowledgments……….…………………...………………………………………….iii
LIST OF FIGURES & TABLE..…………...…………………….…………………...viii
ABBREVIATIONS…….…………....…………...…………...………….……………...ix
ABSTRACT……….….…………...…………...…………...…………………………….x
CHAPTER 1………………………………………………………………………………………1
INTRODUCTION…………………………………………………………….………………...1
1.1OBJECTIVE………..…....………………………………...……………………...…………1
1.2 OVERVIEW……………………..……………………..……………………………………..1

CHAPTER 2………………..…………………………………………………………….……..3
TOOLS & COMPONENTS USED…………………………………………………………….3
2.1 TOOLS……………………………………………………………………………….……...3
2.1.1VISUAL STUDIO 2008…………………….………………...…………...………...……. 4
2.1.1.1 FEATURES…..………………...……………….…………………………………...5
2.1.2 PCWHD IDE COMPILER FOR MICROCHIP PIC……………………..…..…..…. 8
2.2 COMPONENTS USED IN HARDWARE…………………….…………………………....9
2.2.1 POWER SUPPLY……….………….…………………………………………………..10
2.2.1.1 PIN CONFIGURATION OF LM7805………………………………..……………….11
2.2.2 SERIAL PORT…………………………..…………...………………………………...11
2.2.2.1 PIN CONFIGURATION OF SERIAL PORT……………………..…...………….13
2.2.2.2 FLOW CONTROL……………..……….……………………..……....…………...14
2.2.2.3 BAUD RATE…………………….………..…………………………………………...14
2.2.3 MAX232- LEVEL CONVERTER…………………….……..………………….....…15
2.2.4 SWITCHES………………….….………………………………….…………………….16
2.2.4.1 RELAY……………...………………..…….………………………………………….17
2.2.4.2 TRANSISTORS …………………..…………………………………...………………..18
2.2.4.3 OPTOCOUPLERS……………………...…………………………………………….. 19
2.2.5 MICROCONTROLLER PIC …………………………..……………………………..20

CHAPTER 3 ………………..…………………………..……………………………………..22
SOFTWARE AND HARDWAREDESCRIPTION……………….…………………………..22
3.1 SECTIONS…………..……………………….………………………………………….. 22
3.2 WINDOWS APPLICATION………………..………………………………………….. 23
v
3.2.1 SERVER APPLICATION………………..…………………………………………..24
3.2.2 CLIENT APPLICATION………………..…………………………………………….. 26
3.3 STRUCTURE OF TCP/IP………………..………...………………………………….. 28
3.3.1 MAIN FEATURES OF TCP/IP ………………..………………………………………..29
3.3.1.1 SCOPE ………………..………………………………………………………………..29
3.3.1.2 INTERFACES ………………..…………………………………….………………..30
3.3.1.3 MOTIVATION ………………..……………………………………………………..30
3.3.1.4 CONNECTION ORIENTED ………………..………………………………..……..31
3.3.1.4 OPERATION………………..………………………………...…………………….. 31
3.3.2 RELIABLE COMMUNICATION ………………..……………………...…………..34
3.3.2.1 CONNECTION ESTABLISHMENT AND CLEARING …………………..……34
3.3.2.2 DATA COMMUNICATION ………………..………………….…………………..34
3.3.2.3 ROBUSTNESS PRINCIPLE ………………………………………………...……..35
3.3.3 HEADER FORMAT ………………..……………………………………..…………..35
3.4 SOCKET PROGRAMMING ………………..…………………………………………..37
3.4.1 C# SERVER SOCKET PROGRAM……………..………………………………….. 38
3.4.2 CLIENT SOCKET PROGRAM ………………..…………………………….……..39
3.5 HARDWARE ………………..………………………………………………………...….. 39
3.5.1 SERIAL PROGRAMMING IN PIC ………………..……………………………….. 39
3.5.1.1 SOFTWARE UART LIBRARY ………………..…………………………………..40
3.5.1.2 HARDWARE USART LIBRARY………………..……………………………….. 41
3.5.2 HARDWARE DESCRIPTION ………………..……………………………………….. 43

CHAPTER 4 ………………..………………………………….……………………………..45
CONCLUSION ………………..………………………………….………………………….. 45
4.1 USES AND SCOPE………………..………………….…………………………………..45
4.1.1 SWITCH ON/OFF ELECTRONIC APPLIANCES (DESKTOP/WEB BASED)..…. 46
4.1.2 TIMER TO AUTOMATICALLY SWITCHING (ON/OFF) ELECTRONIC
APPLIANCES…………………………………………………………………………………..46
4.1.3 LOUD ALARM TO ALERT ABOUT DANGER…………………………………….. 46
4.1.4 LIVE STREAMING VIDEOS OF HOUSE THROUGH ONLINE SECURITY
CAMERAS……………………………………………………………………………………..47

vi
4.1.5 CAPTURES PICTURES OF REMOTE LOCATION……..……………………….. 47
4.1.6 CONTROL ELECTRONIC DOOR LOCKS ………………..………………………..47
4.2 FUTURE ASPECTS ………………..……………...………..……………………………..47

APPENDIX A……………………………………………………………………………………49

APPENDIX B…………………………………………………………………………………....66

REFERENCES………………………………………………………………………………….97

vii
LIST OF FIGURES AND TABLE

Figure 1.1 Role and Link of Basic Components……….……………………………...………..2


Figure 2. 1 Sections ……………………………………………………………………………...3
Figure 2.2 Hardware Connections……………………………………………………………...10
Figure 2. 3 Power Supply……………………………………………………………………….10
Figure 2. 4 Pin configuration of LM7805……………………………………………………... 11
Figure 2. 5 Nine Pin Serial Port ………………………………………………………………..12
Figure 2. 6 pin configuration of 9 pin serial port ………………………………………….. 13
Figure 2. 7 MAX 232 top view…………………………………………………………………16
Figure 2. 8 Pin configuration of Relay ……………………………………………………….17
Figure 2. 9 [4] BJT used as an electrical switch in grounded emitter configuration ………19
Figure 2. 10 usage of opt coupler in a simple circuit………………………………………...19
Figure 2. 11 Top View of PIC 16F877A…………………….………………………………… 21
Figure 3. 1 Block Diagram of Project…………………………………………………………. 23
Figure 3. 2 Server GUI ………………………………………………………………………..24
Figure 3. 3 Flow Chart of Server Application……………………………………………… 25
Figure 3. 4 Client GUI ………………………………………………………………………... 26
Figure 3. 5 Flow Chart Of Client Application……………………………………………... 27
Figure 3. 6 Error in Connectivity………………………………………………………….. 28
Figure 3. 7 Protocol Layer …………………………………………………………………..29
Figure 3. 8 TCP Header Format ……………………………………………………………. 35
Figure 3. 9 Socket programming………………………………………………………….…. 38
Figure 3. 10 Sending Character “A” in serial communication ……...………………………40
Figure 3. 11 Schematics of Hardware……………………………………………………… 43
Figure 3. 12 Flow Chart Of Hadware’s Work ………………………………………………44
Table 2. 1 Pin description of 9 pin serial port …………………………………..……………13

viii
ABBREVATIONS

ASP.Net--- Active service page


API ---------Application Programming Interface
DPDT-----double pole double through
EMF------- Electromotive Force
SPDT-----Single pole double through
TCP------- Transmission Control Protocol
XML ------Extensible Markup Language
UDP--- User Datagram Protocol

ix
ABSTACT
Our project basically is an IP based control system, which can be accessed where the
internet facility available and it provide you remote control of any device without any
physical contact. By doing this project we learned learn a lot about the working of
IP based systems, micro controllers, and many more applications of electronic subjects.
The basic idea is to take advantage of the vast explosion of cell phones and internet
access through cell phones and to extend human’s reach and possibilities.

With Internet Protocol as the backbone of an enterprise-wide network, everything that


requires a standalone network today simply becomes subsumed into the IP master. This is
interoperability at the very highest level. In the building management sector of this new
environment, controllers are designed for the IP network. More importantly, they are also
designed to thrive on the IP network.

Our system is designed only to activate or deactivate devices at home and to get the
current status of the device. But the application of this type of remote control is
limited only by one’s imagination. For example Lighting, Appliances, Heating and
cooling, Security and monitoring systems, Entertainment ( home audio and video ) ,
Communications ( telephones and intercoms, internet ) , Lawn sprinklers, Curtain
movements, Pool filter pump, Spa heater, Filtration unit, Gate/garage door motor, Shade
motor control, Roof sprinklers, Electric strikes, Keyless entry etc can also be controlled.
This concept can also be implemented in small business where we need to connect few
systems to a server or we need to interconnect few systems.

In short it is versatile and easy to use.

x
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

CHAPTER 1

INTRODUCTION
1.1 OBJECTIVE
The main objective of our project is to design a system through which the user
will be able to operate electric home appliances remotely via internet. This project has
been beneficial for us in expanding our knowledge of remote control systems, as it is
growing rapidly . This project provides a lot of learning edge about the working of IP
based systems, microcontrollers, and utilization of electronic components. The scope and
users of this internet remote control system will grow with the expansion of the number
of internet consumers around the world. Our system is a prototype designed only to
activate / deactivate electrical appliances at home and to get the current status of the
device. But the utilization of this type of remote control is very vast. The primary idea is
to exploit the vast explosion of cellular or mobile phones and other portable and mobile
internet devices.

The report gives all the fundamental details of hardware and software design and the
strategy to build the system.

1.2 OVERVIEW
Our system, through internet connects the user to devices at home. The user
can be anywhere in the world , and can control the home appliances through internet
at a remote place . The user who wants to access his/her home from a remote place,
he/she should have to install the client software and server software will be installed at
home‟s pc . User will access his / her home through this client software. We developed
the Client and Server application on Visual Studio 2008, both Client and Server
Applications are user friendly, anyone having a little knowledge of computer can easily
use it . A Client and Server application will enable a user (client) to send a request to the
1
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Server and in response server will activate / deactivate any device . We have
assigned an IP address to our server, so that it can be accessed by using an internet cloud.

Figure 1.1 Role and Link of Basic Components

Server is connected locally with the microcontroller (PIC) which acts as a decoder and
eventually control the home devices through electrically operated switches . The role
and link of these components is indicated in a Figure 1.1.

In the proceeding chapter the tools and components used to make the whole project are
discussed, then chapter 3 will give a detailed description of hardware and software
followed by conclusion.

2
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

CHAPTER 2

TOOLS & COMPONENTS USED

This chapter will give description of the tools used to develop software applications and
hardware codes, and major components used in Hardware.

Figure 2. 1 Sections

2.1 TOOLS
Software tools used in the project are:

 Visual Studio 2008


 PCWHD IDE Compiler for Microchip PIC
 Proteus

3
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

2.1.1 VISUAL STUDIO 2008

Visual Studio .NET is Microsoft‟s integrated development environment (IDE) for


creating, documenting, running and debugging programs written in a variety of .NET
programming languages. Visual Studio is a complete set of development tools for
building ASP.NET Web applications, XML Web Services, desktop applications, and
mobile applications. Visual Basic, Visual C#, and Visual C++ all use the same integrated
development environment (IDE), which enables tool sharing and eases the creation of
mixed-language solutions. It is used to develop console and graphical user
interface applications along with Windows Forms applications, web sites, web
applications, and web services in both native code together with managed code for all
platforms supported by Microsoft Windows, Windows Mobile, Windows CE, .NET
Framework and Microsoft Silverlight.

In June 2000, Microsoft announced its .NET initiative, a broad new vision for embracing
the Internet and the Web in the development, engineering and use of software. One key
aspect of the .NET strategy is its independence from a specific language or platform.
Rather than forcing developers to use a single programming language, developers can
create a .NET application in any .NET-compatible language. Programmers can contribute
to the same software project, writing code in the .NET languages (such as C#, Visual
C++ .NET, Visual Basic .NET and many others) in which they are most competent. Part
of the initiative includes Microsoft‟s Active Server Pages (ASP) .NET technology, which
allows programmers to create applications for the Web.
The .NET architecture can exist on multiple platforms, further extending the portability
of .NET programs. In addition, the .NET strategy involves a new program-development
process that could change the way programs are written and executed, leading to
increased productivity.
A key component of the .NET architecture is Web services, which are applications that
can be used over the Internet. Clients and other applications can use these Web services
as reusable building blocks.
Visual programming has become popular, because it enables programmers to create
applications easily, using such prepackaged components as buttons, text boxes and

4
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

scrollbars. Similarly, programmers may create an application using Web services for
databases, security, authentication, and data storage and language translation without
having to know the internal details of those components. [9]

2.1.1.1 FEATURES

a. Code editor

Visual Studio, like any other IDE, includes a code editor that supports syntax
highlighting and code completion using IntelliSense for not
only variables, functions and methods but also language constructs like loops and queries.
IntelliSense is supported for the included languages, as well as for XML and
for Cascading Style Sheets and JavaScript when developing web sites and web
applications. Auto complete suggestions are popped up in a modeless list box, overlaid
on top of the code editor. In Visual Studio 2008 onwards, it can be made temporarily
semi-transparent to see the code obstructed by it. The code editor is used for all supported
languages.[1]

The Visual Studio code editor also supports setting bookmarks in code for quick
navigation. Other navigational aids include collapsing code blocks and incremental
search, in addition to normal text search The code editor also includes a multi-
item clipboard and a task list. The code editor supports code snippets, which are saved
templates for repetitive code and can be inserted into code and customized for the project
being worked on. A management tool for code snippets is built in as well. These tools are
surfaced as floating windows which can be set to automatically hide when unused or
docked to the side of the screen. The Visual Studio code editor also supports code
refactoring including parameter reordering, variable and method renaming,
interface extraction and encapsulation of class members inside properties, among others.

Visual Studio features background compilation (also called incremental compilation). As


code is being written, Visual Studio compiles it in the background in order to provide
5
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

feedback about syntax and compilation errors, which are flagged with a red wavy
underline. Warnings are marked with a green underline. Background compilation does
not generate executable code, since it requires a different compiler than the one used to
generate executable code. Background compilation was initially introduced
with Microsoft Visual Basic but has now been expanded for all included languages.[1]

b. Debugger

Visual Studio includes a debugger that works both as a source-level debugger and as a
machine-level debugger. It works with both managed code as well as native code and can
be used for debugging applications written in any language supported by Visual Studio.
In addition, it can also attach to running processes and monitor and debug those
processes. If source code for the running process is available, it displays the code as it is
being run. If source code is not available, it can show the disassembly. The Visual Studio
debugger can also create memory dumps as well as load them later for debugging. Multi-
threaded programs are also supported. The debugger can be configured to be launched
when an application running outside the Visual Studio environment crashes.

The debugger allows setting breakpoints (which allow execution to be stopped


temporarily at a certain position) and watches (which monitor the values of variables as
the execution progresses).Breakpoints can be conditional, meaning they get triggered
when the condition is met. Code can be stepped over, i.e., run one line (of source code) at
a time. It can either step into functions to debug inside it, or step over it, i.e., the
execution of the function body isn't available for manual inspection. The debugger
supports Edit and Continue, i.e., it allows code to be edited as it is being debugged (32 bit
only; not supported in 64 bit). When debugging, if the mouse pointer hovers over any
variable, its current value is displayed in a tooltip ("data tooltips"), where it can also be
modified if desired. During coding, the Visual Studio debugger lets certain functions be
invoked manually from the immediate tool window. The parameters to the method are
supplied at the immediate window.

c. Designer

Visual Studio includes a host of visual designers to aid in the development of


applications. These tools include:

6
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Windows Forms Designer


The Windows Forms designer is used to build GUI applications using Windows
Forms. It includes a palette of UI widgets and controls (including buttons,
progress bars, labels, layout containers and other controls) that can be dragged
and dropped on a form surface. Layout can be controlled by housing the controls
inside other containers or locking them to the side of the form. Controls that
display data (like textbox, list box, grid view, etc.) can be bound to data sources
like databases or queries. The UI is linked with code using an event-driven
programming model. The designer generates either C# orVB.NET code for the
application.
WPF Designer
The WPF designer, codenamed Cider, was introduced with Visual Studio 2008.
Like the Windows Forms designer it supports the drag and drop metaphor. It is
used to author user interfaces targeting Windows Presentation Foundation. It
supports all WPF functionality including data binding and automatic layout
management. It generates XAML code for the UI. The generated XAML file is
compatible with Microsoft Expression Design, the designer-oriented product. The
XAML code is linked with code using a code-behind model.
Web designer/development
Visual Studio also includes a web-site editor and designer that allow web pages to
be authored by dragging and dropping widgets. It is used for
developing ASP.NET applications and supports HTML, CSS and JavaScript. It
uses a code-behind model to link with ASP.NET code. From Visual Studio 2008
onwards, the layout engine used by the web designer is shared with Microsoft
Expression Web.

Class designer
The Class Designer is used to author and edit the classes (including its members
and their access) using UML modeling. The Class Designer can
generate C# and VB.NET code outlines for the classes and methods. It can also
generate class diagrams from hand-written classes.

7
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Data designer
The data designer can be used to graphically edit database schemas, including
typed tables, primary and foreign keys and constraints. It can also be used to
design queries from the graphical view.[1]

Mapping designer
From Visual Studio 2008 onwards, the mapping designer is used by LINQ to
SQL to design the mapping between database schemas and the classes that
encapsulate the data. The new solution from ORM approach, ADO.NET Entity
Framework, replaces and improves the old technology.[1]

2.1.2 PCWHD IDE COMPILER FOR MICROCHIP PIC

CCS provides a complete, integrated tool suite for developing and debugging
embedded applications running on Microchip PIC®MCUs and dsPIC® DSCs. This suite
includes an IDE for project management, a context sensitive C aware editor, build tools
and real time debugger...helping developers create, analyze, debug and document project
code.

The CCS IDE allows developers to manage every aspect of their embedded software
development, from code creation through device programming. External programs can be
invoked from the IDE, simplifying integration with other programmers and debuggers.

The heart of this development tool suite is the CCS intelligent code optimizing C
compiler, which frees developers to concentrate on design functionality instead of having
to become an MCU architecture expert. Maximize code reuse by easily porting from one
MCU to another. Minimize lines of new code with CCS provided peripheral drivers,
built-in functions and standard C operators. Built in libraries are specific to PIC ® MCU
registers, allowing access to hardware features directly from C.

The PCWHD compiler supports the Microchip PIC® PIC10, PIC12, PIC16, PIC18,
PIC24 MCU families and dsPIC® DSCs.

8
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PCWHD Compiler includes: Standard C pre-processors, operators and statements,


interrupt handlers, discrete I/O, multiple compilation units, constants in ROM, float,
ICSP and in-circuit debugging capabilities. For more detailed information on the features
and functions of the PCWHD compiler.

PCD is a C Compiler for Microchip's 24bit opcode family of microcontrollers, which


include the dsPIC30, dsPIC33 and PIC24 families. The compiler is specifically designed
to meet the unique needs of the dsPIC® microcontroller. This allows developers to
quickly design applications software in a more readable, high-level language.
The compiler can efficiently implement normal C constructs, input/output operations, and
bit twiddling operations. All normal C data types are supported along with special built in
functions to perform common functions in the MPU with ease. [2]

2.2 COMPONENTS USED IN HARDWARE

Following are the components used in Hardware

 Power Supply

 Serial Cable

 LM7805

 MAX232S

 Switches

 Micro-controller(PIC)

 Oscillator 4 MHz.

 LEDs

 Capacitor

 Resistors

9
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 2.2 shows the component and connections of hardware circuit

Figure 2.2 Hardware Connections

2.2.1 POWER SUPPLY

To meet the power requirements of microcontroller and other component used in circuit a
5V regulated power is supplied using LM7805 IC, as shown in Figure 2.3.
The capacitors are used for filtration

The output voltage and current


10

Figure 2. 3 Power Supply


REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

is +5V and 100mA respectively, the current can be increased to 1A by providing proper
cooling to LM7805 IC. The capacitors used at input and output terminal should have
voltage rating compatible with the input and output voltage

If a voltage level of more than +5V is required, the circuit can be modified by
replacing the 7805 chips with another regulator with different output voltage from
regulator 78xx chip family. The last numbers in the chip code tells the output voltage.

To keep the regulator working properly the input voltage level must be +3V higher than
the required output voltage.

2.2.1.1 PIN CONFIGURATION OF LM7805:

Figure 2.4 shows the pin configuration of LM7805

Pin 1. Unregulated voltage in

Pin 2. Ground

Pin 3. Regulated voltage out

Data Sheet of LM7805 is given in Appendix B Figure 2. 4 Pin configuration of LM7805

2.2.2 SERIAL PORT

The serial port is an I/O (Input/output) device. An I/O device is just a way to get data into
and out of a computer. There are many types of I/O devices such as serial ports, parallel
ports, disk drive controllers, Ethernet boards, universal serial buses, etc. Most PC's have
one or two serial ports.

11
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Each has a 9-pin connector (sometimes 25-pin) (Figure 2.5) on the back of the computer.
Computer programs can send data (bytes) to the transmit pin (output) and receive bytes
from the receive pin (input). The other pins are for control purposes and ground.

The name "serial" comes from the fact that a serial port "serializes" data. That is, it takes
a byte of data and transmits the 8 bits in the byte one at a time. The advantage is that a
serial port needs only one wire to transmit the 8 bits (while a parallel port needs 8). The
disadvantage is that it takes 8 times longer to transmit the data than it would if there were
8 wires. Serial ports lower cable costs and make cables smaller.

Before each byte of data, a serial port sends a start bit, which is a single bit with a value
of 0. After each byte of data, it sends a stop bit to signal that the byte is complete. It may
also send a parity bit.

Figure 2. 5 Nine Pin Serial Port

Serial ports, also called communication (COM) ports, are bi-directional. Bi-directional
communication allows each device to receive data as well as transmit it. Serial devices
use different pins to receive and transmit data -- using the same pins would limit
communication to half-duplex, meaning that information could only travel in one
direction at a time. Using different pins allows for full-duplex communication, in which
information can travel in both directions at once.

12
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

2.2.2.1 PIN CONFIGURATION OF SERIAL PORT

Figure 2.6 and Table 2.1 shows pin configuration of serial port

Figure 2. 6 pin configuration of 9 pin serial port

Table 2. 1 Pin description of 9 pin serial port


13
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

2.2.2.2 FLOW CONTROL

Flow control means the ability to slow down the flow of bytes in a wire. An important
aspect of serial communications is the concept of flow control. This is the ability of one
device to tell another device to stop sending data for a while. The commands Request to
Send (RTS), Clear To Send (CTS), Data Terminal Ready (DTR) and Data Set Ready
(DSR) are used to enable flow control. Let's look at an example of how flow control
works: You have a modem that communicates at 56 Kbps. The serial connection between
your computer and your modem transmits at 115 Kbps, which is over twice as fast. This
means that the modem is getting more data coming from the computer than it can
transmit over the phone line. Even if the modem has a 128K buffer to store data in, it will
still quickly run out of buffer space and be unable to function properly with all that data
streaming in.

With flow control, the modem can stop the flow of data from the computer before it
overruns the modem's buffer. The computer is constantly sending a signal on the Request
to send pin, and checking for a signal on the Clear to send pin. If there is no Clear to send
response, the computer stops sending data, waiting for the Clear to send before it
resumes. This allows the modem to keep the flow of data running smoothly. One key
difference between a serial and parallel port is that the serial port allows for data to be
transferred in from a remote device or transferred out from the hard drive to a remote
device. This two-way communication process makes it possible to connect work stations
to larger terminals as well as a wide range of peripheral devices.

2.2.2.3 BAUD RATE

The baud unit is named after Jean Maurice Emile Baudot, who was an officer in the
French Telegraph Service. He is credited with devising the first uniform- length 5-bit
code for characters of the alphabet in the late 19th century. What baud really refers to is
modulation rate or the number of times per second that a line changes state. This is not
always the same as bits per second (BPS). If you connect two serial devices together
using direct cables then baud and BPS are in fact the same.
14
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Serial communication using RS-232 requires that is specified by four parameters: the
baud rate of the transmission, the number of data bits encoding a character, the sense of
the optional parity bit, and the number of stop bits.

In our project we have used 9600 as the baud rate since the mobile set we are using
communicates at this baud rate. We have introduced 8 bits as the data and one bit as the
stop. Now the total time for one bit is (1/9600)/ (8+1) = 0.1157µs. [3]

2.2.3 MAX232- LEVEL CONVERTER

The MAX232 is an integrated circuit that converts signals from an RS-232 serial port to
signals suitable for use in TTL compatible digital logic circuits. The MAX232 is a dual
driver/receiver and typically converts the RX, TX, CTS and RTS signals.

The drivers provide RS-232 voltage level outputs (approx. ± 7.5 V) from a single
+ 5 V supply via on-chip charge pumps and external capacitors. This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0 V
to + 5 V range, as power supply design does not need to be made more complicated just
for driving the RS-232 in this case.

The receivers reduce RS-232 inputs (which may be as high as ± 25 V), to standard
5 V TTL levels. These receivers have a typical threshold of 1.3 V, and a
typical hysteresis of 0.5 V.

Figure 2.7 shows pin configuration of MAX232,and figure 2.1 shows how it is used
in our circuit

15
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 2. 7 MAX 232 top view

It is helpful to understand what occurs to the voltage levels. When a MAX232 IC


receives a TTL level to convert, it changes a TTL Logic 0 to between +3 and +15 V, and
changes TTL Logic 1 to between -3 to -15 V, and vice versa for converting from RS232
to TTL. This can be confusing when you realize that the RS232 Data Transmission
voltages at a certain logic state are opposite from the RS232 Control Line voltages at the
same logic state. [3]To clarify the matter, see the Data Sheet in Appendix B.

2.2.4 SWITCHES

To turn on/off an electrical device upon the signal of micro controller an electrically
operated switch is necessary. Only one or combination of two or nore switches can be
used according to the voltage and current requirements of the device.

Some of them which we used are

 Relay
 Transistor

16
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

 Optocoupler

2.2.4.1 RELAY

A relay is an electrically operated switch. Current flowing through the coil of the relay
creates a magnetic field which attracts a lever and changes the switch contacts. The coil
current can be on or off so relays have two switch positions and most have double
throw (changeover) switch contacts[4] as shown in the Figure 2.8.

Figure 2. 8 Pin configuration of Relay

Relays allow one circuit to switch a second circuit which can be completely separate
from the first. The coil of a relay passes a relatively large current, typically 30mA for a
12V relay, but it can be as much as 100mA for relays designed to operate from lower
voltages. Most ICs (chips) cannot provide this current and a transistor is usually used to
amplify the small IC current to the larger value required for the relay coil.[4]

Relays are usually SPDT or DPDT but they can have many more sets of switch contacts,
for example relays with 4 sets of changeover contacts are readily available.[4]

Referring to figure 3.6 the relay's switch connections are usually labeled COM, NC and
NO :

 COM = Common, always connect to this; it is the moving part of the switch.
 NC = Normally Closed, COM is connected to this when the relay coil is off.
 NO = Normally Open, COM is connected to this when the relay coil is on.

17
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Connect to COM and NO if you want the switched circuit to be on when the relay coil is
on. Connect to COM and NC if you want the switched circuit to be on when the relay
coil is off.

Relay is usually a good choice for switching large currents (> 5A).[4]

2.2.4.2 TRANSISTORS

Like relays, transistors can be used as an electrically operated switch. For switching
small DC currents (< 1A) at low voltage they are usually a better choice than a relay

The essential usefulness of a transistor comes from its ability to use a small signal applied
between one pair of its terminals to control a much larger signal at another pair of
terminals. This property is called gain. A transistor can control its output in proportion to
the input signal; that is, it can act as an amplifier. Alternatively, the transistor can be used
to turn current on or off in a circuit as an electrically controlled switch, where the amount
of current is determined by other circuit elements.

The two types of transistors have slight differences in how they are used in a circuit.
A bipolar transistor has terminals labeled base, collector, and emitter. A small current
at the base terminal (that is, flowing from the base to the emitter) can control or switch a
much larger current between the collector and emitter terminals. For a field-effect
transistor, the terminals are labeled gate, source, and drain, and a voltage at the gate can
control a current between source and drain [5]. The gate or base is connected with output
ports of microcontroller.

The Figure 2.9 represents a typical bipolar transistor in a circuit. Charge will flow
between emitter and collector terminals depending on the current in the base. Since
internally the base and emitter connections behave like a semiconductor diode, a voltage
drop develops between base and emitter while the base current exists.[5]

The amount of this voltage depends on the material the transistor is made from, and is
referred to as VBE.

18
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 2. 9 [4] BJT used as an electrical switch in grounded emitter configuration

Transistors are commonly used as electronic switches, both for high-power applications
such as switched-mode power supplies and for low-power applications such as logic
gates.

2.2.4.3 OPTOCOUPLERS

In electronics, an opto-isolator, also called an optocoupler, photo coupler,


or optical isolator, is an electronic device designed to transfer electrical signals by
utilizing light waves to provide coupling with electrical isolation between its input and
output. The main purpose of an opto-isolator is to prevent high or rapidly changing
voltages on one side of the circuit from damaging components or distorting transmissions
on the other side. Commercially available opto-isolators withstand input-to-output
voltages up to 10 kV and voltage transients with speeds up to 10 kV/μs. An opto-isolator
contains a source (emitter) of light, almost always a near infrared light-emitting
diode (LED), that converts electrical input signal into light, a closed optical channel (also
called dielectric channel), and a photo sensor, which detects incoming light and either
generates electric energy directly, or modulates electric current flowing from an external
power supply.

19

Figure 2. 10 usage of opt coupler in a simple circuit.


REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Using a combination of optocoupler with other switch like transistor is very good
because it will optocoupler will stop any reverse flow of current as it keeps both circuits
completely isolated, and assures the safety of microcontroller.

2.2.5 MICROCONTROLLER PIC

Microcontroller is used as Character Decoder. When a key from remote computer


keyboard is depressed, a code is generated and transmitted to one PC to another. The PIC
microcontroller is used as a decoder which enables or disables one of the 6 output lines
which are used to control external devices.

We have used PIC16F877A microcontroller in our project. Its serial communication


programming is easy to use

PICs are popular with both industrial developers and hobbyists alike due to their low
cost, wide availability, large user base, extensive collection of application notes,
availability of low cost or free development tools, and serial programming (and re-
programming with flash memory) capability.

20
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 2.11 shows the Top View of PIC

For further specifications of PIC see Data Sheet in Appendix B

Figure 2. 11 Top View of PIC 16F877A

21
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

CHAPTER 3

SOFTWARE AND HARDWARE


DESCRIPTION

As the previous chapter gave details of all the essential components used, this chapter
will give details of two parts of our project i.e. hardware and software‟s working

3.1 SECTIONS
Our project has two main sections:
 Software
 Hardware

22
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 3. 1 Block Diagram of Project

As shown in figure 3.1 first of all server client will run application on their system. Client
will send request to server ,in response server will generate a corresponding signal which
is sent to microcontroller , in response to that signal microcontroller will on /off the
requested device

3.2 WINDOWS APPLICATION


Now we will discuss the application which is developed in visual studio 2008. The
application consist of two parts

 Server
 Client

23
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Both of the them are basically windows application and developed in C sharp language.
Firstly we will discuss the SERVER application in detail.

3.2.1 SERVER APPLICATION

The graphical user interface is shown in the following Figure 3.2. Then we will run the
appplication of the server the following window will appear. Thenever we want to
establish the connection with the client, server should be in the ON state.

Figure 3. 2 Server GUI

Once we ON the server, it will generate a message “waiting for client”. We have
basically controlled six devices in our application as shown in figure 3.2. Server
application only shows the status of each device. This status will be set on the bases of
signal sent by the client to server application. The flowchart for SERVER application
code is as follows:

24
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Figure 3. 3 Flow Chart of Server Application

Once the client is found, server will generate a message that “connected to 192.168.0.1,
1092”. Here the 192.168.0.1 (can be any number) is internet protocol and 1092 (can be
any number) is port no. Now connection is established between server and client.

Now whenever client sends a request to on/off a device, a new socket is created, server
will then initialize the serial port “COM6” (for example), and server will send signal to
microcontroller which will on/off the requested device.

25
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.2.2 CLIENT APPLICATION


When we will run the application of the Client the following Figure 3.4 GUI will be seen.

Figure 3. 4 Client GUI

26
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

The client application code is illustrated in the following flowchart Figure 2.5

Figure 3. 5 Flow Chart Of Client Application

First of all client will specify the IP address. And pushes the button CONNECT. If the
server is in “ON” state and the requested IP address is correct, Connection will be
established and the following message appear

Connected to 192.168.0.1, 1011.

Now the client has multiple options, like on/off any device or disconnect. If the client
make a request to ON/OFF the device, a new socket is created, connection is established
and a specific signal is sent to the server .Server will respond to that signal in the same
i.e. it will initialize the COM port and send request to microcontroller.

27
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

If client send the signal to “Disconnect “, connection will be terminated, socket is closed
and hence no more data can be send to the server.

At any stage ,if the server is turned off by the user or any other fault occur , then any
request to server by the client will generate the error message as shown in Figure 3.6.

Figure 3. 6 Error in Connectivity

The source code of server and client are given in Appendix-A

To establish a connection between Server and Clint application we need to use a


protocol..We used Transmission Control Protocol (TCP) is as a highly reliable host-to-
host protocol between hosts in packet-switched computer communication networks, and
in interconnected systems of such networks. The functions to be performed by the
Transmission Control Protocol, the program that implements it, and its interface to
programs or users that require its services.

3.3 Structure of TCP/IP


TCP is based on concepts first described by Cerf and Kahn in . The TCP fits into a
layered protocol architecture just above a basic Internet Protocol which provides a way
for the TCP to send and receive variable-length segments of information enclosed in
internet datagram "envelopes". The internet datagram provides a means for addressing
source and destination TCPs in different networks. The internet protocol also deals with
any fragmentation or reassembly of the TCP segments required to achieve transport and
delivery through multiple networks and interconnecting gateways. The internet protocol

28
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

also carries information on the precedence, security classification of the TCP segments,
so this information can be communicated end-to-end across multiple networks.

higher-level

TCP

internet protocol

internet protocol

Figure 3. 7 Protocol Layer

Some computer systems will be connected to networks via front-end computers which
house the TCP and internet protocol layers, as well as network specific software. The
TCP specification describes an interface to the higher level protocols which appears to be
implementable even for the front-end case, as long as a suitable host-to-front end protocol
is implemented.[6][7]

3.3.1 MAIN FEATURES OF TCP/IP

The following are main features of TCP/IP

3.3.1.1 SCOPE

The TCP is intended to provide a reliable process-to-process communication service in a


multi network environment. The TCP is intended to be a host-to-host protocol in
common use in multiple networks.

29
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.3.1.2 INTERFACES

The TCP interfaces on one side to user or application processes and on the other side to a
lower level protocol such as Internet Protocol. The interface between an application
process and the TCP is illustrated in reasonable detail. This interface consists of a set of
calls much like the calls an operating system provides to an application process for
manipulating files. For example, there are calls to open and close connections and to
send and receive data on established connections. It is also expected that the TCP can
asynchronously communicate with application programs. Although considerable
freedom is permitted to TCP implementers to design interfaces which are appropriate to
a particular operating system environment, a minimum functionality is required at the
TCP/user interface for any valid implementation.

The interface between TCP and lower level protocol is essentially unspecified except that
it is assumed there is a mechanism whereby the two levels can asynchronously pass
information to each other. Typically, one expects the lower level protocol to specify this
interface. TCP is designed to work in a very general environment of interconnected
networks. The lower level protocol which is assumed throughout this document is the
Internet Protocol.

3.3.1.3 MOTIVATION

Computer communication systems are playing an increasingly important role in military,


government, and civilian environments. This document focuses its attention primarily on
military computer communication requirements, especially robustness in the presence of
communication unreliability and availability in the presence of congestion, but many of
these problems are found in the civilian and government sector as well.

30
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.3.1.4 CONNECTION ORIENTED

TCP is a connection-oriented, end-to-end reliable protocol designed to fit into a layered


hierarchy of protocols which support multi-network applications. The TCP provides for
reliable inter-process communication between pairs of processes in host computers
attached to distinct but interconnected computer communication networks. Very few
assumptions are made as to the reliability of the communication protocols below the TCP
layer. TCP assumes it can obtain a simple, potentially unreliable datagram service from
the lower level protocols. In principle, the TCP should be able to operate above a wide
spectrum of communication systems ranging from hard-wired connections to packet-
switched or circuit-switched networks.

3.3.1.4 OPERATION

As noted above, the primary purpose of the TCP is to provide reliable, securable logical
circuit or connection service between pairs of processes. To provide this service on top
of a less reliable internet communication system requires facilities in the following areas:

 Basic Data Transfer


 Reliability
 Flow Control
 Multiplexing
 Connections
 Precedence and Security

Basic Data Transfer

The TCP is able to transfer a continuous stream of octets in each direction between its
users by packaging some number of octets into segments for transmission through the
internet system. In general, the TCPs decide when to block and forward data at their own
31
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

convenience. Sometimes users need to be sure that all the data they have submitted to the
TCP has been transmitted. For this purpose a push function is defined. To assure that
data submitted to a TCP is actually transmitted the sending user indicates that it should be
pushed through to the receiving user. A push causes the TCPs topromptly forward and
delivers data up to that point to the receiver. The exact push point might not be visible to
the receiving user and the push function does not supply a record boundary marker.

Reliability
The TCP must recover from data that is damaged, lost, duplicated, or delivered out of
order by the internet communication system. This is achieved by assigning a sequence
number to each octet transmitted, and requiring a positive acknowledgment (ACK) from
the receiving TCP. If the ACK is not received within a timeout interval, the data is
retransmitted. At the receiver, the sequence numbers are used to correctly order
segments that may be received out of order and to eliminate duplicates. Damage is
handled by adding a checksum to each segment transmitted, checking it at the receiver,
and discarding damaged segments.

As long as the TCPs continue to function properly and the internet system does not
become completely partitioned, no transmission errors will affect the correct delivery of
data. TCP recovers from internet communication system errors.

Flow Control
TCP provides a means for the receiver to govern the amount of data sent by the sender.
This is achieved by returning a "window" with every ACK indicating a range of
acceptable sequence numbers beyond the last segment successfully received. The
window indicates an allowed number of octets that the sender may transmit before
receiving further permission.

Multiplexing
To allow for many processes within a single Host to use TCP communication facilities
simultaneously, the TCP provides a set of addresses or ports within each host.

32
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Concatenated with the network and host addresses from the internet communication
layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is,
a socket may be simultaneously used in multiple connections.

The binding of ports to processes is handled independently by each Host. However, it


proves useful to attach frequently used processes (e.g., a "logger" or timesharing service)
to fixed sockets which are made known to the public. These services can then be
accessed through the known addresses. Establishing and learning the port addresses of
other processes may involve more dynamic mechanisms.

Connections
The reliability and flow control mechanisms described above require that TCPs
initialize and maintain certain status information for each data stream. The combination
of this information, including sockets, sequence numbers, and window sizes, is called a
connection.
Each connection is uniquely specified by a pair of sockets identifying its two sides.
When two processes wish to communicate, their TCP's must first establish a connection
(initialize the status information on each side). When their communication is complete,
the connection is terminated or closed to free the resources for other uses.

Since connections must be established between unreliable hosts andover the unreliable
internet communication system, a handshake mechanism with clock-based sequence
numbers is used to avoid erroneous initialization of connections.

Precedence and Security


The users of TCP may indicate the security and precedence of their communication.
Provision is made for default values to be used when these features are not needed.

33
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.3.2 RELIABLE COMMUNICATION

A stream of data sent on a TCP connection is delivered reliably and in order at the
destination.

3.3.2.1 CONNECTION ESTABLISHMENT AND CLEARING

To identify the separate data streams that a TCP may handle, the TCP provides a port
identifier. Since port identifiers are selected independently by each TCP they might not
be unique. To provide for unique addresses within each TCP, we concatenate an internet
address identifying the TCP with a port identifier to create a socket which will be unique
throughout all networks connected together.

3.3.2.2 DATA COMMUNICATION

The data that flows on a connection may be thought of as a stream of octets. The
sending user indicates in each SEND call whether the data in that call (and any preceding
calls) should be immediately pushed through to the receiving user by the setting of the
PUSH flag.
A sending TCP is allowed to collect data from the sending user and to send that data in
segments at its own convenience, until the push function is signaled, then it must send all
unsent data. When a receiving TCP sees the PUSH flag, it must not wait for more data
from the sending TCP before passing the data to the receiving process.
There is no necessary relationship between push functions and segment boundaries.
The data in any particular segment may be the result of a single SEND call, in whole or
part, or of multiple SEND calls.
The purpose of push function and the PUSH flag is to push data through from the
sending user to the receiving user. It does not provide a record service.

34
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.3.2.3 ROBUSTNESS PRINCIPLE

TCP implementations will follow a general principle of robustness be conservative in


what you do, be liberal in what you accept from others.

3.3.3 HEADER FORMAT

TCP segments are sent as internet datagram. The Internet Protocol header carries
several information fields, including the source and destination host addresses. A TCP
header follows the internet header, supplying information specific to the TCP protocol.
This division allows for the existence of host level protocols other than TCP.

Figure 3. 8 TCP Header Format

35
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Source Port: 16 bits


The source port number.

Destination Port: 16 bits


The destination port number.

Sequence Number: 32 bits


The sequence number of the first data octet in this segment (except when SYN is
present). If SYN is present the sequence number is the initial sequence number (ISN) and
the first data octet is ISN+1.

Acknowledgment Number: 32 bits


If the ACK control bit is set this field contains the value of the next sequence number
the sender of the segment is expecting to receive. Once a connection is established this is
always sent.

Data Offset: 4 bits


The number of 32 bit words in the TCP Header. This indicates where the data begins.
The TCP header (even one including options) is an integral number of 32 bits long.

Reserved: 6 bits
Reserved for future use. Must be zero.
Control Bits: 6 bits (from left to right):
URG: Urgent Pointer field significant
ACK: Acknowledgment field significant
PSH: Push Function
RST: Reset the connection
SYN: Synchronize sequence numbers
FIN: No more data from sender

36
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Window: 16 bits
The number of data octets beginning with the one indicated in the acknowledgment
field which the sender of this segment is willing to accept.

Checksum: 16 bits
The checksum field is the 16 bit one's complement of the one's complement sum of all
16 bit words in the header and text. If a segment contains an odd number of header and
text octets to be checksummed, the last octet is padded on the right with zeros to form a
16 bit word for checksum purposes. The pad is not transmitted as part of the segment.
While computing the checksum, the checksum field itself is replaced with zeros.
The checksum also covers a 96 bit pseudo header conceptually

Urgent Pointer: 16 bits


This field communicates the current value of the urgent pointer as a positive offset
from the sequence number in this segment. The urgent pointer points to the sequence
number of the octet following the urgent data. This field is only be interpreted in
segments with the URG control bit set.

3.4 SOCKET PROGRAMMING

C# simplifies the network programming through its namespaces


like System.Net and System.Net.Sockets . A Socket is an End-Point of To and From
(Bidirectional) communication link between two programs (Server Program and Client
Program) running on the same network. We need two programs for communicating a
socket application in C#. A Server Socket Program (Server) and a Client Socket Program
(Client) .

C# Server Socket Program: A C# Server Socket Program running on a computer has a


socket that bound to a Port Number on the same computer and listening to the client's
incoming requests.
37
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.4.1 C# SERVER SOCKET PROGRAM

A C# Client Socket Program have to know the IP Address (Hostname) of the computer
that the C# Server Socket Program resides and the Port Number assign for listening for
client's request.

Once the connection is established between Server and Client, they can communicate
(read or write ) through their own sockets.

Figure 3. 9 Socket programming

The Server Socket Program act as a Server and listening to clients request . Here we
assign a Port No. 9050 for the Server Socket, These are the commands which will create
a port and server will be now in listening state;

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);


newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
newsock.Bind(ipep);
newsock.Listen(9050);

The next step is to create an infinite loop for monitoring the request from Client's side .
When the Server Socket accept a request from the Client side, it reads the data from
Network Stream and also it write the response to Network Stream .

38
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.4.2 C# CLIENT SOCKET PROGRAM

The C# Client Socket Program is the second part of the C# Server Socket Program . The
C# Client Socket Program is a Windows based application . The Client is connected to
the Port 9050 of the C# Server Socket Program , and the IP Address (Computer Name) .

IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(ServrIP),


9050);
//IPEndPoint ipep = new
IPEndPoint(IPAddress.Parse("10.170.201.18"), 9050);
server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
server.Connect(ipep);

When the C# Client program starts, it will connect to the C# Server Socket Program and
start to reads data from Network Stream , and also write to the Network Stream . When
you start the client program you will get a message from Server "client started". When
press the button at the bottom of Client window, it will send a message to the Server and
also receive response from the Server.

3.5 HARDWARE
The hardware in the project is connected Serially with the Server Computer. So it is
important to tell about serial programming of microcontroller

3.5.1 SERIAL PROGRAMMING IN PIC

There are two ways for serial communication in PIC one is through Software UART
library and second is Hardware USART Library.both are discussed briefly. But the one
we hve used is USART.

39
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

3.5.1.1 SOFTWARE UART LIBRARY

Universal asynchronous receiver transmitter (UART) software library is used for


RS232-based serial communication between two electronic devices. In serial
communication, only two cables (plus a ground cable) are required to transfer data in
either direction. Data is sent in serial format over the cable bit by bit.

Normally, the receiving device is in idle mode with its transmit (TX) pin at logic 1,
also known as MARK. Data transmission starts when this pin goes to logic 0, also known
as SPACE. The first bit sent is the start bit at logic 0. Following this bit, 7 or 8 data bits
are sent, followed by an optional parity bit. The last bit sent is the stop bit at logic 1.
Serial data is usually sent as a 10-bit frame consisting of a start bit, 8 data bits, and a stop
bit, and no parity bits.

Figure 4.21 shows how character “A” can be sent using serial communication.
Character “A” has the ASCII bit pattern 01000001.

As shown in the figure, first the start bit is sent, this is followed by 8 data bits
01000001,and finally the stop bit is sent.

Figure 3. 10

40
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

The bit timing is very important in serial communication and the transmitting (TX)
and receiving (RX) devices must have the same bit timings. The bit timing is measured
byte baud rate, which specifies the number of bits transmitted or received each second.

Typical baud rates are 4800, 9600, 19200, 38400, and so on. For example, when
operating at 9600 baud rate with a frame size of 10 bits, 960 characters are transmitted or
received each second. The timing between bits is then about 104ms.[6]

3.5.1.2 HARDWARE USART LIBRARY

The universal synchronous asynchronous receiver transmitter (USART) hardware


library contains a number of functions to transmit and receive serial data using the
USART circuits built on the PIC microcontroller chips. Some PIC18F-series
microcontrollers have only one USART (e.g., PIC18F452), while others have two
USART circuits (e.g., PIC18F8520).

Hardware USART has an advantage over software-implemented USART, in that


higher baud rates are generally available and the microcontroller can perform other
operations while data is sent to the USART.

The hardware USART library provides the following functions:

 _ Usart_Init
 _ Usart_Data_Ready
 _ Usart_Read
 _ Usart_Write

Usart_Init

The Usart_Init function initializes the hardware USART with the specified baud rate.This
function should be called first, before any other USART functions. The onlyparameter

41
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

required by this function is the baud rate. The following example call sets thebaud rate to
9600:
Usart_Init(9600);

Usart_Data_Ready
The Usart_Data_Ready function can be called to check whether or not a data byte has
been received by the USART. The function returns a 1 if data has been received and a 0
if no data has been received. The function has no parameters. The following code checks
if a data byte has been received or not:
if(Usart_Data_Ready( ))

Usart_Read
The Usart_Read function is called to read a data byte from the USART. If data has not
been received, a 0 is returned. Note that reading data from the USART is non blocking
(i.e., function always returns whether or not the USART has received a data byte). The
Usart_Read function should be called after calling the function Usart_Data_Ready to
make sure that data is available at the USART. Usart_Read has no parameters.

In the following example, USART is checked and if a data byte has been received it is
copied to variable MyData:

char MyData;
if(Usart_Data_Read( )) MyData = Usart_Read();

Usart_Write
The Usart_Write function sends a data byte to the USART, and thus a serial data is sent
out of the USART. The data byte to be sent must be supplied as a parameter to the
function. In the following example, character “A” is sent to the USART:[6]
char Temp = ‘A’;
42
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Usart_Write(Temp);

3.5.2 HARDWARE DESCRIPTION

Figure 3.10 shows the schematics of the hardware

Figure 3. 11 Schematics of Hardware

Serial Port is connected with PIC16f877A through MAX232 to make the voltage levels
compatible. And to test the circuit in we used LEDs in schematics

Serial port is connected to Tx (26)and Rx(25) pin of controller via level converter the
controller will wait for the data from serial port of Server will send the data to controller
,which will be in a form of a string. After receiving it controller will use the code and
decode the received data to give an appropriate output to PORTD to turn on/off the
desired device. Then the controller will send back an acknowledge to the sever that the

43
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

desired device has been turned on/off by writing back on .All this will be done using
Hardware USART Library commands as stated above.

Figure 3.10 shows the working of hardware in Flow Chart

Figure 3. 12 Flow Chart Of Hadware’s Work

44
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

CHAPTER 4

CONCLUSION

We developed a system to automate home appliances. This system have many special
features controlling the electricity of the building is one of the feature which enables the
user to control the electronic appliances of his/her building from within the building
boundary or anywhere in the world using web based system.

4.1 USES AND SCOPE

This automation technique has a scope in the small industries who want to cut down their
payrolls. This is the basic concept of the SCADA system . This idea is a basic concept
behind SCADA system. SCADA stands for supervisory control and data acquisition, The
SCADA system is used in part to keep the systems as energy efficient as possible. One
way that it does this is by detecting problems in these industrial systems from a remote
location. For example, if a conveyer belt loses its electrical support, an alarm will go off
on the SCADA system in order to alert someone to fix this problem. This will lead to the
system being fixed as quickly as possible, and the amount of wasted energy from having
the whole factory backed up will be minimized.

The SCADA system has clearly become a vital component of industrial, electrical, and
utility systems. Experts who use these systems and analyze them every day have claimed
its importance in the industrial world. Without SCADA, many operations in these
systems would have to be done manually. This would slow down the overall efficiency of
the system and it would become less energy efficient because of this change. The
SCADA operating system clearly contributes to the energy efficiency of these systems.

45
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Some of the basic jobs this system can perform are following

4.1.1 SWITCH ON/OFF ELECTRONIC APPLIANCES


(DESKTOP/WEB BASED)

This system have many special features controlling the electricity of the building is one
of the feature which enables the user to control the electronic appliances of his/her
building from within the building boundary or anywhere in the world using web based
system.

4.1.2 TIMER TO AUTOMATICALLY SWITCHING


(ON/OFF) ELECTRONIC APPLIANCES

Timer feature automatically switch on or switch off the electricity of the building on the
set time. User can change its time and set it according to his need. User doesn‟t have to
go physically outside and open the lights, now simply set the required time and the
system will switch on and off the electric flow itself.

4.1.3 LOUD ALARM TO ALERT ABOUT DANGER

When any unwanted activity is detected by the system, it immediate activates a loud
alarm siren to alert the user and people around about the danger.

46
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

4.1.4 LIVE STREAMING VIDEOS OF HOUSE THROUGH


ONLINE SECURITY CAMERAS

Special feature of live streaming videos enable the user to view live online web cam
location to remote location from anywhere in the world. Now when unwanted activity is
detected at user‟s premises user can simply log onto the website and view live videos of
every area of the building.

4.1.5 CAPTURES PICTURES OF REMOTE LOCATION

User can capture pictures of remote location from anywhere in the world using his/her
cellular, laptop or PDA. Now whenever user is informed about the burglary, he/she may
go on the website view the remote web cameras and if he/she finds anyone in camera.
User can capture pictures for evidence.

4.1.6 CONTROL ELECTRONIC DOOR LOCKS

Now user can control his/her door locks using his cellular. If anyone arrives and gives
bell, User may check on the gate camera and if she/he knows the person. He/She can
open the door from the cell phone.

4.2 FUTURE ASPECTS


As the internet users are growing around the world the internet is becoming more and
more mobile. People can access internet not only through their desktop PC s and laptops
but also through their mobile, IPods and other portable devices. In this senior the
automation through internet is very tempting because of low cost, high mobility and time
effectiveness.
47
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

In our system the server is home pc it can be a laptop or desktop pc, but in near future
,due to the tcp/ip implementation in microcontroller as in PIC & AVR, the server can be
replaced by small micro controller.

For many years, embedded systems and Ethernet networks existed in separate worlds.
Ethernet was available only to desktop computers and other large computers. Embedded
systems that needed to exchange information with other computers were limited to
interfaces with low speed, limited range, or lack of standard application protocols. But
developments in technology and the marketplace now make it possible for embedded
systems to communicate in local Ethernet networks but developments in technology and
the marketplace now make it possible for embedded systems to communicate in local
Ethernet networks as well as on the Internet. Network communications can make an
embedded system more powerful and easier to monitor and control. An embedded system
can host a Web site, send and receive e-mail, upload and download files, and exchange
information of any kind with other computers connected via a network interface.
Internet protocols provide standard, well-documented ways of exchanging data. Both
Ethernet and the Internet protocols are free and open standards available for use without
royalties or licensing fees.

48
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

APPENDIX-A

A-1 SOURCE CODE OF SERVER APPLICATION


Form1.c

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;

namespace servr
{
public partial class Form1 : Form
{
private int recv;
private byte[] data;
private Socket newsock,client;
private IPEndPoint clientep;
private SerialPort sp1;
public Form1()
{
InitializeComponent();
sp1 = new SerialPort();
}
49
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

private void Form1_Load(object sender, EventArgs e)


{
sp1.PortName = "COM6";
sp1.BaudRate = 9600;
sp1.DataBits = 8;
sp1.Parity = Parity.None;
sp1.StopBits = StopBits.One;
sp1.Open();
}
public void con()
{
try
{
data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
newsock.Bind(ipep);
newsock.Listen(9050);
MessageBox.Show("Waiting for a client...");
client = newsock.Accept();
clientep = (IPEndPoint)client.RemoteEndPoint;
MessageBox.Show("Connected with " + clientep.Address + " , "
+clientep.Port);
string welcome = "connected...";
data = Encoding.ASCII.GetBytes(welcome);
client.Send(data, data.Length, SocketFlags.None);
}
catch (Exception ex)
{

50
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

MessageBox.Show(ex.ToString());
}
}
public void send()
{
string st = null;
con();
try
{
while(true)
{
data = new byte[1024];
recv = client.Receive(data);
st = Encoding.ASCII.GetString(data, 0, recv);
if (st == "0")
break;
if (st == "D1")
{
button1.Text = "D1 = ON";
sp1.Write("1");
break;
}
else if (st == "D2")
{
button3.Text = "D2 = ON";
sp1.Write("2");
break;
}
else if (st == "D3")
{
button5.Text = "D3 = ON";

51
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

sp1.Write("3");
break;
}
else if (st == "D4")
{
button2.Text = "D4 = ON";
sp1.Write("4");
break;
}
else if (st == "D5")
{
button4.Text = "D5 = ON";
sp1.Write("5");
break;
}
else if (st == "D6")
{
button6.Text = "D6 = ON";
sp1.Write("6");
break;
}
else if (st == "1")
{
button1.Text = "D1 = OFF";
sp1.Write("a");
break;
}
else if (st == "2")
{
button3.Text = "D2 = OFF";
sp1.Write("b");

52
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

break;
}
else if (st == "3")
{
button5.Text = "D3 = OFF";
sp1.Write("c");
break;
}
else if (st == "4")
{
button2.Text = "D4 = OFF";
sp1.Write("d");
break;
}
else if (st == "5")
{
button4.Text = "D5 = OFF";
sp1.Write("e");
break;
}
else if (st == "6")
{
button6.Text = "D6 = OFF";
sp1.Write("f");
break;
}
else if (st == "Connect")
{
MessageBox.Show("client found");
break;
}

53
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

client.Send(data, recv, SocketFlags.None);


}
if (st != "exit")
{
client.Close();
newsock.Close();
if (st != "0")
send();
}
else
{
MessageBox.Show("Disconnected from " + clientep.Address);
}
}
catch (Exception ex)
{
MessageBox.Show("Disconnected by client");
MessageBox.Show(ex.ToString());
}
}

private void button1_Click(object sender, EventArgs e)


{

private void button3_Click(object sender, EventArgs e)


{

54
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

private void button7_Click(object sender, EventArgs e)


{
if (button7.Text == "ON Server")
{
button7.Text = "OFF";
send();
}
else if (button7.Text == "OFF")
{
button7.Text = "ON Server";
this.Close();
}
}

}
}

A-2 SOURCE CODE OF CLIENT APPLICATION

2.3.1.2 Form1.c

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Text;

55
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

using System.Windows.Forms;

namespace Client
{
public partial class Form1 : Form
{
private byte[] data;
private string input,stringData;
private Socket server;
private String ServrIP;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
button12.Enabled = false;
button11.Enabled = false;
button10.Enabled = false;
button9.Enabled = false;
button8.Enabled = false;
button7.Enabled = false;
button14.Enabled = false;
textBox2.Text = "127.0.0.1";
ServrIP = textBox2.Text;
}
private void con()
{
ServrIP.Trim();
try

56
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

{
ServrIP = textBox2.Text;
data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(ServrIP), 9050);
//IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("10.170.201.18"), 9050);
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
server.Connect(ipep);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void connect(String st)
{
con();
try
{
int recv = server.Receive(data);
stringData = Encoding.ASCII.GetString(data, 0, recv);

while (true)
{
input = st;
if (input == "exit")
{
server.Send(Encoding.ASCII.GetBytes(input));
break;
}
server.Send(Encoding.ASCII.GetBytes(input));

57
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

data = new byte[1024];


recv = server.Receive(data);
stringData = Encoding.ASCII.GetString(data, 0, recv);
}
MessageBox.Show("Disconnecting from server...");
server.Shutdown(SocketShutdown.Both);
server.Close();
}
catch (SocketException ex)
{
String str = "Unable to connect to server. " + ex.ToString();
return;
}
}

private void button13_Click(object sender, EventArgs e)


{
button14.Enabled = true;
button13.Enabled = false;
String s = sender.ToString().Substring(35, 7);
connect(s);
}

private void button1_Click(object sender, EventArgs e)


{
if (devices_On(sender))
MessageBox.Show("Connect to the server first");
else
{
devices_On(sender);
button1.Enabled = false;

58
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

button12.Enabled = true;
}
}

private void button2_Click(object sender, EventArgs e)


{
if (devices_On(sender))
MessageBox.Show("Connect to the server first");
else
{
devices_On(sender);
button2.Enabled = false;
button11.Enabled = true;
}
}

private void button3_Click(object sender, EventArgs e)


{
if (devices_On(sender))
MessageBox.Show("Connect to the server first");
else
{
devices_On(sender);
button3.Enabled = false;
button10.Enabled = true;
}
}

private void button4_Click(object sender, EventArgs e)


{
if (devices_On(sender))

59
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

MessageBox.Show("Connect to the server first");


else
{
devices_On(sender);
button4.Enabled = false;
button9.Enabled = true;
}
}

private void button5_Click(object sender, EventArgs e)


{
if (devices_On(sender))
MessageBox.Show("Connect to the server first");
else
{
devices_On(sender);
button5.Enabled = false;
button8.Enabled = true;
}
}

private void button6_Click(object sender, EventArgs e)


{
if (devices_On(sender))
MessageBox.Show("Connect to the server first");
else
{
devices_On(sender);
button6.Enabled = false;
button7.Enabled = true;
}

60
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

}
// This function will be called when button disonnect will be clicked
private void button14_Click(object sender, EventArgs e)
{
button14.Enabled = false;
button13.Enabled = true;
connect("exit");
}

private void button12_Click(object sender, EventArgs e)


{
button12.Enabled = false;
button1.Enabled = true;
device_off(sender);
}
private void button11_Click(object sender, EventArgs e)
{
button11.Enabled = false;
button2.Enabled = true;
device_off(sender);
}
private void button10_Click(object sender, EventArgs e)
{
button10.Enabled = false;
button3.Enabled = true;
device_off(sender);
}

private void button9_Click(object sender, EventArgs e)


{
button9.Enabled = false;

61
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

button4.Enabled = true;
device_off(sender);
}

private void button8_Click(object sender, EventArgs e)


{
button8.Enabled = false;
button5.Enabled = true;
device_off(sender);
}

private void button7_Click(object sender, EventArgs e)


{
button7.Enabled = false;
button6.Enabled = true;
device_off(sender);
}
public bool devices_On(object sender)
{
if (button13.Enabled == true)
return true;
else
{
String s = sender.ToString().Substring(35, 2);
connect(s);
return false;
}
}
public void device_off(object sender)
{
String s = sender.ToString().Substring(36, 1);

62
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

connect(s);
}
}
}

A-3 CODE OF MICROCONTROLLER

#include <16F877A.h>
#fuses XT, NOLVP ,PUT
#use delay(clock = 4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte PORTD = 0x08
#byte PORTE = 0x09
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#byte TRISD = 0x88
#byte TRISE = 0x89

#bit pd_7=PORTD.7
#bit pd_1=PORTD.1
#bit pd_2=PORTD.2
#bit pd_3=PORTD.3
#bit pd_6=PORTD.6
#bit pd_4=PORTD.4
#bit pd_5=PORTD.5

void main()
{
63
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

unsigned char ch='0';

PORTD=255;
PORTB=255;
TRISD=0;
TRISB=0;
while(1){
delay_ms(1000);
ch=getc();
switch(ch)
{
case '1':
PORTD=PORTD & 0x7F;
// pd_7=0;
break;
case '2':
PORTD=PORTD & 0xBF;
// pd_6=0;
break;
case '3':
PORTD=PORTD & 0xDF;
break;
case '4':
PORTD=PORTD & 0xEF;
break;
case '5':
PORTD=PORTD & 0xF7;
break;
case '6':
PORTD=PORTD & 0xFB;
break;

64
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

case 'a':
PORTD=PORTD | 0x80;
// pd_7=1;
break;
case 'b':
PORTD=PORTD | 0x40;
break;
case 'c':
PORTD=PORTD | 0x20;
break;
case 'd':
PORTD=PORTD | 0x10;
break;
case 'e':
PORTD=PORTD | 0x08;
break;
case 'f':
PORTD=PORTD | 0x04;
break;
}
}}

65
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

APPENDIX-B
B-1MICRO-CONTROLLER.
In our project, the micro-controller which we are using is 16F877A. PIC16f877A
INTERNAL ARCHITECTURE

66
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

BLOCK DIAGRAM DESCRIPTION

DATA EEPROM AND FLASH PROGRAM MEMORY:

The data EEPROM and Flash program memory is readable and writable during normal
operation (over the full VDD range). This memory is not directly mapped in the register
file space. Instead, it is indirectly addressed through the Special Function Registers.
There are six SFR‟s used to read and write this memory:

 EECON1

 EECON2

 EEDATA

 EEDATH

 EEADR

 EEADRH

EECON1 is the control register for memory accesses.

EECON2 is not a physical register. Reading EECON2 will read all „0‟s. The EECON2
register is used exclusively in the EEPROM write sequence.

When interfacing to the data memory block, EEDATA holds the 8-bit data for read/write
and EEADR holds the address of the EEPROM location being accessed. These devices
have 128 or 256 bytes of data EEPROM (depending on the device), with an address range
from 00h to FFh. On devices with 128 bytes, addresses from 80h to FFh are
unimplemented and will wraparound to the beginning of data EEPROM memory. When
writing to unimplemented locations, the on-chip charge pump will be turned off.

When interfacing the program memory block, the EEDATA and EEDATH registers
form a two-byte word that holds the 14-bit data for read/write and the EEADR and
EEADRH registers form a two-byte word that holds the 13-bit address of the program
memory location being accessed. These devices have 4 or 8K words of program Flash,
with an address range from 0000h to 0FFFh for the PIC16F873A/874A and 0000h to
67
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

1FFFh for the PIC16F876A/877A. Addresses above the range of the respective device
will wraparound to the beginning of program memory.

Reading Flash Program Memory

To read a program memory location, the user must write two bytes of the address to the
EEADR and EEADRH registers, set the EEPGD control bit (EECON1<7>) and then set
control bit RD (EECON1<0>). Once the read control bit is set, the program memory
Flash controller will use the next two instruction cycles to read the data. This causes these
two instructions immediately following the “BSF EECON1,RD” instruction to be
ignored. The data is available in the very next cycle in the EEDATA and EEDATH
registers; therefore, it can be read as two bytes in the following instructions. EEDATA
and EEDATH registers will hold this value until another read or until it is written to by
the user (during a write operation).

Writing to Flash Program Memory

Flash program memory may only be written to if the destination address is in a segment
of memory that is not write-protected, as defined in bits WRT1:WRT0 of the device
configuration word (Register 14-1). Flash program memory must be written in four-word
blocks. A block consists of four words with sequential addresses, with a lower boundary
defined by an address, where EEADR<1:0> = 00. At the same time, all block writes to
program memory are done as erase and write operations. The write operation is edge-
aligned and cannot occur across boundaries. To write program data, it must first be
loaded into the buffer registers (see Figure 3-1). This is accomplished by first writing the
destination address to EEADR and EEADRH and then writing the data to EEDATA and
EEDATH. After the address and data have been set up, then the following sequence of
events must be executed:

68
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

To transfer data from the buffer registers to the program memory, the EEADR and
EEADRH must point to the last location in the four-word block (EEADR<1:0> = 11).
Then the following sequence of events must be executed:

1. Set the EEPGD control bit (EECON1<7>).

2. Write 55h, then AAh, to EECON2 (Flash programming sequence).

3. Set control bit WR (EECON1<1>) to begin the write operation.

The user must follow the same specific sequence to initiate the write for each word in the
program block, writing each program word in sequence (00,01,10,11). When the write is
performed on the last word (EEADR<1:0> = 11), the block of four words are
automatically erased and the contents of the buffer registers are written into the program
memory. After the “BSF EECON1,WR” instruction, the processor requires two cycles to
set up the erase/write operation. The user must place two NOP instructions after the WR
bit is set. Since data is being written to buffer registers, the writing of the first three
words of the block appears to occur immediately. The processor will halt internal
operations for the typical 4 ms, only during the cycle in which the erase takes place (i.e.,
the last word of the four-word block). This is not Sleep mode as the clocks and
peripherals will continue to run. After the write cycle, the processor will resume
operation with the third instruction after the EECON1 write instruction. If the sequence is
performed to any other location, the action is ignored.

I/O PORTS

Some pins for these I/O ports are multiplexed with an alternate function for the peripheral
features on the device. In general, when a peripheral is enabled, that pin may not be used
as a general purpose I/O pin.

69
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PORTA and the TRISA REGISTER

PORTA is a 6-bit wide, bidirectional port. The corresponding data direction register is
TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e.,
put the corresponding output driver in a High-Impedance mode). Clearing a TRISA bit (=
0) will make the corresponding PORTA pin an output (i.e., put the contents of the output
latch on the selected pin).

Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI
pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open-drain output. All other
PORTA pins have TTL input levels and full CMOS output drivers.

Other PORTA pins are multiplexed with analog inputs and the analog VREF input for
both the A/D converters and the comparators. The operation of each pin is selected by
clearing/setting the appropriate control bits in the ADCON1 and/or CMCON registers

The TRISA register controls the direction of the port pins even when they are being used
as analog inputs. The user must ensure the bits in the TRISA register are maintained set
when using them as analog inputs.

70
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PORTA FUNCTIONS

PORTB and the TRISB REGISTER

PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is
TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e.,
put the corresponding output driver in a High-Impedance mode). Clearing a TRISB bit (=
0) will make the corresponding PORTB pin an output (i.e., put the contents of the output
latch on the selected pin).

Three pins of PORTB are multiplexed with the In-Circuit Debugger and Low-Voltage
Programming function: RB3/PGM, RB6/PGC and RB7/PGD.

The interrupt-on-change feature is recommended for wake-up on key depression


operation and operations where PORTB is only used for the interrupt-on-change feature.

PORTB FUNCTIONS

71
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PORTC and the TRISC REGISTER

PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is
TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e.,
put the corresponding output driver in a High-Impedance mode). Clearing a TRISC bit (=
0) will make the corresponding PORTC pin an output (i.e., put the contents of the output
latch on the selected pin). PORTC is multiplexed with several peripheral functions.

72
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PORTC FUNCTIONS

PORTD and TRISD REGISTERS

PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually
configurable as an input or output.

PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by
setting control bit. In this mode, the input buffers are TTL.

PORTD FUNCTIONS

73
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PORTE and TRISE REGISTER

PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are
individually configurable as inputs or outputs. These pins have Schmitt Trigger input
buffers.

PORTE pins are multiplexed with analog inputs. When selected for analog input, these
pins will read as „0‟s.

TRISE controls the direction of the RE pins, even when they are being used as analog
inputs. The user must make sure to keep the pins configured as inputs when using them
as analog inputs.

PORTE FUNCTIONS

74
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

PIN CONFIGURATON OF PIC 16F877A

75
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

76
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Legend: I = input O = output I/O = input/output P = power

77
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

— = Not used TTL = TTL input ST = Schmitt Trigger input

Note:

1: This buffer is a Schmitt Trigger input when configured as the external interrupt.

2: This buffer is a Schmitt Trigger input when used in Serial Programming mode.

3: This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a
CMOS input otherwise

ELECTRICAL CHARACTERISTICS

Absolute Maximum Ratings

Ambient temperature under bias................................................................................-55 to


+125°C

Storage temperature................................................................................................ -65°C to


+150°C

Voltage on any pin with respect to VSS (except VDD, MCLR. and RA4)......... -0.3V to
(VDD + 0.3V)

Voltage on VDD with respect to VSS........................................................................ -0.3 to


+7.5V

Voltage on MCLR with respect to VSS (Note 2) ...........................................................0 to


+14V

Voltage on RA4 with respect to VSS ...............................................................................0


to +8.5V

Total power dissipation (Note 1)


...............................................................................................1.0W

78
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET

Maximum current out of VSS pin


.........................................................................................300 mA

Maximum current into VDD pin


..........................................................................................250 mA

Input clamp current, IIK (VI < 0 or VI > VDD).............................. .............................. +20
mA

Output clamp current, IOK (VO < 0 or VO > VDD) ................................................... +20
mA

Maximum output current sunk by any I/O


pin.....................................................................25 mA

Maximum output current sourced by any I/O pin


...............................................................25 mA

Maximum current sunk by PORTA, PORTB and PORTE (combined) (Note 3).........200
mA

Maximum current sourced by PORTA, PORTB and PORTE (combined) (Note 3)...200
mA

Maximum current sunk by PORTC and PORTD (combined) (Note 3).........................200


mA

Maximum current sourced by PORTC and PORTD (combined) (Note 3)....................200


mA

Note 1: Power dissipation is calculated as follows: Pdis = VDD x {IDD - Σ IOH} + Σ


{(VDD - VOH) x IOH} + Σ (VOl x IOL)

2: Voltage spikes below VSS at the MCLR pin, inducing currents greater than 80 mA,
may cause latch-up. Thus, a series resistor of 50-100Ω should be used when applying a
“low” level to the MCLR pin rather than pulling this pin directly to VSS.

3: PORTD and PORTE are not implemented on PIC16F873A/876A devices.


79
LM78XX/LM78XXA — 3-Terminal 1A Positive Voltage Regulator
April 2010

LM78XX/LM78XXA
3-Terminal 1A Positive Voltage Regulator
Features General Description
• Output Current up to 1A
The LM78XX series of three terminal positive regulators
• Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24 are available in the TO-220 package and with several
• Thermal Overload Protection fixed output voltages, making them useful in a wide
• Short Circuit Protection range of applications. Each type employs internal current
• Output Transistor Safe Operating Area Protection limiting, thermal shut down and safe operating area pro-
tection, making it essentially indestructible. If adequate
heat sinking is provided, they can deliver over 1A output
current. Although designed primarily as fixed voltage
regulators, these devices can be used with external com-
ponents to obtain adjustable voltages and currents.

Ordering Information
Product Number Output Voltage Tolerance Package Operating Temperature
LM7805CT ±4% TO-220 -40°C to +125°C
LM7806CT
LM7808CT
LM7809CT
LM7810CT
LM7812CT
LM7815CT
LM7818CT
LM7824CT
LM7805ACT ±2% 0°C to +125°C
LM7806ACT
LM7808ACT
LM7809ACT
LM7810ACT
LM7812ACT
LM7815ACT
LM7818ACT
LM7824ACT

© 2010 Fairchild Semiconductor Corporation www.fairchildsemi.com


LM78XX/LM78XXA Rev. 1.0 1
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Block Diagram

Input Series Pass Output


Element
1 3

Current SOA
Generator Protection

Starting Reference Error


Circuit Voltage Amplifier

Thermal
Protection

GND
2

Figure 1.

Pin Assignment

TO-220
GND

1. Input
1 2. GND
3. Output

Figure 2.

Absolute Maximum Ratings


Absolute maximum ratings are those values beyond which damage to the device may occur. The datasheet
specifications should be met, without exception, to ensure that the system design is reliable over its power supply,
temperature, and output/input loading variables. Fairchild does not recommend operation outside datasheet
specifications.

Symbol Parameter Value Unit


VI Input Voltage VO = 5V to 18V 35 V
VO = 24V 40 V
RθJC Thermal Resistance Junction-Cases (TO-220) 5 °C/W
RθJA Thermal Resistance Junction-Air (TO-220) 65 °C/W
TOPR Operating Temperature LM78xx -40 to +125 °C
Range
LM78xxA 0 to +125
TSTG Storage Temperature Range -65 to +150 °C

2 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7805)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 10V, CI = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 4.8 5.0 5.2 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 4.75 5.0 5.25
VI = 7V to 20V
Regline Line Regulation(1) TJ = +25°C VO = 7V to 25V – 4.0 100 mV
VI = 8V to 12V – 1.6 50.0
Regload Load Regulation(1) TJ = +25°C IO = 5mA to 1.5A – 9.0 100 mV
IO = 250mA to 750mA – 4.0 50.0
IQ Quiescent Current TJ = +25°C – 5.0 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – 0.03 0.5 mA
VI = 7V to 25V – 0.3 1.3
∆VO/∆T Output Voltage Drift(2) IO = 5mA – -0.8 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 42.0 – µV/VO
RR Ripple Rejection(2) f = 120Hz, VO = 8V to 18V 62.0 73.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(2) f = 1kHz – 15.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 230 – mA
(2)
IPK Peak Current TJ = +25°C – 2.2 – A

Notes:
1. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
2. These parameters, although guaranteed, are not 100% tested in production.

3 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7806) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 11V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min Typ. Max. Unit


VO Output Voltage TJ = +25°C 5.75 6.0 6.25 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 5.7 6.0 6.3
VI = 8.0V to 21V
Regline Line Regulation(3) TJ = +25°C VI = 8V to 25V – 5.0 120 mV
VI = 9V to 13V – 1.5 60.0
(3)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 9.0 120 mV
IO = 250mA to 750mA – 3.0 60.0
IQ Quiescent Current TJ = +25°C – 5.0 8.0 mA
∆IQ Quiescent Current IO = 5mA to 1A – – 0.5 mA
Change
VI = 8V to 25V – – 1.3
(4)
∆VO/∆T Output Voltage Drift IO = 5mA – -0.8 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 45.0 – µV/VO
RR Ripple Rejection(4) f = 120Hz, VO = 8V to 18V 62.0 73.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(4) f = 1kHz – 19.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 250 – mA
IPK Peak Current(4) TJ = +25°C – 2.2 – A
Notes:
3. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
4. These parameters, although guaranteed, are not 100% tested in production.

4 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7808) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 14V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 7.7 8.0 8.3 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 7.6 8.0 8.4
VI = 10.5V to 23V
Regline Line Regulation(5) TJ = +25°C VI = 10.5V to 25V – 5.0 160 mV
VI = 11.5V to 17V – 2.0 80.0
(5)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 10.0 160 mV
IO = 250mA to 750mA – 5.0 80.0
IQ Quiescent Current TJ = +25°C – 5.0 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – 0.05 0.5 mA
VI = 10.5V to 25V – 0.5 1.0
∆VO/∆T Output Voltage Drift(6) IO = 5mA – -0.8 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 52.0 – µV/VO
RR Ripple Rejection(6) f = 120Hz, VO = 11.5V to 21.5V 56.0 73.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(6) f = 1kHz – 17.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 230 – mA
IPK Peak Current(6) TJ = +25°C – 2.2 – A
Notes:
5. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
6. These parameters, although guaranteed, are not 100% tested in production.

5 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7809) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 15V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 8.65 9.0 9.35 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 8.6 9.0 9.4
VI = 11.5V to 24V
Regline Line Regulation(7) TJ = +25°C VI = 11.5V to 25V – 6.0 180 mV
VI = 12V to 17V – 2.0 90.0
(7)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 12.0 180 mV
IO = 250mA to 750mA – 4.0 90.0
IQ Quiescent Current TJ = +25°C – 5.0 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – – 0.5 mA
VI = 11.5V to 26V – – 1.3
∆VO/∆T Output Voltage Drift(8) IO = 5mA – -1.0 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 58.0 – µV/VO
RR Ripple Rejection(8) f = 120Hz, VO = 13V to 23V 56.0 71.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(8) f = 1kHz – 17.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 250 – mA
IPK Peak Current(8) TJ = +25°C – 2.2 – A
Notes:
7. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
8. These parameters, although guaranteed, are not 100% tested in production.

6 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7810) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 16V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 9.6 10.0 10.4 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 9.5 10.0 10.5
VI = 12.5V to 25V
Regline Line Regulation(9) TJ = +25°C VI = 12.5V to 25V – 10.0 200 mV
VI = 13V to 25V – 3.0 100
Regload Load Regulation(9) TJ = +25°C IO = 5mA to 1.5A – 12.0 200 mV
IO = 250mA to 750mA – 4.0 400
IQ Quiescent Current TJ = +25°C – 5.1 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – – 0.5 mA
VI = 12.5V to 29V – – 1.0
∆VO/∆T Output Voltage Drift(10) IO = 5mA – -1.0 – mV/°C

VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 58.0 – µV/VO


RR Ripple Rejection(10) f = 120Hz, VO = 13V to 23V 56.0 71.0 – dB

VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V


rO Output Resistance(10) f = 1kHz – 17.0 – mΩ

ISC Short Circuit Current VI = 35V, TA = +25°C – 250 – mA


IPK Peak Current(10) TJ = +25°C – 2.2 – A

Notes:
9. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
10. These parameters, although guaranteed, are not 100% tested in production.

7 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7812) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 19V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 11.5 12.0 12.5 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 11.4 12.0 12.6
VI = 14.5V to 27V
Regline Line Regulation(11) TJ = +25°C VI = 14.5V to 30V – 10.0 240 mV
VI = 16V to 22V – 3.0 120
(11)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 11.0 240 mV
IO = 250mA to 750mA – 5.0 120
IQ Quiescent Current TJ = +25°C – 5.1 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – 0.1 0.5 mA
VI = 14.5V to 30V – 0.5 1.0
∆VO/∆T Output Voltage Drift(12) IO = 5mA – -1.0 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 76.0 – µV/VO
RR Ripple Rejection(12) f = 120Hz, VI = 15V to 25V 55.0 71.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(12) f = 1kHz – 18.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 230 – mA
IPK Peak Current(12) TJ = +25°C – 2.2 – A
Notes:
11. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
12. These parameters, although guaranteed, are not 100% tested in production.

8 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7815) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 23V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 14.4 15.0 15.6 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 14.25 15.0 15.75
VI = 17.5V to 30V
Regline Line Regulation(13) TJ = +25°C VI = 17.5V to 30V – 11.0 300 mV
VI = 20V to 26V – 3.0 150
(13)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 12.0 300 mV
IO = 250mA to 750mA – 4.0 150
IQ Quiescent Current TJ = +25°C – 5.2 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – – 0.5 mA
VI = 17.5V to 30V – – 1.0
∆VO/∆T Output Voltage Drift(14) IO = 5mA – -1.0 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 90.0 – µV/VO
RR Ripple Rejection(14) f = 120Hz, VI = 18.5V to 28.5V 54.0 70.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(14) f = 1kHz – 19.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 250 – mA
IPK Peak Current(14) TJ = +25°C – 2.2 – A
Notes:
13. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
14. These parameters, although guaranteed, are not 100% tested in production.

9 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
LM78XX/LM78XXA 3-Terminal 1A Positive Voltage Regulator
Electrical Characteristics (LM7818) (Continued)
Refer to the test circuits. -40°C < TJ < 125°C, IO = 500mA, VI = 27V, CI = 0.33µF, CO = 0.1µF, unless otherwise specified.

Symbol Parameter Conditions Min. Typ. Max. Unit


VO Output Voltage TJ = +25°C 17.3 18.0 18.7 V
5mA ≤ IO ≤ 1A, PO ≤ 15W, 17.1 18.0 18.9
VI = 21V to 33V
Regline Line Regulation(15) TJ = +25°C VI = 21V to 33V – 15.0 360 mV
VI = 24V to 30V – 5.0 180
(15)
Regload Load Regulation TJ = +25°C IO = 5mA to 1.5A – 15.0 360 mV
IO = 250mA to 750mA – 5.0 180
IQ Quiescent Current TJ = +25°C – 5.2 8.0 mA
∆IQ Quiescent Current Change IO = 5mA to 1A – – 0.5 mA
VI = 21V to 33V – – 1.0
∆VO/∆T Output Voltage Drift(16) IO = 5mA – -1.0 – mV/°C
VN Output Noise Voltage f = 10Hz to 100kHz, TA = +25°C – 110 – µV/VO
RR Ripple Rejection(16) f = 120Hz, VI = 22V to 32V 53.0 69.0 – dB
VDROP Dropout Voltage IO = 1A, TJ = +25°C – 2.0 – V
rO Output Resistance(16) f = 1kHz – 22.0 – mΩ
ISC Short Circuit Current VI = 35V, TA = +25°C – 250 – mA
IPK Peak Current(16) TJ = +25°C – 2.2 – A
Notes:
15. Load and line regulation are specified at constant junction temperature. Changes in VO due to heating effects must
be taken into account separately. Pulse testing with low duty is used.
16. These parameters, although guaranteed, are not 100% tested in production.

10 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

D Meet or Exceed TIA/EIA-232-F and ITU MAX232 . . . D, DW, N, OR NS PACKAGE


Recommendation V.28 MAX232I . . . D, DW, OR N PACKAGE
(TOP VIEW)
D Operate With Single 5-V Power Supply
D Operate Up to 120 kbit/s C1+ 1 16 VCC
D Two Drivers and Two Receivers VS+ 2 15 GND

D ±30-V Input Levels


C1–
C2+
3
4
14
13
T1OUT
R1IN
D Low Supply Current . . . 8 mA Typical C2– 5 12 R1OUT
D Designed to be Interchangeable With VS– 6 11 T1IN
Maxim MAX232 T2OUT 7 10 T2IN
D ESD Protection Exceeds JESD 22 R2IN 8 9 R2OUT
– 2000-V Human-Body Model (A114-A)
D Applications
TIA/EIA-232-F
Battery-Powered Systems
Terminals
Modems
Computers

description/ordering information
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator to supply EIA-232 voltage
levels from a single 5-V supply. Each receiver converts EIA-232 inputs to 5-V TTL/CMOS levels. These
receivers have a typical threshold of 1.3 V and a typical hysteresis of 0.5 V, and can accept ±30-V inputs. Each
driver converts TTL/CMOS input levels into EIA-232 levels. The driver, receiver, and voltage-generator
functions are available as cells in the Texas Instruments LinASIC library.

ORDERING INFORMATION
ORDERABLE TOP-SIDE
TA PACKAGE†
PART NUMBER MARKING
PDIP (N) Tube MAX232N MAX232N
Tube MAX232D
SOIC (D) MAX232
Tape and reel MAX232DR
0°C to 70°C
Tube MAX232DW
SOIC (DW) MAX232
Tape and reel MAX232DWR
SOP (NS) Tape and reel MAX232NSR MAX232
PDIP (N) Tube MAX232IN MAX232IN
Tube MAX232ID
SOIC (D) MAX232I
–40°C to 85°C Tape and reel MAX232IDR
Tube MAX232IDW
SOIC (DW) MAX232I
Tape and reel MAX232IDWR
† Package drawings, standard packing quantities, thermal data, symbolization, and PCB design
guidelines are available at www.ti.com/sc/package.

Please be aware that an important notice concerning availability, standard warranty, and use in critical applications of
Texas Instruments semiconductor products and disclaimers thereto appears at the end of this data sheet.

LinASIC is a trademark of Texas Instruments.


PRODUCTION DATA information is current as of publication date. Copyright  2002, Texas Instruments Incorporated
Products conform to specifications per the terms of Texas Instruments
standard warranty. Production processing does not necessarily include
testing of all parameters.

POST OFFICE BOX 655303 • DALLAS, TEXAS 75265 1


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

Function Tables

EACH DRIVER
INPUT OUTPUT
TIN TOUT
L H
H L
H = high level, L = low
level

EACH RECEIVER
INPUT OUTPUT
RIN ROUT
L H
H L
H = high level, L = low
level

logic diagram (positive logic)


11 14
T1IN T1OUT

10 7
T2IN T2OUT

12 13
R1OUT R1IN

9 8
R2OUT R2IN

2 POST OFFICE BOX 655303 • DALLAS, TEXAS 75265


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

absolute maximum ratings over operating free-air temperature range (unless otherwise noted)†
Input supply voltage range, VCC (see Note 1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . –0.3 V to 6 V
Positive output supply voltage range, VS+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VCC – 0.3 V to 15 V
Negative output supply voltage range, VS– . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . –0.3 V to –15 V
Input voltage range, VI: Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . –0.3 V to VCC + 0.3 V
Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ±30 V
Output voltage range, VO: T1OUT, T2OUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VS– – 0.3 V to VS+ + 0.3 V
R1OUT, R2OUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . –0.3 V to VCC + 0.3 V
Short-circuit duration: T1OUT, T2OUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unlimited
Package thermal impedance, θJA (see Note 2): D package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73°C/W
DW package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57°C/W
N package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67°C/W
NS package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64°C/W
Lead temperature 1,6 mm (1/16 inch) from case for 10 seconds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260°C
Storage temperature range, Tstg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . –65°C to 150°C
† Stresses beyond those listed under “absolute maximum ratings” may cause permanent damage to the device. These are stress ratings only, and
functional operation of the device at these or any other conditions beyond those indicated under “recommended operating conditions” is not
implied. Exposure to absolute-maximum-rated conditions for extended periods may affect device reliability.
NOTE 1: All voltage values are with respect to network ground terminal.
2. The package thermal impedance is calculated in accordance with JESD 51-7.

recommended operating conditions


MIN NOM MAX UNIT
VCC Supply voltage 4.5 5 5.5 V
VIH High-level input voltage (T1IN,T2IN) 2 V
VIL Low-level input voltage (T1IN, T2IN) 0.8 V
R1IN, R2IN Receiver input voltage ±30 V
MAX232 0 70
TA Operating free
free-air
air temperature °C
MAX232I –40 85

electrical characteristics over recommended ranges of supply voltage and operating free-air
temperature (unless otherwise noted) (see Note 3 and Figure 4)
PARAMETER TEST CONDITIONS MIN TYP‡ MAX UNIT
VCC = 5.5 V, All outputs open,
ICC Supply current 8 10 mA
TA = 25°C
‡ All typical values are at VCC = 5 V and TA = 25°C.
NOTE 3: Test conditions are C1–C4 = 1 µF at VCC = 5 V ± 0.5 V.

POST OFFICE BOX 655303 • DALLAS, TEXAS 75265 3


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

DRIVER SECTION

electrical characteristics over recommended ranges of supply voltage and operating free-air
temperature range (see Note 3)
PARAMETER TEST CONDITIONS MIN TYP† MAX UNIT
VOH High-level output voltage T1OUT, T2OUT RL = 3 kΩ to GND 5 7 V
VOL Low-level output voltage‡ T1OUT, T2OUT RL = 3 kΩ to GND –7 –5 V
ro Output resistance T1OUT, T2OUT VS+ = VS– = 0, VO = ±2 V 300 Ω
IOS§ Short-circuit output current T1OUT, T2OUT VCC = 5.5 V, VO = 0 ±10 mA
IIS Short-circuit input current T1IN, T2IN VI = 0 200 µA
† All typical values are at VCC = 5 V, TA = 25°C.
‡ The algebraic convention, in which the least positive (most negative) value is designated minimum, is used in this data sheet for logic voltage
levels only.
§ Not more than one output should be shorted at a time.
NOTE 3: Test conditions are C1–C4 = 1 µF at VCC = 5 V ± 0.5 V.

switching characteristics, VCC = 5 V, TA = 25°C (see Note 3)


PARAMETER TEST CONDITIONS MIN TYP MAX UNIT
RL = 3 kΩ to 7 kΩ,
SR Driver slew rate 30 V/µs
See Figure 2
SR(t) Driver transition region slew rate See Figure 3 3 V/µs
Data rate One TOUT switching 120 kbit/s
NOTE 3: Test conditions are C1–C4 = 1 µF at VCC = 5 V ± 0.5 V.

RECEIVER SECTION

electrical characteristics over recommended ranges of supply voltage and operating free-air
temperature range (see Note 3)
PARAMETER TEST CONDITIONS MIN TYP† MAX UNIT
VOH High-level output voltage R1OUT, R2OUT IOH = –1 mA 3.5 V
VOL Low-level output voltage‡ R1OUT, R2OUT IOL = 3.2 mA 0.4 V
Receiver positive-going input
VIT+ R1IN, R2IN VCC = 5 V, TA = 25°C 1.7 2.4 V
threshold voltage
Receiver negative-going input
VIT– R1IN, R2IN VCC = 5 V, TA = 25°C 0.8 1.2 V
threshold voltage
Vhys Input hysteresis voltage R1IN, R2IN VCC = 5 V 0.2 0.5 1 V
ri Receiver input resistance R1IN, R2IN VCC = 5, TA = 25°C 3 5 7 kΩ
† All typical values are at VCC = 5 V, TA = 25°C.
‡ The algebraic convention, in which the least positive (most negative) value is designated minimum, is used in this data sheet for logic voltage
levels only.
NOTE 3: Test conditions are C1–C4 = 1 µF at VCC = 5 V ± 0.5 V.

switching characteristics, VCC = 5 V, TA = 25°C (see Note 3 and Figure 1)


PARAMETER TYP UNIT
tPLH(R) Receiver propagation delay time, low- to high-level output 500 ns
tPHL(R) Receiver propagation delay time, high- to low-level output 500 ns
NOTE 3: Test conditions are C1–C4 = 1 µF at VCC = 5 V ± 0.5 V.

4 POST OFFICE BOX 655303 • DALLAS, TEXAS 75265


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

PARAMETER MEASUREMENT INFORMATION


VCC

R1OUT RL = 1.3 kΩ
R1IN
or
or
Pulse R2OUT See Note C
R2IN
Generator
(see Note A)

CL = 50 pF
(see Note B)

TEST CIRCUIT

≤10 ns ≤10 ns

3V
90% 90%
Input 50% 50%
10% 10%
0V
500 ns
tPLH
tPHL
VOH
Output 1.5 V 1.5 V
VOL
WAVEFORMS
NOTES: A. The pulse generator has the following characteristics: ZO = 50 Ω, duty cycle ≤ 50%.
B. CL includes probe and jig capacitance.
C. All diodes are 1N3064 or equivalent.

Figure 1. Receiver Test Circuit and Waveforms for tPHL and tPLH Measurements

POST OFFICE BOX 655303 • DALLAS, TEXAS 75265 5


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

PARAMETER MEASUREMENT INFORMATION


T1IN or T2IN T1OUT or T2OUT
Pulse
Generator EIA-232 Output
(see Note A)
CL = 10 pF
RL
(see Note B)

TEST CIRCUIT
≤10 ns ≤10 ns
3V
90% 90%
Input 50% 50%
10% 10%
0V
5 µs
tPLH
tPHL

90% VOH
90%
Output
10% 10%
VOL
tTHL tTLH

+
0.8 (V – V ) 0.8 (V – V )
OH OL OL OH
SR or
t t
TLH THL
WAVEFORMS

NOTES: A. The pulse generator has the following characteristics: ZO = 50 Ω, duty cycle ≤ 50%.
B. CL includes probe and jig capacitance.

Figure 2. Driver Test Circuit and Waveforms for tPHL and tPLH Measurements (5-µs Input)

Pulse
Generator EIA-232 Output
(see Note A)
3 kΩ CL = 2.5 nF

TEST CIRCUIT

≤10 ns ≤10 ns
Input
90% 90%
10% 1.5 V 1.5 V 10%
20 µs
tTLH
tTHL

VOH
3V 3V
Output
–3 V –3 V
VOL

SR +t 6 V
or t
THL TLH

WAVEFORMS
NOTE A: The pulse generator has the following characteristics: ZO = 50 Ω, duty cycle ≤ 50%.

Figure 3. Test Circuit and Waveforms for tTHL and tTLH Measurements (20-µs Input)

6 POST OFFICE BOX 655303 • DALLAS, TEXAS 75265


MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002

APPLICATION INFORMATION
5V
+
CBYPASS = 1 µF

16
C3† 1 µF
VCC
1 2
C1+ 8.5 V
C1 1 µF 3 VS+
C1–
4 6
VS– –8.5 V
C2+
C2 1 µF 5 C4 1 µF
C2– +

11 14
EIA-232 Output
From CMOS or TTL
10 7
EIA-232 Output
12 13
EIA-232 Input
To CMOS or TTL
9 8
EIA-232 Input
0V

15
GND
† C3 can be connected to VCC or GND.

Figure 4. Typical Operating Circuit

POST OFFICE BOX 655303 • DALLAS, TEXAS 75265 7


REFERENCES
[1] http://en.wikipedia.org/wiki/Microsoft_Visual_Studio

[2] http://www.thedebugstore.com/acatalog/User-Manual-PCB-M-H-W-WH.pdf

[3] http://www.scribd.com/doc/36554721/Micro-Controller-Based-Controlling-and-Updating-
the-Data-of-Alpha-Numeric-LCD-Display-Screen-Using

[4] http://www.kpsec.freeuk.com/components/relay.htm

[5] http://medlibrary.org/medwiki/Transistor
[6] http://www.faqs.org/rfcs/rfc793.html
[7] http://www.ietf.org/rfc/rfc793.txt
[8] Dogon Ibrahim, Advanced PIC Microcontroller Projects in C: From USB to RTOS with the
PIC 18F Series. Newnes, July 8 2008
[9] http://www.templategets.com/microsoft-visual-studio-2008-professional.html

97

You might also like