Está en la página 1de 87

TRIBHUVAN UNIVERSITY

INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS
DEPARTMENT OF ELECTRONICS AND COMPUTER
ENGINEERING

A
FINAL YEAR PROJECT REPORT
ON
“INTERNET BASED HOME MONITORING AND CONTROL USING
EMBEDDED WEB SERVER”

By:
Arun Paudyal (066bex404)
Bandana Sharma (066bex407)
Kashiram Acharya (066bex416)
Sapin Bajracharya (066bex439)

Lalitpur, Nepal
August, 2013
TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS

A
FINAL YEAR PROJECT REPORT
ON
“INTERNET BASED HOME MONITORING AND CONTROL USING
EMBEDDED WEB SERVER”

By:
Arun Paudyal (066bex404)
Bandana Sharma (066bex407)
Kashiram Acharya (066bex416)
Sapin Bajracharya (066bex439)

A PROJECT WAS SUBMITTED TO THE DEPARTMENT OF


ELECTRONICS AND COMPUTER ENGINEERING IN PARTIAL
FULLFILLMENT OF REQUIREMENT FOR THE BACHELOR’S
DEGREE IN ELECTRONICS AND COMMUNICATION ENGINEERING

DEPARTMENT OF ELECTRONICS AND COMPUTER


ENGINEERING
LALITPUR, NEPAL
August, 2013
DEPARTMENT ACCEPTANCE

The project entitled “Internet Based Home Monitoring and Control Using Embedded Web
Server” submitted by Arun Paudyal (066bex404), Bandana Sharma (066bex407), Kashiram
Acharya (066bex416), Sapin Bajracharya (066bex439) in partial fulfilment of the
requirements for the Bachelor’s degree in Electronics & Communication Engineering, has
been accepted as a bona fide record of the work carried out in our department.

Arun Kumar Timalsina, PhD.

Head of Department

Department of Electronics and Computer

Engineering

Pulchowk Campus, IOE

i
PAGE OF APPROVAL

The undersigned certify that they have read, and recommended to the Institute of Engineering
for acceptance, project entitled “Internet Based Home Monitoring and Control Using
Embedded Web Server” submitted by Arun Paudyal (066bex404), Bandana Sharma
(066bex407), Kashiram Acharya (066bex416), Sapin Bajracharya (066bex439) in partial
fulfilment of the requirements for the Bachelor’s degree in Electronics & Communication
Engineering.

________________________________ ________________________________
Internal Examiner,
Supervisor,
Mr. Jitendra Kumar Manandhar, Mr. Uttam Mali,

Lecturer Associate Professor


Department of Electronics and Computer Department of Electronics and Computer
Engineering Engineering
Pulchowk Campus, IOE
Pulchowk Campus, IOE

________________________________
________________________________
Project Coorinator ,
External Examiner,
Aman Shakya, PhD.
Mr. Om Bikram Thapa,
Deputy Head of Department
Vianet Communications Pvt. Ltd.
Department of Electronics and Computer
Lalitpur
Engineering
Pulchowk Campus, IOE.

DATE OF APPROVAL:
ii
COPYRIGHT
The authors have agreed that the Library, Department of Electronics and Computer
Engineering, Pulchowk Campus, Institute of Engineering may make this report freely
available for inspection. Moreover, the author has agreed that permission for extensive
copying of this project report for scholarly purpose may be granted by the supervisors who
supervised the project work recorded herein or, in their absence, by the Head of the
Department wherein the project report was done. It is understood that the recognition will be
given to the author of this report and to the Department of Electronics and Computer
Engineering, Pulchowk Campus, Institute of Engineering in any use of the material of this
project report. Copying or publication or the other use of this report for financial gain without
approval of to the Department of Electronics and Computer Engineering, Pulchowk Campus,
Institute of Engineering and author’s written permission is prohibited. Request for permission
to copy or to make any other use of the material in this report in whole or in part should be
addressed to:

Arun Kumar Timalsina, PhD.

Head of Department

Department of Electronics and Computer Engineering

Pulchowk Campus, IOE

Lalitpur, Nepal

iii
ACKNOWLEDGEMENT
We are highly indebted to the Department of Electronics and Computer Engineering for
providing us an opportunity to employ our theoretical knowledge into practice in the form of
our final year project. This project has been a matter of great enthusiasm for us students
because we learned to use the various knowledge that we have learnt past few years at
Pulchowk Campus.

We are highly thankful to our project supervisor, Mr. Jitendra Kumar Manandhar for his
constant encouragement. We are equally indebted to our seniors Mr. Bibek Joshi, Mr.
Sandeep Manandhar and Mr. Vishal Gewali for clearing our doubts in various stages during
projects and providing the technical assistance. We would also like to thank our class mates
for supporting us. Similarly, we are equally thankful to Robotics Club and our juniors for
providing the various machineries and tools and sound working atmosphere.

Last but not the least we would like to thank all those who are involved in guiding us through
this project.

Arun Paudyal (066bex404) August 29th, 2013

Bandana Sharma (066bex407) Pulchowk, Lalitpur

Kashiram Acharya (066bex416)

Sapin Bajracharya (066bex439)

iv
ABSTRACT
The objective of this project was to design and build an embedded HTTP server using an AVR
microcontroller chip. The web server required the implementation of the interface with
Ethernet as well the internet like TCP/IP. This embedded web server is able to serve small,
static web page. The HTML code for the web page is kept in the program for the AVR
microcontroller. So, implementing the web server we were able to control the appliance
connected to the web server remotely via internet and check the status of the controlled
appliance.
The task of the monitoring and controlling the home appliances was obtained by writing the
TCP/IP stack for the web server. The ENC28J60 module provided the Ethernet interface
between the web server and the internet. The control information from the user via a web page
was passed up to the appliances/devices through the RF communication between the master
and slave controllers. The overall hardware design was made modular making the interface for
the web server, RF modules and the relay interfacing for the devices.
Since the capabilities of the embedded web server are nowhere near that of a regular server
computer, its small size and relatively low cost makes it more practical for some applications.
The web server was built, tested to work, and the web servers were successful in receiving
control information from the user and in turn control the desired devices. The status of the
controlled devices can be seen via the web page as well.

v
MOTIVATION
The term “Internet of Things” (hereafter referred as IoT) is the real motivation for us in
carrying out this project. The term IoT was first proposed by British technical pioneer at MIT.
IoT refers to the uniquely identifiable objects and their virtual representation in the internet
like structure.

So, we were keen in developing something as our major project that could represent or address
the discrete components in our day to day life by connecting them with the internet. The
concept of IoT has become so broad that it has been implemented in various ways.
Preliminarily, this concept was just limited in using the RFID tags for facilitating routing,
inventorying, and loss prevention. Along time, IoT has been used more extensively for
surveillance, security, healthcare, transport, food safety, document management etc. In present
day, IoT has been implemented in many applications like locating people and everyday
objects, tele-operation and tele-presence (ability to monitor and control the distant objects).

After going through these varied implementations of IoT, we were really clicked in doing
something that implements the IoT. But we were still confused till then how to implement the
IoT. While going through the various sites during our research phase, we came across a
hardware implementation known as the Embedded Web Server. This hardware used the
internet protocols like TCP/IP or UDP or ARP and can communicate with the real world
applications through the internet via a static (simple) web page. After learning about the IoT
and Embedded Web Server, we were really motivated in carrying out project implementing
the IoT and the web server. So, we decided that we will control various home appliances using
our web server. Further, we also made the provision of monitoring the status of the controlled
home appliances.

Besides, there is another large community funded professional project in USA carried out by
Physical Graph Corporation known as “Smart Things” that motivated us as well. In Smart
Things, the devices to be controlled are made smart by making the provision of internet
connectivity and other relevant necessities. So, the day to day objects like power sockets,
vi
doors, etc turned smart and they can be directly controlled via internet remotely through web
page or android or iOS application. The Smart Things project has been praised by many
corporate houses like CNN, Forbes, Readers’ Digest, Discovery Channel, Engadget, etc.

So, we learned a lot about the Internet of Things, Smart Things and Embedded Web Server
during the initial research phase. Therefore, while selecting the project, we were really
fascinated in carrying out controlling something remotely via the internet. We were really
excited by the Internet of Things, the professional project Smart Things, and the hardware
implementation Embedded Web Server. So these really motivated us in carrying out this
project. And also this kind of project has never been done previously in Nepal, and this
additionally motivated us in carrying out this project at any cost.

vii
Table of Contents
DEPARTMENT ACCEPTANCE ............................................................................................... i

PAGE OF APPROVAL.............................................................................................................. ii

COPYRIGHT............................................................................................................................. iii

ACKNOWLEDGEMENT ......................................................................................................... iv

ABSTRACT................................................................................................................................ v

MOTIVATION.......................................................................................................................... vi

LIST OF TABLES.................................................................................................................... xii

LIST OF FIGURES .................................................................................................................. xii

LIST OF ABBREVIATIONS................................................................................................... xv

1. INTRODUCTION .................................................................................................................. 1

2. OBJECTIVES......................................................................................................................... 2

3. LITERATURE REVIEW ....................................................................................................... 3

4. BACKGROUND THEORY ................................................................................................... 5

4.1 Computer network............................................................................................................. 5

4.1.1 LAN (Local Area Network) ....................................................................................... 5

4.1.2 WAN (Wide Area Network) ...................................................................................... 6

4.1.3 TCP/IP protocol (TCP/IP Stack) ................................................................................ 7

4.2 Embedded Web Server.................................................................................................... 13

4.3 SPI (Serial Peripheral Interface) ..................................................................................... 14

4.4 RF (Radio Frequency)..................................................................................................... 16

viii
4.4.1 Need for wireless communication ............................................................................ 17

4.4.2 ISM band for RF communication............................................................................. 17

4.5 RF Communications ....................................................................................................... 18

4.6 Serial data transmission................................................................................................... 19

4.6.1 Asynchronous Serial Data Transmission.................................................................. 20

4.6.2 USART /UART ........................................................................................................ 21

4.7 I2C ................................................................................................................................... 21

5. TOOLS AND IDE USED..................................................................................................... 22

5.1 For Simulation................................................................................................................. 22

5.1.1 Proteus VSM ............................................................................................................ 22

5.2 Microcontroller Tools ..................................................................................................... 22

5.2.1 WinAVRTM ............................................................................................................... 22

5.2.2 AVR Studio .............................................................................................................. 23

5.2.3 USB-ASP.................................................................................................................. 23

5.2.4 PCB Wizard.............................................................................................................. 23

5.4.5 KiCAD...................................................................................................................... 23

5.3 Libraries Used ................................................................................................................ 24

5.3.1 RFM12 Library........................................................................................................ 24

5.3.2 RFM12 library features ............................................................................................ 24

6. MAJOR COMPONENTS USED ......................................................................................... 25

6.1 AVR Atmega644 microcontroller................................................................................... 25

ix
6.2 AVR Atmega328 microcontroller................................................................................... 26

6.3 AVR Atmega8 microcontroller....................................................................................... 26

6.3 ENC28J60 Ethernet Controller ....................................................................................... 27

6.4 Router.............................................................................................................................. 28

6.5 SD Card........................................................................................................................... 28

6.6 RFM12 module ............................................................................................................... 29

6.7 Relays.............................................................................................................................. 30

7. METHODOLOGY ............................................................................................................... 31

7.1. System Block Diagram .................................................................................................. 31

7.3 Hardware Implementation............................................................................................... 32

7.3.1 Embedded Web Server ............................................................................................. 32

7.3.2 RF Interfacing Modules............................................................................................ 33

7.3.3 Switching modules ................................................................................................... 34

7.4 Software Implementation ................................................................................................ 34

7.4.1 Embedded Web Server on ATMEGA644 ................................................................ 34

7.4.2 RF master on ATMEGA8 ........................................................................................ 38

7.4.3 RF Slave and Switching Module Controller on ATMEGA8 ................................... 40

8. TESTING.............................................................................................................................. 42

8.1 Testing of Prototype Module .......................................................................................... 42

8.2 Testing of RFM12 Module.............................................................................................. 43

9. PROJECT APPLICATION .................................................................................................. 44

10. PROJECT ADVANTAGES ............................................................................................... 46

x
11. PROBLEMS FACED AND SOLUTIONS USED............................................................. 47

11. RESULT ............................................................................................................................. 48

12. CONCLUSION AND FURTHER WORKS ...................................................................... 48

12.1 Conclusion .................................................................................................................... 48

12.2 Further Works ............................................................................................................... 48

13. BIBLOGRAPHY ................................................................................................................ 49

APPENDIX A : Data Sheet Snaps............................................................................................ 51

A.1 AVR Atmega8 Features ................................................................................................. 51

A.2 AVR Atmega328 features .............................................................................................. 53

A.3 AVR Atmega644 features .............................................................................................. 55

A.4 ENC28J60 Ethernet Controller Features........................................................................ 57

A.5 RFM12 Module Features ............................................................................................... 59

APPENDIX B : SCHEMATICS .............................................................................................. 60

APPENDIX B : SCHEMATICS .............................................................................................. 60

APPENDIX C : PCB LAYOUTS............................................................................................. 63

APPENDIX D : PROJECT SNAPSHOTS............................................................................... 65

APPENDIX E : PROJECT COST ............................................................................................ 67

xi
LIST OF TABLES
Table 4. 1: OSI Reference Model ............................................................................................... 8

Table 4. 2: TCP/IP 5-layer Reference Model ............................................................................. 8

Table 4. 3 : ISM band defined by ITU-R.................................................................................. 18

Table E. 1: Project Cost ............................................................................................................ 67

LIST OF FIGURES
Figure 4. 1: LAN Structure ......................................................................................................... 5

Figure 4. 2: TCP/IP Protocol Layering....................................................................................... 7

Figure 4. 3: IP Header............................................................................................................... 11

Figure 4. 4: Monitoring Home Equipment from the Office ..................................................... 13

Figure 4. 5: Interaction between single slave and single master .............................................. 14

Figure 4. 6: Interaction between different devices supporting SPI........................................... 15

Figure 4. 7: RF data communication between two microcontrollers........................................ 19

Figure 6. 1: AVR Atmega644 microcontroller ......................................................................... 25

Figure 6. 2: AVR Atmega328 microcontroller ......................................................................... 26

Figure 6. 3: AVR Atmega8 microcontroller ............................................................................. 26

Figure 6. 4: ENC28J60 Ethernet Controller Module ................................................................ 27

Figure 6. 5: Router .................................................................................................................... 28

Figure 6. 6: SD Card ................................................................................................................. 29

Figure 6. 7: RFM12 Module ..................................................................................................... 29

xii
Figure 6. 8: 5 pin SPDT relay ................................................................................................... 30

Figure 7. 1: System Block Diagram.......................................................................................... 31

Figure 7. 2: Embedded Web Server Interface using Atmega644 ............................................. 32

Figure 7. 3: Interfacing RFM12 Module with slave controller................................................. 33

Figure 7. 4: Switching module with relays and power adapter ................................................ 34

Figure 7. 5: Flowchart showing implementation of TCP/IP stack ........................................... 36

Figure 7. 6: Flowchart showing master communication with Atmega8................................... 39

Figure 7. 7: Flowchart showing RF slave communication with Atmega8 ............................... 41

Figure 8. 1: Embedded web server prototype ........................................................................... 42

Figure 8. 2: RFM Module testing in breadboard circuitry........................................................ 43

Figure 8. 3: RFM Module testing with Atmega328 interface................................................... 43

Figure A. 1: AVR Atmega8 pin diagram.................................................................................. 52

Figure A. 2: AVR Atmega328 pin diagram.............................................................................. 54

Figure A. 3: AVR Atmega644 pin diagram.............................................................................. 56

Figure A. 4: ENC28J60 Ethernet Controller pin diagrams....................................................... 58

Figure B. 1: AVR Atmega328 interface schematics................................................................. 60

Figure B. 2: AVR Atmega8 interface schematics..................................................................... 61

xiii
Figure C. 1: PCB layout of RFM12 module with Atmega8 controller..................................... 63

Figure C. 2: PCB Layout of Atmega328 interface ................................................................... 63

Figure C. 4: PCB layout of Switching Module......................................................................... 64

Figure C. 3: PCB layout of Atmega644 interface for embedded web server ........................... 64

Figure D. 1: Atmega644 interface for embedded web server................................................... 65

Figure D. 2: Complete Embedded web server unit................................................................... 65

Figure D. 3: Relay Interface Module with RFM12 (slave) and Atmega8 (slave) .................... 66

xiv
LIST OF ABBREVIATIONS
ARP Address Resolution Protocol

AVR Advanced Virtual RISC

AC/DC Alternating Current/Direct Current

ASK Amplitude Shift Keying

ARCNET Attached Resource Computer NETwork

BOOTP BOOTstrap Protocol

CAN Campus Area Network

DSL Digital Subscriber Line

DNS Domain Name System

DHCP Dynamic Host Configuration Protocol

DMA Dynamic Memory Access

EEPROM Electrically Erasable Programmable Read Only Memory

EDGE Enhanced Data rates for Global Evolution

FCC Federal Communications Commission

FTP File Transfer Protocol

FIFO First In Fist Out

FSK Frequency Shift Keying

GPRS General Packet Radio Service

xv
GHz Giga Hertz

GPS Global Positioning System

GCC GNU Compiler Collection

GNU GNU's Not Unix

HTML Hyper Text Transfer Protocol

HTTP Hyper Text Transfer Protocol

ISP In System Programming

ISM Industrial Scientific and Medical

I/O Input/output

IEEE Institute of Electrical and Electronics Engineers

IDE Integrated Development Environment

I2C Inter Integrated Circuit

ISO International Organization for Standardization

ITU International Telecommunication Union

ICMP Internet Controlled Message Protocol

IoT Internet of Things

IP Internet Protocol

IPv4 Internet Protocol version 4

LED Light Emitting Diode

xvi
LAN Local Area Network

MSTR Master

MHz Mega Hertz

MAN Metropolitan Area Network

MCU Micro Controller Unit

OSI Open System Interconnections

PAN Personal Area Network

PSU Power Supply Unit

PCB Printed Circuit Board

PWM Pulse Width Modulation

RCM Rabbit Core Microprocessor

RF Radio Frequency

RF Radio Frequency

RFID Radio Frequency Identification

RISC Reduced Instructions Set Computer

RFM RF Module

SD Secure Digital

SCL Serial Clock

SDA Serial Data/Address

xvii
SPI Serial Peripheral Interface

SMTP Simple Mail Transfer Protocol

SPDT Single Pole Double Throw

SPCR SPI Control Register

SRAM Static Random Access Memory

SSI Synchronous Serial Interface

TCP/TP Transmission Control Protocol/Internet Protocol

TOS Type OF Service

UART Universal Asynchronous Receiver Transmitter

USB Universal Serial Bus

USART Universal Synchronous Asynchronous Receiver Transmitter

UDP User Datagram Protocol

VLAN Virtual Local Area Network

VPN Virtual Private Network

VSM Virtual System Modelling

VoIP Voice over Internet Protocol

WAN Wide Area Network

Wi-Fi Wireless Fidelity

xviii
1. INTRODUCTION
In today’s world, everyone is busy and every second counts. Therefore, it is hard for
people to manage time for their every works. Technology has made a huge leap over years
and people are always keen to complete their works by the use of minimum amount of time
and money that is practicable. People have been more bounded to their works thereby
resulting a scarcity of time for household and other domestic works. A system that could
assist individual in controlling and monitoring household and other relevant activities at
their convenience would contribute in better utilization of their valuable time and
resources.

Therefore, we propose to develop an internet-based solution to facilitate this task. The


internet-based approach will have the advantages of wide accessibility (from any internet-
enabled device). Our proposed system uses embedded web server technology to provide a
low cost and low power solution.

We are going to control household devices like lights, ON/OFF control of simple
appliances like water pump, microwave oven, etc. Beside we can use our approach for
monitoring purposes like state of the controlled devices, temperature monitoring, and
status of doors/windows and so on.

1
2. OBJECTIVES
1. To design and implement remote home control and monitoring system.
2. To implement communication and control through internet using embedded web
server.
3. To design the communication system to be widely and easily accessible.
4. To design a low power and low cost system.
5. To build the proposed system within the predetermined time frame using minimum
possible cost.

2
3. LITERATURE REVIEW
While going through the relevant literatures, we got the information and knowledge on the
working of the embedded web server. Though there are computer based web server
prevalent, but due to the robustness and the many advantages in contrast to the computer
based web server many projects and research were carried out focusing the embedded web
server technology. Most of the researchers and project doers have used the ATMEL
microcontroller for their embedded web server projects. Talking about the projects and
research carried out implementing the embedded web server technology in other countries,
there are few to mention like Embedded Web Server (Bachelor level thesis) by Arturus
Lukosius at Vilnius Gediminas Technical University; Lithuania [2] , Embedded Web
Server based Remote Monitoring System by Tan Jing Hong at Universiti Teknikal
Malaysia [3], Embedded ATMEL HTTP Server by Jeremy Tzeming Tam at Cornell
University USA [4], AVR Microcontroller based Web Server by Vishram Mishra at Cochin
University of Science and Technology, India. [5]

Embedded Web Server was chiefly concerned with the creation of the embedded web
server. This bachelor level thesis had the details for the creating the embedded web server
by writing the TCP/IP HTTP protocol for the AVR microcontroller by using the Ethernet
interface.

Embedded Web Server based Remote Monitoring System, design and development of an
embedded web server using 8-bit microprocessor and TCP/IP Ethernet connection to be
used for office/home automation applications has been carried out. In this project, the
controller developed is based on Rabbit microprocessor and its core module model RCM
3700. Controlling the motor and others I/O like sensor and also alarms through a website
base controller is the primary task. Showing the I/O data through RCM 3700 with the
TCP/IP Ethernet connection to personal computer in webpage is another feature of this
project. The webpage and firmware has been done in Dynamic C programming language.
Embedded ATMEL HTTP Server is also focused in designing and building an embedded
HTTP server using a microcontroller chip. The web server in this project required the
3
implementation of the interface with Ethernet as well as several internet protocols such as
TCP/IP and ARP. This embedded web server is able to serve small, static web pages as
well as perform certain useful laboratory lab functions such as displaying the current
temperature read by the microcontroller from a thermometer, on the webpage. The web
server was built in this project has been successfully tested and a temperature reporting
feature has been added to it.
In AVR Microcontroller based Web Server, implementation of a web server over an AVR
microcontroller has been done. The web server can host a small web page that will be
stored in the microcontroller’s Flash memory. Through the interface of the web page, a
user can control the devices attached to the microcontroller.
After going through the several above literature in the web server, we got more
information in implementing the web server. We got the knowledge about the internet
protocol like TCP/IP or ARP that are needed to construct the web server. We also got to
know about the Ethernet interface that acts as the bridge between the web server and the
internet. The simple interfacing and other tasks can be done via the web server and the
overview can be viewed from the static web page hosted in the program memory of the
microcontroller itself.

4
4. BACKGROUND THEORY

4.1 Computer network


A computer network is an interconnection of a group of computers. Networks may be
classified by what is called the network layer at which they operate according to basic
reference models considered as standards in the industry such as the four layer Internet
Protocol Suite model. While the seven-layer Open Systems Interconnection (OSI)
reference model is better known in academia, the majority of networks use the Internet
Protocol Suite (IP) as their network model.

4.1.1 LAN (Local Area Network)

Figure 4. 1: LAN Structure

A local area network (LAN) is a computer network covering a small geographic area, like
a home, office, or group of buildings. The defining characteristics of LANs, in contrast to
Wide Area Networks (WANs), include their much higher data transfer rates, smaller
geographic range, and lack of a need forleased telecommunication lines. Ethernet over
unshielded twisted pair cabling, and Wi-Fi are the two most common technologies
5
currently, but ARCNET, Token Ring and many others have been used in the past.
Although switched Ethernet is now the most common data link layer protocol and IP as a
network layer protocol, many different options have been used, and some continue to be
popular in niche areas. Smaller LANs generally consist of a one or more switches linked to
each other - often with one connected to a router, cable modem, or DSL modem for
Internet access. Larger LANs are characterized by their use of redundant links with
switches using the spanning tree protocol to prevent loops, their ability to manage differing
traffic types via quality of service, and to segregate traffic via VLANing. LANs may have
connections with other LANs via leased lines, leased services, or by 'tunneling' across the
Internet using VPN technologies.

4.1.2 WAN (Wide Area Network)


Wide Area Network (WAN) is a computer network that covers a broad area (example: any
network whose communications links cross metropolitan, regional, or national boundaries).
Or, less formally, a network that uses routers and public communications links. Contrast
with personal area networks (PANs), local area networks (LANs), campus area networks
(CANs), or metropolitan area networks (MANs) which are usually limited to a room,
building, campus or specific metropolitan area (e.g., a city) respectively. The largest and
most well-known example of a WAN is the Internet. WANs are used to connect LANs and
other types of networks together, so that users and computers in one location can
communicate with users and computers in other locations. Many WANs are built for one
particular organization and are private. Others, built by Internet service providers, provide
connections from an organization's LAN to the Internet. WANs are often built using leased
lines. At each end of the leased line, a router connects to the LAN on one side and a hub
within the WAN on the other. Leased lines can be very expensive. Instead of using leased
lines, WANs can also be built using less costly circuit switching or packet switching
methods. Network protocols including TCP/IP deliver transport and addressing functions.

6
4.1.3 TCP/IP protocol (TCP/IP Stack)
The Internet protocol suite is the set of communications protocols that implement the
protocol stack on which the Internet and most commercial networks run. It has also been
referred to as the TCP/IP protocol suite, which is named after two of the most important
protocols in it: the Transmission Control Protocol (TCP) and the Internet Protocol (IP),
which were also the first two networking protocols defined. The Internet Protocol suite—
like many protocol suites—can be viewed as a set of layers. Each layer solves a set of
problems involving the transmission of data, and provides a well-defined service to the
upper layer protocols based on using services from some lower layers. Upper layers are
logically closer to the user and deal with more abstract data, relying on lower layer
protocols to translate data into forms that can eventually be physically transmitted. The
TCP/IP reference model consists of four layers. The TCP/IP flow that I use for my PSM is
from the application layer (HTTP) then the data will send to the transport layer (TCP) and
go to the network (IP) and lastly go to the data link (the Ethernet).

Figure 4. 2: TCP/IP Protocol Layering

7
4.1.3.1 Network Protocol Layers
Computers on a network communicate in agreed upon ways called protocols. The
complexity of networking protocol software calls for the problem to be divided into
smaller pieces. A layering model aids this division and provides the conceptual basis for
understanding how software protocols together with hardware devices provide a powerful
communication system.

4.1.3.2 Layering Models


In the early days of networking, before the rise of the ubiquitous Internet, the International
Organization for Standardization (ISO) developed a layering model whose terminology
persists today.
Name of Purpose of Layer
Layer
Layer 7 Application Specifies how a particular application uses a network
Layer 6 Presentation Specifies how to represent data
Layer 5 Session Specifies how to establish communication with a remote system.
Layer 4 Transport Specifies how to reliably handle data transfer.
Layer 3 Network Specifies addressing assignments and how packets are
forwarded.
Layer 2 Data Link Specifies the organization of data into frames and how to send
frames over a network.
Layer 1 Physical Specifies the basic network hardware.

Table 4. 1: OSI Reference Model

Name of Layer Purpose of Layer


Layer 5 Application Specifies how a particular application uses a network
Layer 4 Transport Specifies how to ensure reliable transport of data

Layer 3 Internet Specifies packet format and routing.


Layer 2 Network Specifies frame organization and transmittal

Layer 1 Physical Specifies the basic network hardware.

Table 4. 2: TCP/IP 5-layer Reference Model

8
The 7-layer model has been revised to the 5-layer TCP/IP reference model to meet the
current needs of protocols.

4.1.3.3 Application layer


HTTP – Hypertext Transfer Protocol is a communications protocol used to transfer or
convey information on the World Wide Web. HTTP is a request/response protocol
between clients and servers.
FTP – File Transfer Protocol is used to transfer data from one computer to another over
the Internet, or through a network. FTP is a commonly used protocol for exchanging files
over any network that supports the TCP/IP protocol.
SMTP – Simple Mail Transfer Protocol is the standard for e-mail transmissions across the
Internet. SMTP is a relatively simple, text-based protocol, where one or more recipients of
a message are specified and then the message text is transferred.
DNS – Domain Name System. Domain names are significant because they guide users to
where they want to go on the Internet. It stores other information such as the list of mail
exchange servers that accept email for a given domain. In providing a worldwide keyword-
based redirection service, the Domain Name System is an essential component of
contemporary Internet use. The most basic use of DNS is to translate hostnames to IP
addresses. It is in very simple terms like a phone book. For example, if you want to know
the internet address of www.utem.edu.my, the Domain Name System can be used to tell
you it is 60.125.130.10.
DHCP – DHCP (Dynamic Host Configuration Protocol) is a protocol used by networked
computers (clients) to obtain IP addresses and other parameters such as the default
gateway, subnet mask, and IP addresses of DNS servers from a DHCP server. DHCP is a
more advanced protocol based on BOOTP, but is far more complex to implement. Most
DHCP servers also offer BOOTP support.
BOOTP – short for BOOTstrap Protocol is a UDP network protocol used by a network
client to obtain its IP address automatically. This is usually done in the bootstrap process of
9
computers or operating systems running on them. The BOOTP servers assign the IP
address from a pool of addresses to each client. BOOTP enables 'diskless workstation'
computers to obtain an IP address prior to loading any advanced operating system.
Transport layer
TCP – The Transmission Control Protocol (TCP) is one of the core protocols of the
Internet protocol suite. TCP provides reliable, in-order delivery of a stream of bytes,
making it suitable for applications like file transfer and e-mail. It is so important in the
Internet protocol suite that sometimes the entire suite is referred to as "the TCP/IP protocol
suite." The Internet Protocol (IP) works by exchanging groups of information called
packets. Packets are short sequences of bytes consisting of a header and a body. The
header describes the packet's destination, which routers on the Internet use to pass the
packet along, in generally the right direction, until it arrives at its final destination. The
body contains the application data.
UDP – User Datagram Protocol (UDP) is one of the core protocols of the Internet protocol
suite. Using UDP, programs on networked computers can send short messages sometimes
known as datagrams to one another. UDP is sometimes called the Universal Datagram
Protocol. Unlike TCP, UDP supports packet broadcast (sending to all on local network)
and multicasting. Common network applications that use UDP include the Domain Name
System , streaming media applications such as IPTV, Voice over IP , Trivial File Transfer
Protocol and online games.

4.1.3.4 Network layer


IP – IP address (Internet Protocol address) is a unique address that certain electronic
devices use in order to identify and communicate with each other on a computer network
utilizing the Internet Protocol standard (IP)—in simpler terms, a computer address. Any
participating network device—including routers, switches, computers, time-servers,
printers, Internet fax machines, and some telephones—can have their own unique address.
An IP address can also be thought of as the equivalent of a street address or a phone
number (compare: VoIP (voice over (the) internet protocol)) for a computer or other
network device on the Internet. ARP – The Address Resolution Protocol (ARP) is the
10
standard method for finding a host's hardware address when only its network layer address
is known. ARP is not an IP-only or Ethernet-only protocol; it can be used to resolve many
different network-layer protocol addresses to hardware addresses, although, due to the
overwhelming prevalence of IPv4 and Ethernet, ARP is primarily used to translate IP
addresses to Ethernet MAC addresses. It is also used for IP over other LAN technologies,
such as Token Ring, FDDI, or IEEE 802.11, and for IP over ATM.

4.1.3.4 Internet Protocol (IP)


All TCP, UDP and ICMP data get transmitted as IP datagrams. IP provides an unreliable,
connectionless datagram delivery service. There is no guarantee that an IP datagram
successfully gets to its destination. When something goes wrong, IP has a simple error
handling algorithm: Throw away datagram and try to send an ICMP message back to the
source. Any required reliability must be provided by the upper layers.

IP Header Figure shows the format of an IP datagram. The normal size of the IP header is
20 bytes, unless options are present. The most significant bit is numbered 0 at the left, and
the least significant bit of a 32-bit value is numbered 31 on the right. The 4 bytes in the 32-
bit value are transmitted in the order: bits 0 - 7, then bits 8 – 15 and so on. This is called
Big-Endian byte ordering, which is the byte ordering required for all binary integers in the
TCP/IP headers as they traverse a network. This is called the network byte order.

Figure 4. 3: IP Header

11
Header length The header length is the number of 32-bit words (4 bytes per word) in the
header, including any options. This limits the header length to 60 bytes.

Type of Service (TOS) The field, (TOS) is composed of a 32-bit precedence field (which
is currently ignored), 4 TOS bits, and an unused bit that must be 0. The 4 TOS bits are:
minimize delay, maximize throughput, maximize reliability and minimize monetary cost.
Only 1 of these bits can be turned on. If all 4 bits are 0, it implies normal service

Total Length This is the total length of the IP datagram in bytes. Using this field and the
header length field, we know where the data portion of the IP datagram starts and its
length. Since this is a 16-bit field, the maximum size of an IP datagram is 65535 bytes.

Identification This field uniquely identifies each datagram sent by a host. It normally
increments by one each time a datagram is sent.
Time to Live sets an upper limit on the number of routers through which datagram can
pass. It limits the lifetime of the datagram. It is initialized by the sender to some value
(Often 32 or 64) and decrements by one in every router that handles the datagram. Then
this field reaches 0, the datagram is discarded, and the sender is notified with an ICMP
message. This prevents the packet from getting caught in eternal routing loops.

Protocol is used by IP to demultiplex incoming datagrams. It identifies which protocol


gave the data for IP to send.

Header Checksum is calculated over the IP header only. It does not cover any data that
follows the header. ICMP, UDP and TCP all have a checksum in their own headers to
cover their own header and data. Every IP datagram contains the source IP address and the
destination IP address. These are 32-bit values.

The Option Field This is a variable-length list of optional information for the datagrams.
The options are rarely used and not all hosts and routers support the option.

12
4.2 Embedded Web Server
Small systems to large systems may provide an interface and control via the onboard
switches or via IR or RF based remote control. But what if the User who wants to control a
device, is out of reach of the device or is at another part of world. There are other methods
developed to control the devices remotely, but each technique requires some new
implementations to be done. Here we use the existing technique of Internet Web based
HTTP protocol with TCP/IP protocol suite to control the devices. Embedding a web
application in a system is termed as embedded web server. Suppose an Embedded Web
Server is embedded in several units in a house as shown in figure 1.1. Every server is
connected to the network. A computer located a home as on figure controls all devices and
can receive requests from other computers on the Internet. The web server is identified by
its unique IP address and can be controlled remotely from anywhere in the world. A
computer located in an office may send a request to turn off the Refrigerator located at
home via Internet. The web server will be running an HTTP application through the
interface of which the user can control and monitor the devices.

Figure 4. 4: Monitoring Home Equipment from the Office


13
An embedded HTTP server is a component of a software system that implements the
HTTP protocol.

Examples of usage within an application might be:

 To provide a thin-client interface for a traditional application.


 To provide indexing, reporting, and debugging tools during the development stage.
 To implement a protocol for the distribution and acquisition of information to be
displayed in the regular interface — possibly a web service, and possibly using
XML as the data format.
 To develop a web application

There are a few advantages to using HTTP to perform the above:


 HTTP is a well studied cross-platform protocol and there are mature
implementations freely available.
 HTTP is seldom blocked by firewalls and intranet routers.
 HTTP clients (e.g. web browsers) are readily available with all modern computers.
 There is a growing tendency of using embedded HTTP servers in applications that
parallels the rising trends of home-networking and ubiquitous computing.

4.3 SPI (Serial Peripheral Interface)


The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard,
named by Motorola, that operates in full duplex mode. Devices communicate
in master/slave mode where the master device initiates the data frame. Multiple slave
devices are allowed with individual slave select (chip select) lines. Sometimes SPI is called
a four-wire serial bus, contrasting with three-, two-, and one-wire serial buses. SPI is often
referred to as SSI (Synchronous Serial Interface).

14
Figure 4. 5: Interaction between single slave and single master
An ATmega 32 Microcontroller uses SPI (Serial Peripheral Interface) to effectively
communicate with the Ethernet controller ENC28J60. The usage of SPI provides serial
communication thus eliminating large number of lines used for data and addressing
purpose. The SPI allows high-speed synchronous data transfer between the AVR and
peripheral devices or between several AVR devices. On most parts the SPI has a second
purpose where it is used for In System Programming (ISP). The interconnection between
two SPI devices always happens between a master device and a slave device. Compared to
some peripheral devices like sensors which can only run in slave mode, the SPI of the
AVR can be configured for both master and slave mode. The mode the AVR is running in
is specified by the settings of the master bit (MSTR) in the SPI control register (SPCR).
Special considerations about the SS pin have to be taken into account.

The master is the active part in this system and has to provide the clock signal a serial data
transmission is based on. The slave is not capable of generating the clock signal and thus
cannot get active on its own. The slave just sends and receives data if the master generates
the necessary clock signal. The master however generates the clock signal only while
sending data. That means that the master has to send data to the slave to read data from the
slave. The interaction between a master and a slave AVR is shown in the figure

Figure 4. 6: Interaction between different devices supporting SPI 15


Two identical SPI units are displayed. The left unit is configured as master while the right
unit is configured as slave. The MISO, MOSI and SCK lines are connected with the
corresponding lines of the other part. The mode in which a part is running determines if
they are input or output signal lines. Because a bit is shifted from the master to the slave
and from the slave to the master simultaneously in one clock cycle both 8-bit shift registers
can be considered as one 16-bit circular shift register. This means that after eight SCK
clock pulses the data between master and slave will be exchanged. The system is single
buffered in the transmit direction and double buffered in the receive direction.

4.4 RF (Radio Frequency)


Radio frequency or RF is a frequency or rate of oscillation in the range of 3 Hz to 300
GHz. This range relates to the frequency of alternating current electrical signals to create
and detect radio waves. As this range is beyond the vibration rate that many mechanical
systems respond to, RF refers to oscillations in electrical circuits. When the current is input
to an antenna, an electromagnetic field is generated that is suitable for wireless
broadcasting and/or communications. These frequencies cover the electromagnetic
radiation spectrum ranging from nine kilohertz, the lowest allocated wireless
communications frequency to thousands of gigahertz. When an RF current is given to an
antenna, an electromagnetic field is created that propagates through space. Properties of RF
current are:

 The energy in an RF current can radiate off a conductor into space as


electromagnetic waves (radio waves); this is the basis of radio technology.
 RF current does not penetrate deeply into electrical conductors but tends to flow
along their surfaces; this is known as the skin effect. For this reason, when the
human body comes in contact with high power RF currents it can cause superficial
but serious burns called RF burns.
 RF currents applied to the body often do not cause the painful sensation of electric
shock as do lower frequency currents.[2][3] This is because the current changes
direction too quickly to trigger depolarization of nerve membranes.

16
 RF current can easily ionize air, creating a conductive path through it. This
property is exploited by "high frequency" units used in electric arc welding, which
use currents at higher frequencies than power distribution uses.
 Another property is the ability to appear to flow through paths that contain
insulating material, like the dielectric insulator of a capacitor.
 When conducted by an ordinary electric cable, RF current has a tendency to reflect
from discontinuities in the cable such as connectors and travel back down the cable
toward the source, causing a condition called standing waves, so RF current must
be carried by specialized types of cable called transmission line.

4.4.1 Need for wireless communication

 Wireless networks are wire free, relying on radio waves to transmit data instead of
cables. Wires have a tendency to get tangled, lost or damaged over time. Wireless
devices eliminate this concern.
 Efficiency - improved communications leads to faster transfer of information
within businesses and between partners/customers.
 You are rarely out of touch - you don't need to carry cables or adaptors in order to
access office networks.
 Reduced costs - relative to 'wired', wireless networks are, in most cases, cheaper to
install and maintain.

4.4.2 ISM band for RF communication


The industrial, scientific and medical (ISM) radio bands are radio bands (portions of the
radio spectrum) reserved internationally for the use of radio frequency (RF) energy for
industrial, scientific and medical purposes other than telecommunications.[1] Examples of
applications in these bands include radio-frequency process heating, microwave ovens, and
medical diathermy machines. The powerful emissions of these devices can create
electromagnetic interference and disrupt radio communication using the same frequency,
so these devices were limited to certain bands of frequencies. In general, communications

17
equipment operating in these bands must tolerate any interference generated by ISM
equipment, and users have no regulatory protection from ISM device operation.

Despite the intent of the original allocations, and because there are multiple allocations, in
recent years the fastest-growing uses of these bands have been for short-range, low power
communications systems. Cordless phones, Bluetooth devices, near field communication
devices, and wireless computer networks all use frequencies allocated to low power
communications as well as ISM.

Table 4. 3 : ISM band defined by ITU-R

4.5 RF Communications
In our daily life, a communication link between two devices becomes essential. This
communication may be wired or wireless. If two devices we are dealing with are close to
each other (like a MCU and a Memory) then a wired link is preferred. However in many
situations two devices we are dealing with are reasonably far apart. In such a case a
wireless link is preferred.

Some of the distinctive features of RF data communication are:

 Widely used, including Bluetooth, Radios, Cell phones, Satellite, etc.

18
 Wide range, from few meters to millions of kilometers (Can be Used to control
Robots in Mars)
 Does not require two devices to be in line of sight.
 Can cross many obstacles
 Circuits can be complicated and costly.

The RF communication is carried out via RF module. The module consists of the
transmitter and the receiver circuitry. The transmitter is fed with the data from one
controller and the receiver receives the data from the transmitter. The general transmission
of the data between two controllers using RF communication can be depicted from the
following figure.

Figure 4. 7: RF data communication between two microcontrollers

4.6 Serial data transmission


The digital data can be transmitted between any two devices in two fashions, parallel or
serial. Serial data transmission means information is transmitted from source to destination
over a single pathway and one bit is transmitted at a time. There are two modes of serial
data transmission.

a) Simplex: Data is transmitted in single direction.


b) Duplex: Data is transmitted in either direction.
19
c) Half duplex: Transmission can be done on both direction but not simultaneously.
d) Full duplex: Transmission can be done on both direction and simultaneously.
Both synchronous and asynchronous serial data communication are widely used in serial
data transmission. The synchronous method transfers a block of data (characters) at a time,
whereas the asynchronous method transfers a single byte at a time. Asynchronous serial
data communication is widely used for character oriented transmissions. In this method,
each over a computer or peripheral device serial port .UARTs are now commonly included
in microcontrollers. The Universal Asynchronous Receiver/Transmitter (UART) takes
bytes of data and transmits the individual bits in a sequential fashion. At the destination, a
second UART reassembles the bits into complete bytes. Each UART contains a shift
register which is the fundamental method of conversion between serial and parallel forms.
Serial transmission of digital information (bits) through a single wire or other medium
character is placed between start and stop bits. This is called framing. The start bit is
always one bit, but the stop bit can be one or two bits. The start bit is always a 0(low), and
the stop bit(s) is 1(high). By using USART unit we can transfer data to computers. To
allow compatibility among data communication equipment made by various
manufacturers, an interfacing standard called RS232 was set. RS232 is one of the most
widely used interfacing standards. This standard is used in PCs and numerous types of
equipment.

4.6.1 Asynchronous Serial Data Transmission


In this type of data transmission, the receiving device does not need to be synchronized
with the transmitting device. The transmitting device can send one or more data units when
it is ready to send data. Each data unit must be formatted. In other words, each data unit
must contain start and stop bits, indicating the beginning and the end of each data unit. The
interface circuit is required between the microcomputer and the serial I/O device. Each
asynchronous serial data unit can be divided into equal time intervals called bit intervals.
An 8 bit data will have 8 bit intervals. Thus each data bit will correspond to one of the 8
intervals. The format for asynchronous serial data contains the following information:

20
 A low START bit that indicates beginning of the data to be transferred.
 8 data bits, denoting the actual data being transferred.
 An optional parity bit for either odd or even parity.

4.6.2 USART /UART


A UART is a well established standard for low cost, low speed serial communications over
a simple 2-wire (plus ground) interface. Asynchronous communications differs from
synchronous communications in that synchronization between transmitter and receiver are
encoded into the transmitted signal, rather than using a separate wire to transfer the
transmitter clock to the receiver. Embedding the synchronization information in the data
reduces the cost of cables and connectors, and may also be beneficial on a space
constrained PCB or if one wants to keep the pin-usage low. On the other side adding
synchronization information to the data stream increases overhead, causing the effective
data rate to be lower than the baud rate. Normally, asynchronous communication modes
facilitate somewhat lower data rates compared with synchronous modes. Some of the
reason is the above mentioned overhead, but also because asynchronous communications
may impose stronger requirements on the transceivers and the transmission lines between
receiver and transmitter. Low cost and low power transceivers usually don't have advanced
clock recovery mechanisms, but simply rely on the combination of oversampling and that
the receiver and transmitter clock frequencies are sufficiently close.

4.7 I2C
I2C is the interface type. This one originated with Philips/Signetics, whose 8XC528 (8051
family) is an example of a microcontroller with an I2C interface built-in. The I2C interface
requires just two signal lines, plus a common ground. Serial Data/Address (SDA) is a
bidirectional line that requires open-collector or open-drain outputs. Serial Clock (SCL) is
the clock. Instead of a chip-select line, the master sends a slave address on SDA.

21
5. TOOLS AND IDE USED

Integrated Development Environment is a software application that provides facilities for


programmer for software Development. Beside the IDE we have used many software tools
to facilitate in completing our project works.

5.1 For Simulation

5.1.1 Proteus VSM


The Proteus Virtual system modeling (VSM) combines mixed mode SPICE circuit
simulation, animated components and microcontroller models to facilitate co-simulation of
complete microcontroller based design. It is possible to develop and test such designs
before a physical prototype is constructed. This is possible because we can interact with
the design using circuit indicators like LED, display panels, actuators etc. It also provides
extensive debugging facility by employing breakpoints, single stepping and variable
display of both assembly code and high level language source code. We have used Proteus
in order to be assured about the hardware we are trying to implement before making them
in the real world hardware.
5.2 Microcontroller Tools

5.2.1 WinAVRTM

WinAVRTM (pronounced "whenever") is a suite of executable, open source software


development tools for the Atmel AVR series of RISC microprocessors hosted on the
Windows platform. It includes the GNU GCC compiler for C and C++. WinAVR contains
all the tools for developing on the AVR. This includes avr-gcc (compiler), avrdude
(programmer), avr-gdb (debugger), and more. WinAVR is used all over the world from
hobbyists sitting in their damp basements, to schools, to commercial projects.
WinAVRTM is comprised of many open source projects. If you feel adventurous,
volunteers are always welcome to help with fixing bugs, adding features, porting, writing
documentation and many other tasks on a variety of projects.
22
5.2.2 AVR Studio
Atmel® AVR Studio is the Integrated Development Environment (IDE) for developing
and debugging embedded Atmel AVR applications. The AVR Studio 5 IDE gives user a
seamless and easy-to-use environment to write, build, and debug C/C++ and assembler
code. The AVR studio includes a compiler, assembler and a simulator, and interfaces
seamlessly with the in-system debuggers and programmers to make code development
easier.

5.2.3 USB-ASP
USB-ASP is an open source AVR ISP programmer. It is supported by AVR-DUDE AVR
programmer and can program all AVR devices supporting SPI ISP programming mode.

5.2.4 PCB Wizard


The PCB wizard is a powerful and a highly innovative package for designing single side
and double side PCBs. It provides a comprehensive range of tools covering all the
traditional steps in PCB production, including schematic drawing, schematic capture,
component placement, automatic routing. Circuit diagrams are drawn using circuit symbol
components connected with wires. Components are simply dragged, dropped and arranged
in the working window and necessary connections are made between the component
terminals.

5.4.5 KiCAD
KiCAD is an open source software suite for electronic design automation. It facilitates the
design of schematics for electronic circuits and their conversion to PCBs (printed circuit
board) design. KiCAD uses an integrated environment for all of the stages of the design
process schematic Capture, PCB layout, Gerber file generation/visualization and library
editing. KiCAD has a built-in basic auto router. Tools exist within the package to create
artwork and 3D view of the PCB. KiCAD is also a cross platform.

23
5.3 Libraries Used

5.3.1 RFM12 Library


Rfm12lib is an open source library for Atmel AVR microcontrollers that allow the user to
hook up RF12 modules (RFM12) from HopeRF to your microcontroller and add wireless
functionality to the project. It is written in C and requires the free AVR-GCC compiler.
The library supports modules of all frequency bands.

5.3.2 RFM12 library features


Some of the features of the open source library that we used are listed below:

 Basic packet format, including:


o An 8-bit (0..255) packet type or address field
o Packet length up to 255 bytes
o A simple header checksum
 Interrupt or polling based packet transfer handling
 Multiple frequency bands, depending on the used module (433, 868 and 915 MHz)
 Collision avoidance (carrier sense)
 Usage of synchronization patterns to start data reception
 Hardware or software SPI support
 Transmit only mode, to reduce the size of the binary
 Basic ASK (amplitude shift keying) receive and transmit functionality (for radio
controlled outlets and the like)
 Low-battery detection feature (using the RFM12)
 Low-power Wakeup timer feature (using the RFM12)

24
6. MAJOR COMPONENTS USED
6.1 AVR Atmega644 microcontroller
The high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller
combines 64KB ISP flash memory with read-while-write capabilities, 2KB EEPROM,
4KB SRAM, 32 general purpose I/O lines, 32 general purpose working registers, real time
counter, three flexible timer/counters with compare modes and PWM, 2 USARTs, byte
oriented 2-wire serial interface, 8-channel/10-bit A/D converter with optional differential
input stage with programmable gain, programmable watchdog timer with internal
oscillator, SPI serial port, JTAG (IEEE 1149.1 compliant) test interface for on-chip
debugging, and six software selectable power saving modes. The device operates between
2.7-5.5 volts. By executing powerful instructions in a single clock-cycle, the device
achieves throughputs approaching 1 MIPS per MHz, balancing power consumption and
processing speed.

Figure 6. 1: AVR Atmega644 microcontroller

25
6.2 AVR Atmega328 microcontroller
The high-performance Atmel picoPower 8-bit AVR RISC-based microcontroller combines
32KB ISP flash memory with read-while-write capabilities, 1024B EEPROM, 2KB
SRAM, 23 general purpose I/O lines, 32 general purpose working registers, three flexible
timer/counters with compare modes, internal and external interrupts, serial programmable
USART, a byte-oriented 2-wire serial interface, SPI serial port, a 6-channel 10-bit A/D
converter (8-channels in TQFP and QFN/MLF packages), programmable watchdog timer
with internal oscillator, and five software selectable power saving modes. The device
operates between 1.8-5.5 volts. By executing powerful instructions in a single clock cycle,
the device achieves throughputs approaching 1 MIPS per MHz, balancing power
consumption and processing speed.

Figure 6. 2: AVR Atmega328 microcontroller

6.3 AVR Atmega8 microcontroller


The low-power Atmel 8-bit AVR RISC-based microcontroller combines 8KB of
programmable flash memory, 1KB of SRAM, 512K EEPROM, and a 6 or 8 channel 10-bit
A/D converter. The device supports throughput of 16 MIPS at 16 MHz and operates
between the voltages ranging from 2.7-5.5 volts. It has been used as the slave controller.

Figure 6. 3: AVR Atmega8 microcontroller

26
6.3 ENC28J60 Ethernet Controller
Microchip's ENC28J60 is a 28-pin, 10BASE-T stand alone Ethernet Controller with on
board MAC & PHY, 8 Kbytes of Buffer RAM and an SPI serial interface. With a small
foot print package size the ENC28J60 minimizes complexity, board space and cost. Target
applications include VoIP, Industrial Automation, Building Automation, Home Control,
Security and Instrumentation. The ENC28J60 is a stand-alone Ethernet controller with an
industry standard Serial Peripheral Interface (SPI™). It is designed to serve as an Ethernet
network interface for any controller equipped with SPI. The ENC28J60 meets all of the
IEEE 802.3 specifications. It incorporates a number of packet filtering schemes to limit
incoming packets. It also provides an internal DMA module for fast data throughput and
hardware assisted IP checksum calculations. Communication with the host controller is
implemented via two interrupt pins and the SPI, with data rates of up to 10 Mb/s. Two
dedicated pins are used for LED link and network activity indication.

Figure 6. 4: ENC28J60 Ethernet Controller Module

27
6.4 Router
A router is a device that forwards data packets between computer networks, creating an
overlay internetwork. A router is connected to two or more data lines from different
networks. When a data packet comes in one of the lines, the router reads the address
information in the packet to determine its ultimate destination. Then, using information in

Figure 6. 5: Router

its routing table or routing policy, it directs the packet to the next network on its journey.
Routers perform the "traffic directing" functions on the Internet. In our project we have
used the local network of the router in order to send the command to the controlled
devices. The network of the router is also fed to the ENC28J60 module.

6.5 SD Card
Secure Digital or (SD) is a non-volatile memory card format for use in portable devices,
such as mobile phones, digital cameras, GPS navigation devices, and tablet computers. The
Secure Digital standard is maintained by the SD Card Association (SDA). SD technologies
have been implemented in more than 400 brands across dozens of product categories and
more than 8,000 models. The Secure Digital format includes four card families available in
three different form factors. The four families are the original Standard-Capacity (SDSC),
the High-Capacity (SDHC), the extended-Capacity (SDXC), and the SDIO, which
combines input/output functions with data storage. The three form factors are the original
size, the "mini" size, and the "micro" size. There are many combinations of form factors
and device families. Electrically passive adapters allow the use of a smaller card in a host

28
Figure 6. 6: SD Card

device built to hold a larger card. SD card is used in our project in order to store the
database of all the monitoring and controlling actions

6.6 RFM12 module


The RFM12 is a great inexpensive option for wireless communication; it's an ISM band
FSK transceiver module implemented with a unique PLL. These modules operate in the
434MHZ band and fully comply with FCC and ETSI regulations. This module has a wide
voltage supply range of 2.2-3.8VDC. An SPI interface is used to send data and configure
the RFM12 module. The configuration commands, described in the RF12 IC Datasheet
linked below, can be used to set the data rate, frequency band, wake-up timer, transfer data,
receive data from the 16-bit FIFO, and many other functions. Here RFM12 module has
been used to transmit the control signals between the master and the slave controller units.

Figure 6. 7: RFM12 Module

29
6.7 Relays
A relay is an electrically operated switch. Many relays use an electromagnet to operate a
switching mechanism mechanically, but other operating principles are also used. Relays
are used where it is necessary to control a circuit by a low-power signal (with complete
electrical isolation between control and controlled circuits), or where several circuits must
be controlled by one signal. We have used relay as a switch to control the states (ON/OFF)
of the devices.

Figure 6. 8: 5 pin SPDT relay

30
7. METHODOLOGY

7.1. System Block Diagram

Master Unit

SD Card
Embedded
Web Server

AC/DC Main Ethernet Network


PSU Controller Interface Connection USER
RF Module

RF Module RF Module

Secondary Secondary
Controller Controller

I/O Board I/O Board


Relays Sensors Relays Sensors

Slave Unit Slave Unit

Figure 7. 1: System Block Diagram

31
7.3 Hardware Implementation
Hardware-wise, the main components of the system can be divided into following:

Embedded Web Server


RF Interface Modules
Switching Modules

7.3.1 Embedded Web Server


The Embedded Web Server consists of the main controller interface for ATMEGA644, SD
card interface, ENC28j60 Ethernet Controller Module and power supply unit. The main
Controller (ATMEGA644) is clocked at its highest rate of 20 MHz to give (almost)
20MIPS computation speed. It interfaces with ENC28j60 Ethernet controller through
hardware SPI, SD card through software SPI and to the RF interfacing module through
hardware UART. To allow the maximum allowed clock rate (20MHz) for the controller, it
is powered at 5V Vcc. ENC28j60 and SD card require 3.3V Vcc, thus dual supply of 5V
and 3.3V is provided on the interface. ENC28J60 has 5V tolerant SPI inputs, while SD
card interface is through 1K: 2.2K Resistive Voltage Divider.

Figure 7. 2: Embedded Web Server Interface using Atmega644

32
7.3.2 RF Interfacing Modules
The RF interfacing modules are small modules interfacing one ATMEGA8 microcontroller
and one RFM12/B module. The Module contains Socket for attaching RFM12/B module.
The module also has fixed i/o pins of the ATMEGA8 microcontroller available to be
interfaced outside to act as a fully functional slave unit in the system, as well as UART
pins for interfacing with another master controller to act as a wireless link. The RFM12B
modules, requiring <3.6V Vcc, the wireless modules are run at 3.3V, with ATMEGA8
running at 8 MHz to keep within recommended specifications.

Figure 7. 3: Interfacing RFM12 Module with slave controller

33
7.3.3 Switching modules
The Switching modules are relay control modules that switch on and off to control the
attached devices. Each SPDT relay controls a single device to be attached to the system.
The relays are driven by ULN2003 Darlington array.

Figure 7. 4: Switching module with relays and power adapter

7.4 Software Implementation


Software-wise, the embedded web server and home control system can be divided into

Embedded Web Server on ATMEGA644


RF master on ATMEGA8
RF Slave + Switching Module Controller on ATMEGA8

7.4.1 Embedded Web Server on ATMEGA644


The code for the embedded web server lies in the ATMEGA644 microcontroller on the
Embedded Web Server Module. ATMEGA644 microcontroller was selected for this case
for having the largest amount of RAM (4KB) and ROM (64KB) among the ATMEGA
family of microcontrollers available locally.
The code for this controller can be roughly divided into 4 Sections

34
i. TCP/IP Stack
ii. SD Card + FAT
iii. UART
iii. Main Operating Code

The TCP/IP stack contains all required functions and modules for the web server, including
low level drivers for ENC28J60 Ethernet Controller (enc28j60.h, enc28j60.c), TCP/IP
stack implementation (ip_arp_udp_tcp.h, ip_arp_udp_tcp.c, net.h), and helper functions for
http server (websrv_help_functions.h, websrv_help_functions.c) such as url
encoding/decoding and string searching. The web server is implemented as HTTP/1.0
server (without keep alive connections), making the implementation simpler in terms of
memory requirement for use in low memory embedded systems.

SD card is interfaced through its available SPI mode for sake of simplicity in embedded
design. The card is accessed through FAT16/32 filesystem through the ‘fatfs’ embedded
file system library. This section contains all necessary code for FAT32 filesystem access
on SD card including low level SD/SPI access functions(mmc.c) and FAT filesystem
access functions(ff.h, ff.c, diskio.h).
Due to requiring 3.3V signal levels (while ENC28J60 tolerated 5V signals), rather than
sharing SPI bus, SD interface was placed on GPIO pins using software SPI (part of low
level driver in mmc.c).

The UART section comprises of code for handling UART (Serial Communcation)
functions. It includes uart.h and uart.c. It is an interrupt based UART implementation with
circular buffers for both RX and TX. This implementation allows efficient and error free
usage of hardware UART with minimal delay and impact on the other code sections. The
UART is used for communication with the RF interface module, serving as communication
link between the web-server controller (master) and the slave controllers operating the
remotely controlled devices.

35
The main operation code comprises all the other code sections not included in the above
sections. Chiefly, the code in main.c, which comprises the initialization codes as well as
the infinite loop for the system. It also forms the request-response handling part of the http
server and utilizes modules from the TCP/IP stack section. The basic code flow of this
section (ie. main code) is illustrated in the flowchart below.

Initialization

HTTP No
request
received?

Yes

HTTP No
request Display Error Page
valid?

Yes

Is action No
requested? Send UART
message to RFM
module
Yes

Display Page

Is Yes
message Update local Status
received? Database
from RF?
36
No

Figure 7. 5: Flowchart showing implementation of TCP/IP stack


The Initialization Section comprises of initialization routines for i/o ports, timers, UART,
SPI, fatfs, and TCP/IP stack. After initialization, the infinite loop (main loop) consists of
performing the following actions:
1. Check if HTTP request is received (using functions to access TCP/IP stack)
2. If received, check for validity (ie. Request is supported by the server)
3. If not supported, send error page (“HTTP1.0/ 401 Unauthorized”)
4. If supported, check if action is being requested
5. If action requested (turning certain device on/off) send appropriate command to
RF interface through UART for broadcast into the wireless network
6. Display page containing current status of all available devices
7. Check for any message received from RF interface
8. If message available, change local status database to reflect status broadcast by
the device
9. Loop

Here, the RF interface connected through UART link acts as a bridge between the web-
server and the local RF network, relaying messages passed from UART to RF and vice
versa.

The slave devices periodically broadcast their status (including status of connected inputs
and outputs). The web-server controller listens to these messages and stores the latest
status information in its memory. When displaying the status page, the received status from
this memory is displayed.

The periodic status messages also inform the sever of the unavailability of any slave device
if message from the device is not received in a given time frame. The web-server then
displays the status accordingly when it serves the status page.

The received Status messages are also logged in the SD card, along with timestamp, to
serve as device log and usage history.

37
7.4.2 RF master on ATMEGA8
The code for the RF master lies in the ATMEGA8 controller on the RF interface module
connected to the web-server controller through UART. The main purpose of this module is
to act as link between the web-server controller (through UART) and the local RF network
(through RFM12/B modules). Appropriately, it consists of the following sections.
i. RFM 12/B driver
ii. UART
iii. Main control loop

The RFM12/B module is connected to the controller through SPI. The low-level driver
comprises of the SPI link and hardware register access (rfm12_spi.c, frm12_hw.h,
rfm12_core.h). The high level interface consists of packet generation, transmission and
reception. For the sake of reliable data transmission and reception, data is sent in packets
of fixed structure composed of
i. Prologue (0xAAAA)
ii. Sync Pattern (0x2DD4)
iii. Header (type, length, header checksum)
iv. ‘length’ bytes of data

Prologue and Sync Pattern are RFM12/B specific portions, necessary for synchronization
of internal clocks on the modules as well as confirmation of valid data reception. The
message header provides length for accurate reception and checksum for error detection.
Messages with checksum failure are ignored by the system.

The UART section comprises of code for handling UART (Serial Communication)
functions. It includes uart.h and uart.c. It is an interrupt based UART implementation with
circular buffers for both RX and TX. This implementation allows efficient and error free
usage of hardware UART with minimal delay and impact on the other code sections. The
UART is used for communication with the web-server controller.

38
The main section (main.c) of the code contains the initialization section and infinite loop
section as shown in the flowchart below.
The initialization section comprises of initialization codes for the i/o ports, UART and
RFM module.
The main loop cycles between 3 tasks as shown below.
As this module acts as message relay between the RF and UART, it listens for received
UART messages, and transmits them through RF.
It checks for received RF messages and transmits them through UART to the web-server
controller.
Finally, it calls the RFM service routines that handle the actual low-level transmission and
reception of queued RF data.

Initialization

Message No
received Send RFM message
from
UART?

Yes

Message No
received Send UART message
from RF?

Yes

Complete Queued
RF tasks

Figure 7. 6: Flowchart showing master communication with Atmega8


39
7.4.3 RF Slave and Switching Module Controller on ATMEGA8
The code for the RF slave and Switch controller lies in the ATMEGA8 microcontroller on
an RF interface module. The Hardware module is identical to the one used for the RF
master connected to the web-server microcontroller. In this case, the controller functions as
a standalone system, interfacing RFM12/B for RF communication with web-server
microcontroller and controls a switching module (composed of relays controlled via
Darlington array) through its GPIO pins.
It consists of the following sections
i. RFM12/B driver
ii. Main Control Loop
The RFM12/B module is connected to the controller through SPI. The low-level driver
comprises of the SPI link and hardware register access (rfm12_spi.c, frm12_hw.h,
rfm12_core.h). The high level interface consists of packet generation, transmission and
reception. For the sake of reliable data transmission and reception, data is sent in packets
of fixed structure composed of
iii. Prologue (0xAAAA)
iv. Sync Pattern (0x2DD4)
v. Header (type, length, header checksum)
vi. ‘length’ bytes of data

Prologue and Sync Pattern are RFM12/B specific portions, necessary for synchronization
of internal clocks on the modules as well as confirmation of valid data reception. The
message header provides length for accurate reception and checksum for error detection.
Messages with checksum failure are ignored by the system. The main control loop consists
of an initialization section and an infinite loop as shown below.

The initialization section comprises initialization routines for I/O ports, timers and
RFM12/B module and driver.

40
In each pass of the infinite loop, the following tasks are performed.

1. Check timer to see if 1 second has passed


2. If 1 second passed, send a status message through RF and reset timer for next 1
second countdown
3. Check for received RF messages
4. If message received and valid, set outputs (relay controls) accordingly
5. Call RFM service routines for queued low-level RFM tasks
6. Loop

Initialization

1 Second No
Timer Send Status message
Overflow?

Yes

Message No Set Outputs


received according to received
from RF? message

Yes

Complete Queued
RF tasks

Figure 7. 7: Flowchart showing RF slave communication with Atmega8

41
8. TESTING
During the hardware and software implementation, various kinds of testing were carried
out. The testing of the prototype module and the RF interface module were carried out
during this phase.

8.1 Testing of Prototype Module


The embedded web server module was built implementing the TCP/IP. The prototype
module was fabricated on a PCB design and was tested using the network from the router
and a light bulb was successfully controlled.

Figure 8. 1: Embedded web server prototype

42
8.2 Testing of RFM12 Module
We have used the RFM12 module in order to transmit the control signals between the
master and the slave controller units. The RFM working of the RFM12 module was tested
using the breadboard circuitry and later with Atmega328 interface.

Figure 8. 2: RFM Module testing in breadboard circuitry

Figure 8. 3: RFM Module testing with Atmega328 interface

43
9. PROJECT APPLICATION
Previously, it has been mentioned that this project is the outcome of the motivation in
implementing the Internet of Things (referred IoT hereafter). So, instead of just completion
of the Embedded Web Server, our project is more concerned about the implementing the
term IoT. In fact this project is implementation of the IoT. Building the embedded web
server is a part in achieving the implementation for IoT.

Implementation of the IoT can be achieved in two distinct ways.

a) Controlling the normal device by interfacing it with the embedded web server unit
b) Controlling the normal device after making it smart i.e. upgrading the normal
device with control ports and necessary parameters.

In our project, we have implemented the first ways more efficiently and also made a
provision for the second way. Thus, this project more applies in controlling the general
devices by interfacing it with the relay driver unit and ultimately to the embedded web
server unit.

This project successfully implements the IoT concept and is able to control the different
devices and appliances remotely via the internet. The devices to be controlled are linked
with the relay driver unit. The relay driver unit is further linked with the “slave controller
unit”. The slave controller unit consists of the RF module and the slave controller unit. The
slave controller unit communicates with the “master controller unit”. The master controller
unit consists of the embedded web server and the RF module. The control signal for
controlling the devices obtained through the internet is exchanged between the master and
slave controller units via RF communication. Thus the device is finally controlled via the
command from the slave controller that finally drives the relay connected to that device
and ultimately the device is controlled. Here control refers to the ON/OFF control of the
corresponding devices.

So, this project has vast applications according to the scenario to be used. The project finds
its application in controlling the things that utilizes the concept of IoT. We have restricted

44
our project just in home monitoring and control. But this project can be extensively used in
other areas as well. All other areas that require the internet based control come under the
application of this project.

This project solely finds its application any areas that implement the IoT. Naming few, the
applications of this project are listed below:

 Domestic and Home Automation: controlling of the home appliances and devices
(Smart Home)
 Industrial control: controlling the machineries in the industries
 Monitoring: checking the status of the controlled devices
 Smart lightning system in streets and public places
 Monitoring and optimization of performance in the solar plants
 Perimeter Access Control: Access control to restricted areas and detection of
people in non-authorized areas.
 Smart Agriculture, etc.

45
10. PROJECT ADVANTAGES
Home monitoring and control has been carried out and implemented in various ways over
past few years. Being the project relating to home monitoring and control, this project has
the following advantages:

Low Cost: The project implements the low cost AVR HTTP web server for home
monitoring and control purposes. The use of embedded server makes it cheaper in contrast
to other computer based monitoring and control systems.

Low Power: This is one of the power friendly projects. The total power consumption of the
system is less than 5 watts. The system can be run 24/7 with the help of inexpensive
battery backup system.

Platform Independent: The monitoring and control of the appliance can be controlled via
any internet enabled devices (regardless the platform, operating system they use) and
through any desktop or mobile internet browsers.

Suitable for varied locations: There is sound internet connectivity available in various part
of the Nepal, and since our web page is simple static one, the control and monitoring action
can be carried out through the GPRS/EDGE networks as well. So our project seems fit for
the varied locations throughout the country.

Time Saving: People nowadays are always in rush. So, with this project in hand people
now can monitor and control their home appliances at their convenient time when they are
at work, in vehicles, etc.

46
11. PROBLEMS FACED AND SOLUTIONS USED
 Memory: Previously we have used Atmega328 microcontroller for our project.
This controller has 32KB ROM and 2KB RAM. This proved insufficient for us in
storing the code for the embedded web server and the FAT system code. So, this
problem was solved using the bigger Atmega644 microcontroller. This controller
has double ROM and RAM specifications compared to the Atmega328.

 Fabrication: While implementing the project on hardware, we faced problem in


fabricating the components in PCB. This problem was solved taking assistance
from the seniors at the Robotics Club.

 Router: To test the working of our embedded web server, we used the local
network of the Router at the Robotics Club. There was problem with router and we
could not identify it. So, we used the router at our home to test the embedded web
server.

 RFM12 Communication Error: There was an issue with the reliability of the data
received from the RF module. The data received was found to be erroneous and
was a big problem to us. This problem was minimized implementing the checksum
and carrier sense methods.

47
11. RESULT
After implementing the above hardware the embedded web server worked fine. The
control information can be given via the static web page. The control information passed to
the slave controller unit via the master controller unit. The RF communication worked
satisfactorily. The device to be controlled was interfaced with the relay interfacing board.
The ON/OFF control of the device from the web page and its status monitoring from the
web page was successfully accomplished.

12. CONCLUSION AND FURTHER WORKS


12.1 Conclusion
The primary objective of this project was to develop a “home monitoring and control
system” implementing the embedded web server unit that could facilitate the current home
appliance control methods. The objective has been achieved with good and sound results.
We have been able to use our embedded web server over the local network to control the
appliance attached to it. The control information can be sent via the static web page to the
device to be controlled. The status of the controlled device can be seen on the same web
page.

12.2 Further Works


Though this project is complete and functional in itself, it has several directions for the
future research and further enhancements to be made. Some of the further works that can
be carried out in this project are discussed hereafter. This project has still got some areas of
refinement. The ZigBee module can be used instead of RFM12 for better wireless
communication. Likewise, the system can be powered by SMPS and battery backup system
making it suitable for working both in on and off power modes. Similarly the trend of
smart phones applications seem increasing these days, so a dedicated smart phone app can
be developed for the iOS and Android platform for this project. So, this will facilitate the
smart phone users for more interactive home monitoring and control. Likewise the overall
system design can be made more compact and attractive.

48
13. BIBLOGRAPHY
1) “Computer Networks” ; Tanenbaum, Andrew S.; 4th edition; Pearson Inc ; 2007
[book]
2) “Embedded Web Server” ; Lukosius, Arturas ; Vilnius Gediminas Technical
University; [bachelor level thesis]
3) “An Embedded Web Server-Based Remote Monitoring System” ; Hong, Tan Jin ;
Universiti Teknikal Malaysia Melaka [final year project report]
4) “Emebdded ATMEL HTTP Server” ; Tzeming Tan, Jeremy ; Cornell University ;
[final year project report]
5) “AVR microcontroller based embedded web server”; Mishra, Vishram ; Cochin
University of Science and Technology (School of Engineering) ; [final year project
report]
6) “Learning AVR” ; http://www.embedded-creations.com/projects/uipAVR.html ;
[online]
7) “An AVR microcontroller based Ethernet device” ;
http://tuxgraphics.org/electronics/200606/article06061.shtml ; [online]
8) “HTTP/TCP with an atmega88 microcontroller (AVR Web Server)” ;
http://tuxgraphics.org/electronics/200611/embedded-webserver.shtml ; [online]
9) “The Internet Protocol Suite” ;
http://www.starlancs.com/EducateMe/educate_IP_stack.html ; [online]
10) “Internet of Things”; http://en.wikipedia.org/wiki/Internet_of_Things [online article]
11) “RFM12 Library”; http://das-labor.org/wiki/RFM12_library/en [online]
12) “ATmega32 AVR based Web server using ENC28J60 Ethernet interface” ;
http://www.embeddedmarket.com/products/AVR-Embedded-Web-server/ [online]
13) “Embedded Atmel HTTP Web Server” ; Tzeming Tam, Jeremy ; Cornell University
http://people.ece.cornell.edu/land/courses/eceprojectsland/STUDENTPROJ/2003to2
004/tt82/ATMELwebserver.pdf [online (project report)]
14) “Interfacing RFM12 Transceiver Module” ; Peter Gracias; Texas A&M University ;
http://www.embedds.com/interfacing-rfm12-transceiver-module/ [online]

49
15) “Web Server In a Box” ; Grassi, Mauro ; Silicon Chip Magazine ; November 2009
[magazine]
16) “ENC28J60 Stand-alone Ethernet Controller With SPI ” ; Microchip Technology
Inc. ; 2004 [pdf (datasheet)]
17) “RFM12 Datasheet” ; Harris Semiconductor ; [pdf(datasheet)]
18) “AVR Atmega8 microcontroller Datasheet” ; Atmel Corporation ; [pdf(datasheet)]
19) “AVR Atmega328 microcontroller Datasheet” ; Atmel Corporation ;
[pdf(datasheet)]
20) “AVR Atmega644 microcontroller Datasheet” ; Atmel Corporation ;
[pdf(datasheet)]

50
APPENDIX A : Data Sheet Snaps
A.1 AVR Atmega8 Features
• High-performance, Low-power Atmel AVR 8-bit Microcontroller
• Advanced RISC Architecture
– 130 Powerful Instructions – Most Single-clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16MIPS Throughput at 16MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
– 8Kbytes of In-System Self-programmable Flash program memory
– 512Bytes EEPROM
– 1Kbyte Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits In-System Programming by On-chip
Boot Program
True Read-While-Write Operation
– Programming Lock for Software Security
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Three PWM Channels
– 8-channel ADC in TQFP and QFN/MLF package Eight Channels 10-bit Accuracy
– 6-channel ADC in PDIP package Six Channels 10-bit Accuracy
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
51
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
• Operating Voltages
– 2.7V - 5.5V (ATmega8L)
– 4.5V - 5.5V (ATmega8)
• Speed Grades
– 0 - 8MHz (ATmega8L)
– 0 - 16MHz (ATmega8)
• Power Consumption at 4 MHz, 3V, 25°C
– Active: 3.6mA
– Idle Mode: 1.0mA
–Power-down Mode: 0.5µA

Figure A. 1: AVR Atmega8 pin diagram

52
A.2 AVR Atmega328 features
• High Performance, Low Power Atmel AVR 8-Bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single Clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory Segments
– 4/8/16/32KBytes of In-System Self-Programmable Flash program memory
– 256/512/512/1KBytes EEPROM
– 512/1K/1K/2KBytes Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits In-System Programming by On-chip
Boot Program True Read-While-Write Operation
– Programming Lock for Software Security
• Atmel QTouch library support
– Capacitive touch buttons, sliders and wheels
– QTouch and QMatrix acquisition
– Up to 64 sense channels
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel 10-bit ADC in TQFP and QFN/MLF package Temperature Measurement
– 6-channel 10-bit ADC in PDIP Package Temperature Measurement
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Byte-oriented 2-wire Serial Interface (Philips I 2 C compatible)
– Programmable Watchdog Timer with Separate On-chip Oscillator
53
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby,and Extended
Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
• Operating Voltage:
– 1.8 - 5.5V
• Temperature Range:
–-40
°C to 85°C
• Speed Grade:
– 0 - 4MHz@1.8 - 5.5V, 0 - 10MHz@2.7 - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V
• Power Consumption at 1MHz, 1.8V, 25°C
– Active Mode: 0.2mA
– Power-down Mode: 0.1µA
– Power-save Mode: 0.75µA (Including 32 KHz RTC)

Figure A. 2: AVR Atmega328 pin diagram


54
A.3 AVR Atmega644 features
• High-performance, Low-power Atmel AVR 8-bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single-clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20MHz
• High Endurance Non-volatile Memory segments
– 64 Kbytes of In-System Self-programmable Flash program memory
– 2 Kbytes EEPROM
– 4 Kbytes Internal SRAM
– Write/Erase cyles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits In-System Programming by On-
chip Boot Program True Read-While-Write Operation
– Programming Lock for Software Security
• JTAG (IEEE std. 1149.1 Compliant) Interface
– Boundary-scan Capabilities According to the JTAG Standard
– Extensive On-chip Debug Support
– Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel, 10-bit ADC Differential mode with selectable gain at 1x, 10x or 200x
– Byte-oriented Two-wire Serial Interface
– One Programmable Serial USART
– Master/Slave SPI Serial Interface

55
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and
Extended Standby
• I/O and Packages
– 32 Programmable I/O Lines
– 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF
• Speed Grades
– ATmega644V: 0 - 4MHz @ 1.8V - 5.5V, 0 - 10MHz @ 2.7V - 5.5V
– ATmega644: 0 - 10MHz @ 2.7V - 5.5V, 0 - 20MHz @ 4.5V - 5.5V
• Power Consumption at 1MHz, 3V, 25·C
– Active: 240µA @ 1.8V, 1MHz
– Power-down Mode: 0.1µA @ 1.8V

56

Figure A. 3: AVR Atmega644 pin diagram


A.4 ENC28J60 Ethernet Controller Features
Ethernet Controller Features
• IEEE 802.3 compatible Ethernet controller
• Integrated MAC and 10BASE-T PHY
• Receiver and collision squelch circuit
• Supports one 10BASE-T port with automatic
polarity detection and correction
• Supports Full and Half-Duplex modes
• Programmable automatic retransmit on collision
• Programmable padding and CRC generation
• Programmable automatic rejection of erroneous packets
• SPI™ Interface with speeds up to 10 Mb/s

Buffer
• 8-Kbyte transmit/receive packet dual port SRAM
• Configurable transmit/receive buffer size
• Hardware-managed circular receive FIFO
• Byte-wide random and sequential access with auto-increment
• Internal DMA for fast data movement
• Hardware assisted IP checksum calculation

Medium Access Controller (MAC) Features


• Supports Unicast, Multicast and Broadcast packets
• Programmable receive packet filtering and wake-up host on logical AND or OR of the
following:
- Unicast destination address
- Multicast address
- Broadcast address
- Magic Packet™
- Group destination addresses as defined by

57
64-bit hash table
- Programmable pattern matching of up to
64 bytes at user-defined offset
• Loopback mode

Physical Layer (PHY) Features


• Wave shaping output filter
• Loopback mode

Figure A. 4: ENC28J60 Ethernet Controller pin diagrams

58
A.5 RFM12 Module Features
• Fully integrated (low BOM, easy design-in)
• No alignment required in production
• Fast-settling, programmable, high-resolution PLL synthesizer
• Fast frequency-hopping capability
• High bit rate (up to 115.2 kbps in digital mode and 256 kbps in analog mode)
• Direct differential antenna input/output
• Integrated power amplifier
• Programmable TX frequency deviation (15 to 240 KHz)
• Programmable RX baseband bandwidth (67 to 400 kHz)
• Analog and digital RSSI outputs
• Automatic frequency control (AFC)
• Data quality detection (DQD)
• Internal data filtering and clock recovery
• RX synchron pattern recognition
• SPI compatible serial control interface
• Clock and reset signals for microcontroller
• 16 bit RX Data FIFO
• Two 8 bit TX data registers
• Low power duty cycle mode
• Standard 10 MHz crystal reference
• Wake-up timer
• 2.2 to 5.4 V supply voltage
• Low power consumption
• Low standby current (0.3 µA)
• Compact 16 pin TSSOP package

59
APPENDIX B : SCHEMATICS

60
Figure B. 1: AVR Atmega328 interface schematics
Figure B. 2: AVR Atmega8 interface schematics
61
Figure B.3: AVR Atmega644 interface schematics
62
APPENDIX C : PCB LAYOUTS

Figure C. 1: PCB layout of RFM12 module with Atmega8 controller

Figure C. 2: PCB Layout of Atmega328 interface

63
Figure C. 3: PCB layout of Atmega644 interface for embedded web server

Figure C. 4: PCB layout of Switching Module

64
APPENDIX D : PROJECT SNAPSHOTS

Figure D. 1: Atmega644 interface for embedded web server

Figure D. 2: Complete Embedded web server unit

65
Figure D. 3: Relay Interface Module with RFM12 (slave) and Atmega8 (slave)

66
APPENDIX E : PROJECT COST

SN Details Price

1 Relays 250

2 Atmega328 550

3 Miscellaneous 1000

4 Atmega8 (x3) 1050

5 Fabrication 1500

6 ENC28J60 1800

7 Atmega 644 1800

8 PCB Copper Board 2000

9 Router 2500

10 Stationery Cost 4500

Total NRs. 18,950

Table E. 1: Project Cost

67

También podría gustarte