Remote Home Automation Through Internet
Remote Home Automation Through Internet
Submitted by:
Anum Javed 2007-Elect-185
Noshaba Nasir 2007-Elect-188
-------------------------- ----------------------------
Internal Examiner External Examiner
------------------------------
Director
Undergraduate Studies
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
viii
ABBREVATIONS
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.
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.
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.
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
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:
3
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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.
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.
c. Designer
6
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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]
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
Power Supply
Serial Cable
LM7805
MAX232S
Switches
Micro-controller(PIC)
Oscillator 4 MHz.
LEDs
Capacitor
Resistors
9
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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
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.
Pin 2. Ground
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.
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
Figure 2.6 and Table 2.1 shows pin configuration of serial port
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.
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]
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
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.
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.
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
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
19
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.
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
21
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
CHAPTER 3
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
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
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.
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.
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
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
26
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
The client application code is illustrated in the following flowchart Figure 2.5
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
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.
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
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.1 SCOPE
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
30
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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:
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.
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.
33
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
A stream of data sent on a TCP connection is delivered reliably and in order at the
destination.
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.
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
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.
35
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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
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.
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;
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
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) .
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
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
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]
_ 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);
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.
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.
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
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.
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.
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
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.
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.
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.
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
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
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
54
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
}
}
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();
}
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
58
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
button12.Enabled = true;
}
}
59
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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");
}
61
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
button4.Enabled = true;
device_off(sender);
}
62
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
connect(s);
}
}
}
#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
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
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
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.
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).
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:
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 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 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.
PORTB FUNCTIONS
71
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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 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 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
75
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
76
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
77
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
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
Voltage on any pin with respect to VSS (except VDD, MCLR. and RA4)......... -0.3V to
(VDD + 0.3V)
78
REMOTE CONTROL HOME AUTOMATION THROUH INTERNET
Input clamp current, IIK (VI < 0 or VI > VDD).............................. .............................. +20
mA
Output clamp current, IOK (VO < 0 or VO > VDD) ................................................... +20
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
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.
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
Current SOA
Generator Protection
Thermal
Protection
GND
2
Figure 1.
Pin Assignment
TO-220
GND
1. Input
1 2. GND
3. Output
Figure 2.
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.
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.
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.
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.
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.
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.
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.
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.
10 www.fairchildsemi.com
LM78XX/LM78XXA Rev. 1.0
MAX232, MAX232I
DUAL EIA-232 DRIVERS/RECEIVERS
SLLS047I – FEBRUARY 1989 – REVISED OCTOBER 2002
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.
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
10 7
T2IN T2OUT
12 13
R1OUT R1IN
9 8
R2OUT R2IN
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.
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.
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.
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.
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
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)
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.
[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