Sei sulla pagina 1di 63

CHAPTER 1

INTRODUCTION

Home automation or smart home (also known as domotics) is building automation for
the
home. It involves the control and automation of lighting, heating (such as smart
thermostats),
ventilation, air conditioning (HVAC), and security, as well as home appliances such
as
washer/dryers, ovens or refrigerators/freezers. Wi-Fi is often used for remote
monitoring and
control. Home devices, when remotely monitored and controlled via the Internet, are
an
important constituent of the Internet of Things. Modern systems generally consist
of switches
and sensors connected to a central hub sometimes called a "gateway" from which the
system is
controlled with a user interface that is interacted either with a wall-mounted
terminal, mobile
phone software, tablet computer or a web interface, often but not always via
Internet cloud
services.

While there are many competing vendors, there are very few worldwide accepted
industry
standards and the smart home space is heavily fragmented. Popular communications
protocol for products include X10, Ethernet, RS-485, 6LoWPAN, Bluetooth
LE
(BLE), ZigBee and Z-Wave, or other proprietary protocols all of which are
incompatible with
each other. Manufacturers often prevent independent implementations by withholding
documentation and by litigation.

The home automation market was worth US$5.77 billion in 2015, predicted to have a
market
value over US$10 billion by the year 2020.

The main purpose of our project is to ease the work at home and the other aim of
our project is
to save the energy also so basically we named our project as ADVANCE
HOME
AUTOMATION we are calling it advance just because in this project we are using
DIGITAL
IMAGE PROCESSING technique to control the fan of the house and also we are
interfacing
aurduino with the MATLAB.

1
CHAPTER 2

PROJECT OVERVIEW

2.1 Objectives

The main purpose of our project is to ease the work at home and the other aim of
our project is
to save the energy also so basically we named our project as ADVANCE
HOME
AUTOMATION we are calling it advance just because in this project we are using
DIGITAL
IMAGE PROCESSING technique to control the fan of the house and also we are
interfacing
arduino with the MATLAB.

2.2 Requirement

2.2.1 Arduino Uno Board

2.2.2 Mq5 Gas Sensor

2.2.3 L293d Motor Driver IC

2.2.4 7805 Regulator IC

2.2.5 CD Loader

2.2.6 Ldr

2.2.7 DC Motor

2.2.8 Led

2.2.9 Laser Torch

2
2.3 Block Diagram

Figure 2.1 Block diagram of home automation

3
CHAPTER 3

HARDWARE DESCRIPTION

3.1 Arduino Uno Board

Arduino is an open-source electronics platform based on easy-to-use hardware and


software. Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a
Twitter message - and turn it into an output - activating a motor, turning on an
LED,
publishing something online. You can tell your board what to do by sending a set of
instructions to the microcontroller on the board. To do so you use the Arduino
programming
language (based on Wiring), and the Arduino Software (IDE), based on Processing.

Over the years Arduino has been the brain of thousands of projects, from everyday
objects to
complex scientific instruments. A worldwide community of makers - students,
hobbyists,
artists, programmers, and professionals - has gathered around this open-source
platform, their
contributions have added up to an incredible amount of accessible knowledge that
can be of
great help to novices and experts alike.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast
prototyping,
aimed at students without a background in electronics and programming. As soon as
it reached
a wider community, the Arduino board started changing to adapt to new needs and
challenges,
differentiating its offer from simple 8-bit boards to products for IoT
applications, wearable, 3D
printing, and embedded environments. All Arduino boards are completely open-source,
empowering users to build them independently and eventually adapt them to their
particular
needs. The software, too, is open-source, and it is growing through the
contributions of users
worldwide.

4
3.2 MQ-5 Gas Sensor

The Grove - Gas Sensor (MQ5) module is useful for gas leakage detection (in home
and
industry). It is suitable for detecting H2, LPG, CH4, CO, Alcohol. Due to its high
sensitivity
and fast response time, measurements can be taken as soon as possible. The
sensitivity of the
sensor can be adjusted by using the potentiometer.

When a gas interacts with this sensor, it is first ionized into its constituents
and is then
adsorbed by the sensing element. This adsorption creates a potential difference on
the element
which is conveyed to the processor unit through output pins in form of current.The
gas sensor
module consists of a steel exoskeleton under which a sensing element is housed.
This sensing
element is subjected to current through connecting leads. This current is known as
heating
current through it, the gases coming close to the sensing element get ionized and
are absorbed
by the sensing element. This changes the resistance of the sensing element which
alters the
value of the current going out of it.

5
FIG 3.1 GAS SENSOR

3.2.1. Operating Principle

MQ-5 gas sensor applies SnO2 which has a lower conductivity in the clear air as
a gas-sensing material. In an atmosphere where there may be inflammable gases,
the conductivity of the gas sensor raises along with the inflammable gas
concentration increases. MQ-5 plays a high performance in detecting butane,
propane and methane, and can identify both propane and methane at a same time.
MQ-5 is highly sensitive to natural gas. It features with the ability to detect
various inflammable gases and lower cost, making it an ideal choice of different
applications of gas detection.

Table 3.1 Gas sensor stats

6
3.3.2. Application

This module can be applied to liquefied gas, natural gas and/or coal gas monitoring
devices for
household or industrial usage

3.3.3 Features

 Stable and long life

 Fast response and High sensitivity

 Wide detecting scope

7
Figure 3.2 Concentration of gas

3.3 L293d Motor Driver IC

L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive
on either
direction. L293D is a 16-pin IC which can control a set of two DC motors
simultaneously in
any direction. It means that you can control two DC motor with a single L293D IC.
Dual H-
bridge Motor Driver integrated circuit

The l293d can drive small and quiet big motors as well It works on the concept of
H-bridge.
H-bridge is a circuit which allows the voltage to be flown in either direction. As
you know
voltage need to change its direction for being able to rotate the motor in
clockwise or
anticlockwise direction, Hence H-bridge IC are ideal for driving a DC motor.

In a single L293D chip there are two h-Bridge circuit inside the IC which can
rotate two dc
motor independently. Due its size it is very much used in robotic application for
controlling
DC motors.

8
There are two Enable pins on l293d. Pin 1 and pin 9, for being able to drive the
motor, the pin
1 and 9 need to be high. For driving the motor with left H-bridge you need to
enable pin 1 to
high. And for right H-Bridge you need to make the pin 9 to high. If anyone of the
either pin1
or pin9 goes low then the motor in the corresponding section will suspend working.
It’s like a
switch.

3.3.1 Pin Configration

9
Figure 3.3 Pin diagram of L293D

3.4 7805 Regulator IC

A voltage regulator is designed to automatically maintain a constant voltage level.


A voltage
regulator may be a simple "feed-forward" design or may include negative feedback
control
loops. It may use an electromechanical mechanism, or electronic components.
Depending on
the design, it may be used to regulate one or more AC or DC voltages.

A simple voltage/current regulator can be made from a resistor in series with a


diode (or series
of diodes). Due to the logarithmic shape of diode V-I curves, the voltage across
the diode
changes only slightly due to changes in current drawn or changes in the input. When
precise
voltage control and efficiency are not important, this design may be fine.

Feedback voltage regulators operate by comparing the actual output voltage to some
fixed
reference voltage. Any difference is amplified and used to control the regulation
element in
such a way as to reduce the voltage error. This forms a negative feedback control
loop;
increasing the open-loop gain tends to increase regulation accuracy but reduce
stability.

10
(Stability is avoidance of oscillation, or ringing, during step changes.) There
will also be a
trade-off between stability and the speed of the response to changes. If the output
voltage is
too low (perhaps due to input voltage reducing or load current increasing), the
regulation
element is commanded, up to a point, to produce a higher output voltage–by dropping
less of
the input voltage (for linear series regulators and buck switching regulators), or
to draw input
current for longer periods (boost-type switching regulators); if the output voltage
is too high,
the regulation element will normally be commanded to produce a lower voltage.
However,
many regulators have over-current protection, so that they will entirely stop
sourcing current.

(or limit the current in some way) if the output current is too high, and some
regulators may
also shut down if the input voltage is outside a given range (see also: crowbar
circuits).

3.5 Ldr(Light Dependent Resistor)

A Light Dependent Resistor or a photo resistor is a device whose resistivity is a


function of the
incident electromagnetic radiation. Hence, they are light sensitive devices. They
are also called
as photo conductors, photo conductive cells or simply photocells. They are made up
of
semiconductor materials having high resistance.

A light dependent resistor works on the principle of photo conductivity.Photo


conductivity is
an optical phenomenon in which the materials conductivity is increased when light
is absorbed
by the material. When light falls i.e. when the photons fall on the device, the
electrons in the
valence band of the semiconductor material are excited to the conduction band.
These photons
in the incident light should have energy greater than the band gap of the
semiconductor
material to make the electrons jump from the valence band to the conduction band.
Hence
when light having enough energy strikes on the device, more and more electrons are
excited to
the conduction band which results in large number of charge carriers. The result of
this process
is more and more current starts flowing throgh the device when the circuit is
closed and hence
it is said that the resistance of the device has been decreased. This is the most
common
working principle of LDR.
11
Figure 3.4 Light detecting resistor

A Light Dependent Resistor or a photo resistor is a device whose resistivity is a


function of the
incident electromagnetic radiation. Hence, they are light sensitive devices. They
are also called
as photo conductors, photo conductive cells or simply photocells. They are made up
of
semiconductor materials having high resistance.

3.5.1 Working Principle of LDR

A light dependent resistor works on the principle of photo conductivity.Photo


conductivity is
an optical phenomenon in which the materials conductivity is increased when light
is absorbed
by the material. When light falls i.e. when the photons fall on the device, the
electrons in the
valence band of the semiconductor material are excited to the conduction band.
These photons
in the incident light should have energy greater than the band gap of the
semiconductor
material to make the electrons jump from the valence band to the conduction band.
Hence
when light having enough energy strikes on the device, more and more electrons are
excited to
the conduction band which results in large number of charge carriers. The result of
this process
is more and more current starts flowing throgh the device when the circuit is
closed and hence
it is said that the resistance of the device has been decreased.

12
Figure 3.5 Variation in resistance with changing light
intensity

3.5.2 Characterstics Of LDR

LDR’s are light dependent devices whose resistance is decreased when light falls on
them and
that is increased in the dark. When a light dependent resistor is kept in dark, its
resistance is
very high. This resistance is called as dark resistance. It can be as high as 10 12
Ω and if the
device is allowed to absorb light its resistance will be decreased drastically. If
a constant
voltage is applied to it and intensity of light is increased the current starts
increasing. Figure
below shows resistance vs. illumination curve for a particular LDR.

13
Figure 3.6 Resistance illumination graph

Photocells or LDR’s are nonlinear devices. There sensitivity varies with the
wavelength of
light incident on them. Some photocells might not at all response to a certain
range of
wavelengths. Based on the material used different cells have different spectral
response
curves.

When light is incident on a photocell it usually takes about 8 to 12 ms for the


change in
resistance to take place, while it takes one or more seconds for the resistance to
rise back again
to its initial value after removal of light. This phenomenon is called as
resistance recovery rate.
This property is used in audio compressors. Also, LDR’s are less sensitive than
photo diodes
and photo transistor. (A photo diode and a photocell (LDR) are not the same, a
photo-diode is
a p-n junction semiconductor device that converts light to electricity, whereas a
photocell is a
passive device, there is no p-n junction in this nor it “converts” light to
electricity). Types of
Light Dependent Resistors: Based on the materials used they are classified as:

1. Intrinsic photo resistors (Un doped semiconductor): These are made of pure
semiconductor materials such as silicon or germanium. Electrons get excited
from
valance band to conduction band when photons of enough energy fall on it
and number
charge carriers is increased.

14
2. Extrinsic photo resistors (doped semiconductor): These are semiconductor
materials
doped with impurities which are called as dopants. Theses dopants create
new energy
bands above the valence band which are filled with electrons. Hence this
reduces the
band gap and less energy is required in exciting them. Extrinsic photo
resistors are
generally used for long wavelengths.

3.5.3 Construction of a Photocell

The structure of a light dependent resistor consists of a light sensitive material


which is
deposited on an insulating substrate such as ceramic. The material is deposited in
zigzag
pattern in order to obtain the desired resistance and power rating. This zigzag
area separates
the metal deposited areas into two regions. Then the ohmic contacts are made on the
either
sides of the area. The resistances of these contacts should be as less as possible
to make sure
that the resistance mainly changes due to the effect of light only. Materials
normally used are
cadmium sulphide, cadmium selenide, indium antimonide and cadmium sulphonide. The
use
of lead and cadmium is avoided as they are harmful to the environment.

Figure 3.7 Cross sectional view of LDR

15
3.5.4 Applications Of LDR

There are many applications for Light Dependent Resistors. These include:

Cost: LDR’s have low cost and simple structure. They are often used as light
sensors. They
are used when there is a need to detect absences or presences of light like
in a camera
light

Lighting switch: The most obvious application for an LDR is to automatically turn
on a light
at a certain light level. An example of this could be a street light or a
garden light.

Camera shutter control: LDRs can be used to control the shutter speed on a camera.
The
LDR would be used to measure the light intensity which then adjusts the
camera
shutter speed to the appropriate level meter. Used in street lamps, alarm
clock,
burglar alarm circuits, light intensity meters, for counting the packages
moving on a
conveyor belt, etc.

3.6 DC Motor

A DC motor is any of a class of rotary electrical machines that converts direct


current
electrical energy into mechanical energy. The most common types rely on the forces
produced
by magnetic fields. Nearly all types of DC motors have some internal mechanism,
either
electromechanical or electronic, to periodically change the direction of current
flow in part of
the motor.

DC motors were the first type widely used, since they could be powered from
existing direct-
current lighting power distribution systems. A DC motor's speed can be
controlled over a
wide range, using either a variable supply voltage or by changing the
strength of current
in its field windings. Small DC motors are used in tools, toys, and
appliances. The
universal motor can operate on direct current but is a lightweight motor used
for portable
power tools and appliances. Larger DC motors are used in propulsion of
electric
vehicles, elevator and hoists, or in drives for

steel rolling mills. The advent of power electronics has made replacement of DC
motors with
AC motors possible in many applications.
16
3.7 LED

A light-emitting diode (LED) is a two-lead semiconductor light source. It is a p–n


junction
diode, which emits light when activatedWhen a suitable voltage is applied to the
leads,
electrons are able to recombine with electron holes within the device, releasing
energy in the
form of photons. This effect is called electroluminescence, and the color of the
light
(corresponding to the energy of the photon) is determined by the energy band gap of
the
semiconductor. LEDs are typically small (less than 1 mm2 ) and integrated optical
components
may be used to shape the radiation pattern.

Appearing as practical electronic components in 1962the earliest LEDs emitted low-


intensity
infrared light. Infrared LEDs are still frequently used as transmitting elements in
remote-
control circuits, such as those in remote controls for a wide variety of consumer
electronics.
The first visible-light LEDs were also of low intensity and limited to red. Modern
LEDs are
available across the visible, ultraviolet, and infrared wavelengths, with very high
brightness.

Early LEDs were often used as indicator lamps for electronic devices, replacing
small
incandescent bulbs. They were soon packaged into numeric readouts in the form of
seven-
segment displays and were commonly seen in digital clocks. Recent developments in
LEDs
permit them to be used in environmental and task lighting. LEDs have allowed new
displays
and sensors to be developed, while their high switching rates are also used in
advanced
communications technology.

LEDs have many advantages over incandescent light sources including lower energy
consumption, longer lifetime, improved physical robustness, smaller size, and
faster switching.
Light-emitting diodes are now used in applications as diverse as aviation lighting,
automotive
headlamps, advertising, general lighting, traffic signals, camera flashes, and
lighted wallpaper.
As of 2017, LED lights home room lighting are as cheap or cheaper than compact
fluorescent

17
lamp sources of comparable outputThey are also significantly more energy efficient
and,
arguably, have fewer environmental concerns linked to their disposal.

3.8 LASER

A laser is a device that emits light through a process of optical amplification


based on the
stimulated emission of electromagnetic radiation. The term "laser" originated as an
acronym
for "light amplification by stimulated emission of radiation".The first laser was
built in 1960
by Theodore H. Maiman at Hughes Research Laboratories, based on theoretical work by
Charles Hard Townes and Arthur Leonard Schawlow. A laser differs from other sources
of
light in that it emits light coherently. Spatial coherence allows a laser to be
focused to a tight
spot, enabling applications such as laser cutting and lithography. Spatial
coherence also allows
a laser beam to stay narrow over great distances (collimation), enabling
applications such as
laser pointers. Lasers can also have high temporal coherence, which allows them to
emit light
with a very narrow spectrum, i.e., they can emit a single color of light. Temporal
coherence
can be used to produce pulses of light as short as a femtosecond.

Among their many applications, lasers are used in optical disk drives, laser
printers, and
barcode scanners; DNA sequencing instruments, fiber-optic and free-space optical
communication; laser surgery and skin treatments; cutting and welding materials;
military and
law enforcement devices for marking targets and measuring range and speed; and
laser
lighting displays in entertainment.

18
CHAPTER 4

ATMEGA 328P MICROCONTROLLER

(ARDUINO BASED)

4.1 Introduction to Arduino

Arduino is an open-source electronics platform based on easy-to-use hardware and


software.
It's intended for anyone making interactive projects. Over the years Arduino has
been the brain
of thousands of projects, from everyday objects to complex scientific instruments.
A
worldwide community of makers - students, hobbyists, artists, programmers, and
professionals
- has gathered around this open-source platform, their contributions have added up
to an
incredible amount of accessible knowledge that can be of great help to novices and
experts
alike.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast
prototyping,
aimed at students without a background in electronics and programming. As soon as
it reached
a wider community, the Arduino board started changing to adapt to new needs and
challenges,
differentiating its offer from simple 8-bit boards to products for IoT
applications, wearable, 3D
printing, and embedded environments. All Arduino boards are completely open-source,

19
empowering users to build them independently and eventually adapt them to their
particular
needs.

4.2 Why Arduino?

The Arduino software is easy-to-use for beginners, yet flexible enough for advanced
users. It
runs on Mac, Windows, and Linux. Teachers and students use it to build low cost
scientific
instruments, to prove chemistry and physics principles, or to get started with
programming and
robotics. Designers and architects build interactive prototypes, musicians and
artists use it for
installations and to experiment with new musical instruments.

20
There are many other microcontrollers and microcontroller platforms available for
physical
computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and
many
others offer similar functionality. All of these tools take the messy details of
microcontroller
programming and wrap it up in an easy-to-use package. Arduino also simplifies the
process of
working with microcontrollers, but it offers some advantage for teachers, students,
and
interested amateurs over other systems:

1. Inexpensive - Arduino boards are relatively inexpensive compared to other


microcontroller platforms. The least expensive version of the Arduino
module can be
assembled by hand, and even the pre-assembled Arduino modules at cheaper
rates.

2. Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX,


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

3. Simple, clear programming environment - The Arduino Software (IDE) is easy-


to-
use for beginners, yet flexible enough for advanced users to take advantage
of as well.
For teachers, it's conveniently based on the Processing programming
environment, so
students learning to program in that environment will be familiar with how
the Arduino
IDE works.

4. Open source and extensible software - The Arduino software is published as


open
source tools, available for extension by experienced programmers. The
language can
be expanded through C++ libraries, and people wanting to understand the
technical
details can make the leap from Arduino to the AVR C programming language on
which
it's based. Similarly, you can add AVR-C code directly into your Arduino
programs if
you want to.

5. Open source and extensible hardware - The plans of the Arduino boards are
published under a Creative Commons license, so experienced circuit
designers can
make their own version of the module, extending it and improving it.

21
4.3 Arduino Uno board

The Uno is a microcontroller board based on the ATmega328P. It has 14 digital


input/output
pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz
crystal, a
USB connection, a power jack, an ICSP header and a reset button. It contains
everything
needed to support the microcontroller; simply connect it to a computer with a USB
cable or
power it with a AC-to-DC adapter or battery to get started.. You can tinker with
your UNO
without worrying too much about doing something wrong, worst case scenario you can
replace
the chip for a few dollars and start over again.

"Uno" means one in Italian and was chosen to mark the release of Arduino Software
(IDE) 1.0.
The Uno board and version 1.0 of Arduino Software (IDE) were the reference versions
of
Arduino, now evolved to newer releases. The Uno board is the first in a series of
USB Arduino
boards, and the reference model for the Arduino platform; for an extensive list of
current, past
or outdated boards see the Arduino index of boards.

Figure 4.1 An Arduino Uno Board


Table 4.1 Specifications of arduino uno
Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-12V
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6

22
Analog Input Pins 6
DC Current per I/O Pin 20mA
DC Current for 3.3V Pin 50Ma

32 KB (ATmega328P)
Flash Memory of which 0.5 KB used by bootloader

SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
Length 68.6 mm
Width 53.4 mm

Weight 25 g

4.4 Atmega 328P Microcontroller

Circumstances that we find ourselves in today in the field of microcontrollers had


their
beginnings in the development of technology of integrated circuits. This
development has
made it possible to store hundreds of thousands of transistors into one chip. That
was a
prerequisite for production of microprocessors, and the first computers were made
by adding
external peripherals such as memory, input-output lines, timers and other. Further
increasing of
the volume of the package resulted in creation of integrated circuits. These
integrated circuits
contained both processor and peripherals. That is how the first chip containing a
microcomputer, or what would later be known as a microcontroller came about.

Microprocessors and microcontrollers are widely used in embedded systems products.


Microcontroller is a programmable device. A microcontroller has a CPU in addition
to a fixed
amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed
amount
of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal
for
many applications in which cost and space are critical.

4.4.1 Features

 Advanced RISC Architecture

23
 Up to 16 MIPS Throughput at 16 MHz

 16K Bytes of In-System Self-Programmable Flash

 512 Bytes EEPROM

 1K Byte Internal SRAM

 32 Programmable I/O Lines

 In-System Programming by On-chip Boot Program

 8-channel, 10-bit ADC

 Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes

 One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and


Capture

 Four PWM Channels

 Programmable Serial USART

 Master/Slave SPI Serial Interface

 Byte-oriented Two-wire Serial Interface

 Programmable Watchdog Timer with Separate On-chip Oscillator

 External and Internal Interrupt Sources

The AVR core combines a rich instruction set with 32 general purpose working
registers.
All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),
allowing two
independent registers to be accessed in one single instruction executed in one
clock cycle. The
resulting architecture is more code efficient while achieving throughputs up to ten
times faster
than conventional.

4.4.2 CISC microcontrollers

The ATmega328 provides the following features: 16 Kbytes of In-System Programmable


Flash
Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1 Kbyte SRAM,

24
32 general purpose I/O lines, 32 general purpose working registers, a JTAG
interface for
Boundary scan, On-chip Debugging support and programming, three flexible
Timer/Counters
with compare modes, Internal and External Interrupts, a serial programmable USART,
a byte
oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional
differential input
stage with programmable gain (TQFP package only), a programmable Watchdog Timer
with
Internal Oscillator, an SPI serial port, and six software selectable power saving
modes. The
Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D
Converter,
SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The
Power-
down mode saves the register contents but freezes the Oscillator, disabling all
other chip
functions until the next External Interrupt or Hardware Reset. In Power-save mode,
the
Asynchronous Timer continues to run, allowing the user to maintain a timer base
while the rest
of the device is sleeping.

The ADC Noise Reduction mode stops the CPU and all I/O modules except
Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In
Standby mode, the crystal/resonator Oscillator is running while the rest of the
device is
sleeping. This allows very fast start-up combined with low-power consumption. In
Extended
Standby mode, both the main Oscillator and the Asynchronous Timer continue to run.

The device is manufactured using Atmel’s high density nonvolatile memory


technology. The On chip ISP Flash allows the program memory to be reprogrammed in-
system
through an SPI serial interface, by a conventional nonvolatile memory programmer,
or by an
On-chip Boot program running on the AVR core. The boot program can use any
interface to
download the application program in the Application Flash memory. Software in the
Boot
Flash section will continue to run while the Application Flash section is updated,
providing
true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System
Self-
Programmable Flash on a monolithic chip, the Atmel ATmega16 is a powerful
microcontroller
that provides a highly-flexible and cost-effective solution to many embedded
control
applications.

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
25
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.

4.4.3 Pin Configuration

Figure 4.2 Pin Configuration of ATMEGA 328


4.4.4 Pin Descriptions
 VCC: Digital supply voltage. (+5V)

 GND: Ground. (0 V) Note there are 2 ground Pins.

 Port A (PA7 - PA0): Port A serves as the analog inputs to the A/D
Converter. Port A
also serves as an 8-bit bi-directional I/O port, if the A/D Converter is
not used. When
pins PA0 to PA7 are used as inputs and are externally pulled low, they
will source

26
current if the internal pull-up resistors are activated. The Port A pins
are tri-stated when
a reset condition becomes active, even if the clock is not running.

 Port B (PB7 - PB0): Port B is an 8-bit bi-directional I/O port with


internal pull-up
resistors (selected for each bit). Port B also serves the functions of
various special
features of the ATmega16 as listed on page 58 of datasheet.

 Port C (PC7 - PC0): Port C is an 8-bit bi-directional I/O port with


internal pull-up
resistors (selected for each bit). Port C also serves the functions of the
JTAG interface
and other special features of the ATmega16 as listed on page 61 of
datasheet. If the
JTAG interface is enabled, the pull-up resistors on pins PC5 (TDI), PC3
(TMS) and
PC2 (TCK) will be activated even if a reset occurs.

 Port D (PD7 - PD0): Port D is an 8-bit bi-directional I/O port with


internal pull-up
resistors (selected for each bit). Port D also serves the functions of
various special
features of the ATmega16 as listed on page 63 of datasheet.

 RESET: Reset Input. A low level on this pin for longer than the minimum
pulse
length will generate a reset, even if the clock is not running.

 XTAL1: External oscillator pin 1

 XTAL2: External oscillator pin 2

 AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It
should be
externally connected to VCC, even if the ADC is not used. If the ADC is
used, it
should be connected to VCC through a low-pass filter.

 AREF: AREF is the analog reference pin for the A/D Converter.

27
4.4.5 Digital Input Output Port

Atmega16 has 32 I/O (Input/Output) pins grouped as A, B, C & D with 8 pins in


each
group. This group is called as PORT.
 PA0 - PA7 (PORTA)

 PB0 - PB7 (PORTB)

 PC0 - PC7 (PORTC)

 PD0 - PD7 (PORTD)

These are additional function that pin can perform other than I/O. Some of them are
 ADC (ADC0 - ADC7 on PORTA)

 UART (Rx,Tx on PORTD)

 TIMERS (OC0 - OC2)

 SPI (MISO, MOSI, SCK on PORTB)

 External Interrupts (INT0 - INT2)

28
4.4.6 Block Diagram

Figure 4.3 Block Diagram of atmega328P

29
The AVR core combines a rich instruction set with 32 general purpose working
registers.
All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),
allowing
two independent registers to be accessed in one single instruction executed in one
clock
cycle. The resulting architecture is more code efficient while achieving
throughputs up to
ten times faster than conventional CISC microcontrollers. The ATmega328/P provides
the
following features: 4K/8Kbytes of In-System Programmable Flash with Read-While-
Write
capabilities,1Kbytes EEPROM, 2Kbytes SRAM, 23 general purpose I/O lines, 32 general
purpose working registers, three flexible Timer/Counters with compare modes,
internal and
external interrupts, a serial programmable USART, a byte-oriented 2-wire Serial
Interface,
an SPI serial port, a 6 channel 10-bit ADC (8 channels in TQFP and QFN/MLF
packages),
a programmable Watchdog Timer with internal Oscillator, and five software
selectable
power saving modes. The Idle mode stops the CPU while allowing the SRAM,
Timer/Counters, USART, 2-wire Serial Interface, SPI port, and interrupt system to
continue
functioning. The Power-down mode saves the register contents but freezes the
Oscillator,
disabling all other chip functions until the next interrupt or hardware reset. In
Power-save
mode, the asynchronous timer continues to run, allowing the user to maintain a
timer base
while the rest of the device is sleeping. The ADC Noise Reduction mode stops the
CPU
and all I/O modules except asynchronous timer and ADC, to minimize switching noise
during ADC conversions. In Standby mode, the crystal/resonator Oscillator is
running
while the rest of the device is sleeping. This allows very fast start-up combined
with low
power consumption. Atmel offers the QTouch library for embedding capacitive touch
buttons, sliders and wheels functionality into AVR microcontrollers. The patented
charge-
transfer signal acquisition offers robust sensing and includes fully debounced
reporting of
touch keys and includes Adjacent Key
4.5 AVR CPU CORE
The main function of the CPU core is to ensure correct program execution.
The
CPU must therefore be able to access memories, perform calculations, control
peripherals,
and handle interrupts.

30
Figure 4.4 Architecture of AVR CPU Core

In order to maximize performance and parallelism, the AVR uses a Harvard


architecture -with separate memories and buses for program and data. Instructions
in the
program memory are executed with a single level pipelining. While one instruction
is being
executed, the next instruction is pre-fetched from the program memory. This concept
enables instructions to be executed in every clock cycle. The program memory is In-
System Reprogrammable Flash memory.
The fast-access Register File contains 32 × 8-bit general purpose working
registers
with a single clock cycle access time. This allows single-cycle Arithmetic Logic
Unit
(ALU) operation. In a typical ALU operation, two operands are output from the
Register
File, the operation is executed, and the result is stored back in the Register File
– in one
clock cycle.

31
CHAPTER 5
SOFTWAERE DESCRIPTION

5.1 MATLAB

5.1.1 Introduction

The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to
provide easy access to matrix software developed by the LINPACK (linear system
package) and EISPACK (Eigen system package) projects.

MATLAB is a high-performance language for technical computing. It integrates


computation, visualization, and programming environment. Furthermore, MATLAB is a
modern programming language environment: it has sophisticated data structures,
contains
built-in editing and debugging tools, and supports object-oriented programming.
These
factors make MATLAB an excellent tool for teaching and research.

MATLAB (matrix laboratory) is a multi-paradigm numerical computing


environment
and fourth-generation programming language. A proprietary
programming
language developed by MathWorks, MATLAB allows matrix manipulations, plotting
of functions and data, implementation of algorithms, creation of user interfaces,
and
interfacing with programs written in other languages,
including C, C+
+, C#, Java, Fortran and Python.

Millions of engineers and scientists worldwide use MATLAB ® to analyze and design
the
systems and products transforming our world. MATLAB is in automobile active safety
systems, interplanetary spacecraft, health monitoring devices, smart power grids,
and LTE
cellular networks. It is used for machine learning, signal processing, image
processing,
computer vision, communications, computational finance, control design, robotics,
and
much more.

The MATLAB platform is optimized for solving engineering and scientific problems.
The
matrix-based MATLAB language is the world’s most natural way to express
computational
mathematics. Built-in graphics make it easy to visualize and gain insights from
data. A vast
library of prebuilt toolboxes lets you get started right away with algorithms
essential to

32
your domain. The desktop environment invites experimentation, exploration, and
discovery. These MATLAB tools and capabilities are all rigorously tested and
designed to
work together.

It has powerful built-in routines that enable a very wide variety of computations.
It also has
easy to use graphics commands that make the visualization of results immediately
available. Specific applications are collected in packages referred to as toolbox.
There are
toolboxes for signal processing, symbolic computation, control theory, simulation,
optimization, and several other fields of applied science and engineering.

5.1.2 MATLAB Session

The goal of this minimum session (also called starting and exiting sessions) is to
learn the
first steps:

• How to log on

• Invoke MATLAB

• Do a few simple calculations

• How to quit MATLAB

5.1.3 Starting MATLAB

After logging into your account, you can enter MATLAB by double-clicking on the
MATLAB shortcut icon (MATLAB 8.1.0.430) on your Windows desktop. When you start
MATLAB, a special window called the MATLAB desktop appears. The desktop is a
window that contains other windows. The major tools within or accessible from the
desktop are:

• The Command Window


• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button

33
Figure 5.1 The graphical interface to the MATLAB workspace
When MATLAB is started for the first time, the screen looks like the one that shown
in the
Figure 1.1. This illustration also shows the default configuration of the MATLAB
desktop.
You can customize the arrangement of tools and documents to suit your needs.
Now, we are interested in doing some simple calculations. We will assume that you
have
sufficient understanding of your computer under which MATLAB is being run. You are
now faced with the MATLAB desktop on your computer, which contains the prompt (>>)
in the Command Window. Usually, there are 2 types of prompt:
>> for full version
EDU> for educational version
Note: To simplify the notation, we will use this prompt, >>, as a standard prompt
sign,
though our MATLAB version is for educational purpose.

5.1.4 Quitting MATLAB


To end your MATLAB session, type quit in the Command Window, or select File −→ Exit
MATLAB in the desktop main menu.

34
5.1.5 Creating MATLAB variables
MATLAB variables are created with an assignment statement. The syntax of variable
assignment is
variable name = a value (or an expression)
For example,
>> x = expression
where expression is a combination of numerical values, mathematical operators,
variables,
and function calls. On other words, expression can involve:
• manual entry
• built-in functions
• user-defined functions

5.1.6 Overwriting variable

Once a variable has been created, it can be reassigned. In addition, if you do not
wish to
see the intermediate results, you can suppress the numerical output by putting a
semicolon
(;) at the end of the line. Then the sequence of commands looks like this:

>> t = 5;

>> t = t+1

t=6

Error messages:

If we enter an expression incorrectly, MATLAB will return an error message. For


example, in the following, we left out the multiplication sign, *, in the following
expression

>> x = 10;

>> 5x

??? 5x

Error: Unexpected MATLAB expression.

5.1.7 Making corrections

35
To make corrections, we can, of course retype the expressions. But if the
expression is
lengthy, we make more mistakes by typing a second time. A previously typed command
can be recalled with the up-arrow key ↑. When the command is displayed at the
command
prompt, it can be modified if needed and executed.

5.1.8 Controlling the hierarchy of operations or precedence

Let’s consider the previous arithmetic operation, but now we will include
parentheses. For
example, 1 + 2 × 3 will become (1 + 2) × 3

>> (1+2)*3

ans =

and, from previous example

>> 1+2*3

ans =

By adding parentheses, these two expressions give different results: 9 and 7.

The order in which MATLAB performs arithmetic operations is exactly that


taught in
high school algebra courses. Exponentiations are done first, followed by
multiplications
and divisions, and finally by additions and subtractions. However, the standard
order of
precedence of arithmetic operations can be changed by inserting parentheses. For
example,
the result of 1+2×3 is quite different than the similar expression with parentheses
(1+2)×3.
The results are 7 and 9 respectively. Parentheses can always be used to overrule
priority,
and their use is recommended in some complex expressions to avoid ambiguity.

Therefore, to make the evaluation of expressions unambiguous, MATLAB has


established
a series of rules. The order in which the arithmetic operations are evaluated is
given in
Table. MATLAB arithmetic operators obey the same precedence rules as those in most
computer programs.

5.1.9 Hierarchy of arithmetic operations

Precedence Mathematical operations

First The contents of all parentheses are evaluated first,


starting from the
36
innermost parentheses and working outward.

Second All exponentials are evaluated, working from left to right.

Third All multiplications and divisions are evaluated, working


from left to
right.

Fourth All additions and subtractions are evaluated, starting from


left to right

For operators of equal precedence, evaluation is from left to right. Now, consider
another
example:

In MATLAB, it becomes

>> 1/(2+3^2)+4/5*6/7

ans =

0.7766

or, if parentheses are missing,

>> 1/2+3^2+4/5*6/7

ans =

10.1857

So here what we get: two different results. Therefore, we want to emphasize the
importance of precedence rule in order to avoid ambiguity.

5.1.10 Entering multiple statements per line

It is possible to enter multiple statements per line. Use commas (,) or semicolons
(;) to
enter more than one statement at once. Commas (,) allow multiple statements per
line
without suppressing output.

>> a=7; b=cos(a), c=cosh(a)

b = 0.6570

C = 548.3170

37
5.11 Miscellaneous commands
Here are few additional useful commands:
• To clear the Command Window, type clc
• To abort a MATLAB computation, type ctrl-c
• To continue a line, type . . .
5.12 Mathematical functions

MATLAB offers many predefined mathematical functions for technical computing which

contains a large set of mathematical functions.


Typing help elfun and help specfun calls up full lists of elementary and
special
functions respectively. There is a long list of mathematical functions that are
built into
MATLAB. These functions are called built-ins. Many standard mathematical functions,
such as sin(x), cos(x), tan(x), ex, ln(x), are evaluated by the functions sin, cos,
tan, exp, and
log respectively in MATLAB.
Table lists some commonly used functions, where variables x and y can be numbers,
vectors, or matrices.

TABLE 5.1 Functions for MATLAB

In addition to the elementary functions, MATLAB includes a number of predefined

38
constant values. A list of the most common values is given in Table

5.2 MATLAB Support Package for Arduino

With MATLAB® Support Package for Arduino® Hardware, you can use MATLAB to
interactively communicate with an Arduino board. The package enables you to perform
tasks such as:

 Acquire analog and digital sensor data from your Arduino board

 Control other devices with digital and PWM outputs

 Drive DC, servo, and stepper motors (also supports Adafruit Motor Shield)

 Access peripheral devices and sensors connected over I2C or SPI

 Communicate with an Arduino board over a USB cable or wirelessly over Wi-Fi

 Build custom add-ons to interface with additional hardware and software


libraries

Because MATLAB is a high level interpreted language, you can see results from I/O
instructions immediately, without compiling. MATLAB includes thousands of built-in
math, engineering, and plotting functions that you can use to quickly analyze and
visualize
data collected from your Arduino.

39
MATLAB support package for Arduino lets you write MATLAB programs that read and
write data to your Arduino and connected devices such as Adafruit motor
shield, I2C,
and SPI devices. Because MATLAB is a high level interpreted language,
programming with it is easier than with C/C++ and other compiled languages,
and
you can see results from I/O instructions immediately – no compiling. MATLAB
includes thousands of built-in math, engineering, and plotting functions that
you can
use to quickly analyze and visualize data collected from your Arduino.
With MATLAB support package for Arduino, the Arduino is connected to a computer
running MATLAB. Processing is done on the computer with MATLAB.

5.2.1 Benefits of Using MATLAB for Arduino Programming

 Read and write sensor data interactively without waiting for your code to
compile

 Analyze your sensor data using thousands of pre-built functions for signal
processing, machine learning, mathematical modeling, and more

 Quickly visualize your data using MATLAB’s vast array of plot types

40
Figure 5.2 Arduino common blocks in MATLAB

41
CHAPTER 6
IMAGE PROCESSING
6.1 INTRODUCTION
Image processing is the field of signal processing. Images can be thought of as
two-
dimensional signals via a matrix representation, and image processing can be
understood as
applying standard onedimensional signal processing techniques to two-dimensional
signals. Image processing is a very important subject, and finds applications in
such fields
as photography, satellite imaging, medical imaging, and image compression, just to
name a
few.
In the past, image processing was largely done using analog devices. However, as
computers have become more powerful, processing shifted toward the digital domain.
Like one-dimensional digital signal processing, digital image processing overcomes
traditional analog "problems" such as noise, distortion during processing,
inflexibility of
system to change, and difficulty of implementation. The image processing technique
we
will be implementing will be image blurring. As the board we have does not support
a
direct connection for the input image, we will use MATLAB to output the image as a
matrix and store it in the data memory of the DSP. To do this, we will use the
parallel port
connection to get our input data into the board. The DSP will then do the
processing and
write the output data in the program memory. We extract the output data and go back
to
MATLAB to analyze the results.
Our project methodology includes the following:
1. Use MATLAB to simulate the processing technique.
2. Implement the technique with assembly language on a ATMEGA328-based Arduino
board to perform the same operation.
3. Carefully locating the memory blocks where we will store our original and output
image.

6.2 THEORY
There are various ways of implementing the image blurring technique:
i. Linear blur – horizontal or vertical averaging of a fixed number of
pixels.

42
ii. Block blur – averaging a small block of pixels by propagating a fixed
sized
window through the entire image.
iii. Gaussian blur – convolution of the image with a two-dimensional
Gaussian
function.

6.3 Block Diagram

Figure 6.1 Block diagram of image processing


6.4 Image Acquisition
Generally an image is a two-dimensional function f(x,y)(here x and y are plane
coordinates).The amplitude of image at any point say f is called intensity of the
image. It is
also called the gray level of image at that point. We need to convert these x and y
values to
finite discrete values to form a digital image. The input image is a fundus taken
from stare
data base and drive data base. The image of the retina is taken for processing and
to check
the condition of the person. We need to convert the analog image to digital image
to

43
process it through digital computer. Each digital image composed of a finite
elements and
each finite element is called a pixel.
We have some conditions for forming an image f(x,y) as values of image are
proportional
to energy radiated by a physical source. So f(x,y) must be nonzero and finite. i.e.
0< f(x,y)
< ∞.

6.4.1 Image Resizing/Scaling


Image scaling occurs in all digital photos at some stage whether this be in Bayer
demosaicing or in photo enlargement. It happens anytime you resize your image from
one
pixel grid to another. Image resizing is necessary when you need to increase or
decrease
the total number of pixels. Even if the same image resize is performed, the result
can vary
significantly depending on the algorithm.
Images are resized because of number of reasons but one of them is very important
in our
project. Every camera has its resolution, so when a system is designed for some
camera
specifications it will not run correctly for any other camera depending on
specification
similarities. so it is necessary to make the resolution constant for the
application and hence
perform image resizing.

6.4.2 RGB to GRAY Conversion


Humans perceive colour through wavelength-sensitive sensory cells called cones.
There
are three different varieties of cones, each has a different sensitivity to
electromagnetic
radiation (light) of different wavelength. One cone is mainly sensitive to green
light, one to
red light, and one to blue light. By emitting a restricted combination of these
three colours
(red, green and blue), and hence stimulate the three types of cones at will, we are
able to
generate almost any detectable colour. This is the reason behind why colour images
are
often stored as three separate image matrices; one storing the amount of red (R) in
each
pixel, one the amount of green (G) and one the amount of blue (B). We call such
colour
images as stored in an RGB format. In grayscale images, however, we do not
differentiate
how much we emit of different colours, we emit the same amount in every channel. We
will be able to differentiate the total amount of emitted light for each pixel;
little light gives
dark pixels and much light is perceived as bright pixels. When converting an RGB
image
to grayscale, we have to consider the RGB values for each pixel and make as output
a
single value reflecting the brightness of that pixel. One of the approaches is to
take the
44
average of the contribution from each channel: (R+B+C)/3. However, since the
perceived
brightness is often dominated by the green component, a different, more "human-
oriented",
method is to consider a weighted average, e.g.: 0.3R + 0.59G + 0.11B.

6.4.3 Image Enhancement


Image enhancement is the process of adjusting digital images so that the results
are more
suitable for display or further analysis. For example, we can eliminate noise,
which will
make it more easier to identify the key characteristics. In poor contrast images,
the adjacent
characters merge during binarization. We have to reduce the spread of the
characters before
applying a threshold to the word image. Hence, we introduce “POWER- LAW
TRANSFORMATION” which increases the contrast of the characters and helps in better
segmentation. The basic form of power-law
transformation is
s = cr γ, where r and s are the input and output intensities, respectively; c and γ
are positive
constants. A variety of devices used for image capture, printing, and display
respond
according to a powerlaw. By convention, the exponent in the power-law equation is
referred to as gamma. Hence, the process used to correct these power-law response
phenomena is called gamma correction. Gamma correction is important, if displaying
an
image accurately on a computer screen is of concern. In our experimentation, γ is
varied in
the range of 1 to 5. If c is not equal to ’1’, then the dynamic range of the pixel
values will
be significantly affected by scaling. Thus, to avoid another stage of rescaling
after power-
law transformation, we fix the value of c = 1.With γ = 1, if the power-law
transformed
image is passed through binarization, there will be no change in the result
compared to
simple binarization. When γ > 1, there will be a change in the histogram plot,
since there is
an increase of samples in the bins towards the gray value of zero. Gamma correction
is
important if displaying an image accurately on computer screen is of concern.

6.5 Edge Detection


Edge detection is the name for a set of mathematical methods which aim at
identifying
points in a digital image at which the image brightness changes sharply or, more
technically, has discontinuities or noise. The points at which image brightness
alters
sharply are typically organized into a set of curved line segments termed edges.
The same problem of detecting discontinuities in 1D signal is known as step
detection and
the problem of finding signal discontinuities over time is known as change
detection. Edge

45
detection is a basic tool in image processing, machine vision and computer
envisage,
particularly in the areas of feature reveal and feature extraction.

6.5.1 Edge detection techniques


Different colours has different brightness values of particular colour. Green
image has
more bright than red and blue image or blue image is blurred image and red image is
the
high noise image. Following are list of various edge-detection methods:-  Sobel
Edge
Detection Technique  Perwitt Edge Detection  Roberts Edge Detection Technique 
Zerocross Threshold Edge Detection Technique  Canny Edge Detection Technique In
our
project we use “CANNY EDGE DETECTION TECHNIQUE” because of its various
advantages over other edge detection techniques.

6.5.2 Image Matching:-


Recognition techniques based on matching represent each class by a prototype
pattern
vector. An unknown pattern is assigned to the class to which is closest in terms of
predefined metric. The simplest approach is the minimum distance classifier, which,
as its
name implies, computes the (Euclidean) distance between the unknown and each of the
prototype vectors. It chooses the smallest distance to make decision. There is
another
approach based on correlation, which can be formulated directly in terms of images
and is
quite intuitive.
We have used a totally different approach for image matching. Comparing a reference
image with the real time image pixel by pixel. Though there are some disadvantages
related to pixel based matching but it is one of the best techniques for the
algorithm which
is used in the project for decision making. Real image is stored in matric in
memory and
the real time image is also converted in the desired matric. For images to be same
their
pixel values in matrix must be same. This is the simplest fact used in pixel
matching. If
there is any mismatch in pixel value it adds on to the counter used to calculate
number of
pixel mismatches.
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming environment. Furthermore, MATLAB is a
modern programming language environment: it has sophisticated data structures,
contains
built-in editing and debugging tools, and supports object-oriented programming.
These
factors make MATLAB an excellent tool for teaching and research.

46
MATLAB has many advantages compared to conventional computer languages (e.g., C,
FORTRAN) for solving technical problems. MATLAB is an interactive system whose
basic data element is an array that does not require dimensioning. The software
package
has been commercially available since 1984 and is now considered as a standard tool
at
most universities and industries worldwide.
It has powerful built-in routines that enable a very wide variety of computations.
It also has
easy to use graphics commands that make the visualization of results immediately
available. Specific applications are collected in packages referred to as toolbox.
There are
toolboxes for signal processing, symbolic computation, control theory, simulation,
optimization, and several other fields of applied science and engineering.
There are various tools in Matlab that can be utilized for image processing, such
as
Simulink, GUI etc. Simulink contains various toolboxes and image processing toolbox
is
one such example. Simulink is used for simulation of various projects. GUI is
another
important tool in Matlab. It can be designed either by manual programming which is
tedious task or by using guide. GUI is explained in next section.
6.6 GUI
A graphical user interface (GUI) is a graphical display in one or more windows
containing
controls, called components, which enable a user to perform interactive tasks. The
user of
the GUI does not have to create a script or type commands at the command line to
accomplish the tasks. Unlike coding programs to accomplish tasks, the user of a GUI
need
not understand the details of how the tasks are performed. GUI components can
include
menus, toolbars, push buttons, radio buttons, list boxes, and sliders—just to name
a few.
GUIs created using MATLAB tools can also perform any type of computation, read and
write data files, communicate with other GUIs, and display data as tables or as
plots. The
following figure illustrates a simple GUI that you can easily build
The GUI contains
•An axes component
•A pop-up menu listing three data sets that correspond to MATLAB
Functions: peaks, membrane, and sinc
•Astatic text component to label the pop-up menu
•Three buttons that provide different kinds of plots: surface, mesh, and contour
When you click a push button, the axes component displays the selected data set
using the
specified type of 3-D plot.

47
Typically, GUIs wait for an end user to manipulate a control, and then respond to
each user
action in turn. Each control, and the GUI itself, has one or more call-backs, named
for the
fact that they “call back” to MATLAB to ask it to do things. A particular user
action, such
as pressing a screen button, or passing the cursor over a component, triggers the
execution
of each call back. The GUI then responds to these events. You, as the GUI creator,
write
call-backs that define what the components do to handle events. This kind of
programming
is often referred to as event-driven programming. In event-driven programming, call
back
execution is asynchronous, that is, events external to the software trigger call
back
execution. In the case of MATLAB GUIs, most events are user interactions with the
GUI,
but the GUI can respond to other kinds of events as well, for example, the creation
of a file
or connecting a device to the computer.
You can code call-backs in two distinct ways:
•As MATLAB language functions stored in files
•As strings containing MATLAB expressions or commands (such as 'c = sqrt(a*a +
b*b);
'or' print')Using functions stored in code files as call-backs is preferable to
using strings,
because functions have access to arguments and are more powerful and flexible. You
cannot use
MATLAB scripts (sequences of statements stored in code files that do not define
functions)
as call-backs. Although you can provide a call back with certain data and make it
do
anything you want, you cannot control when call-backs execute. That is, when your
GUI is
being used, you have no control over the sequence of events that trigger particular
call-
backs or what other callbacks might still be running at those times. This
distinguishes
event-driven programming from other types of control flow, for example, processing
sequential data files.
A MATLAB GUI is a figure window to which you add user-operated components. You can
select, size, and position these components as you like using call-backs you can
make the
components do what you want when the user clicks or manipulates the components with
keystrokes.
You can build MATLAB GUIs in two ways:
•Use GUIDE (GUI Development Environment), an interactive GUI construction kit.
This approach starts with a figure that you populate with components from within a
graphic layout editor. GUIDE creates an associated code file containing call-backs
for the

48
GUI and its components. GUIDE saves both the figure (as a FIG-file) and the code
file.
Opening either one also opens the other to run the GUI.
•Create code files that generate GUIs as functions or scripts (programmatic GUI
construction).
Using this approach, you create a code file that defines all component properties
and
behaviours. When a user executes the file, it creates a figure, populates it with
components,
and handles user interactions. Typically, the figure is not saved between sessions
because
the code in the file creates a new one each time it runs.
The code files of the two approaches look different. Programmatic GUI files are
generally
longer, because they explicitly define every property of the figure and its
controls, as well
as the call-backs. GUIDE GUIs define most of the properties within the figure
itself. They
store the definitions in its FIG-file rather than in its code file. The code file
contains call-
backs and other functions that initialize the GUI when it opens.
You can create a GUI with GUIDE and then modify it programmatically. However, you
cannot create a GUI programmatically and then modify it with GUIDE. The GUI-
building
technique you choose depends on your experience, your preferences, and the kind of
application you need the GUI to operate. This table outlines some possibilities.

49
CHAPTER 7
FUNCTIONAL INTEGRATION OF PROJECT
7.1 Block Diagram

Figure 7.1: Block Diagram of home automation

7.2 Coding

%a = arduino('COM3')
a.pinMode(2,'OUTPUT'); %buzzer
a.pinMode(3,'OUTPUT'); %light_out
a.pinMode(4,'OUTPUT'); %motor_gate1
a.pinMode(5,'OUTPUT'); %motor_gate2
a.pinMode(6,'INPUT'); %ldr_gate1
a.pinMode(7,'INPUT'); %ldr_gate2
a.pinMode(8,'INPUT'); %gas_sensor
a.pinMode(9,'OUTPUT'); %fan_left
a.pinMode(10,'OUTPUT'); %fan_right
vid = videoinput('winvideo',1,'MJPG_160x120');
pause(3);
image_1 = getsnapshot(vid);
%preview(vid);
for i = 1:20
pause(2);
image_2 = getsnapshot(vid);
Imaged1 = im2double(image_1);
n=fix(size(Imaged1,1)/2);
A=Imaged1(:,1:n+20,:);

50
B=Imaged1(:,n+21:end,:);
Imaged2 = im2double(image_2);
m=fix(size(Imaged2,1)/2);
C=Imaged2(:,1:m+20,:);
D=Imaged2(:,m+21:end,:);
ImagegA = im2bw(A,0.4);
ImagegB = im2bw(B,0.4);
ImagegC = im2bw(C,0.4);
ImagegD = im2bw(D,0.4);
Black_A = sum(sum(ImagegA == 0));
White_A = sum(sum(ImagegA));
disp(Black_A);
disp(White_A);
Black_B = sum(sum(ImagegB == 0));
White_B = sum(sum(ImagegB));
disp(Black_B);
disp(White_B);
Black_C = sum(sum(ImagegC == 0));
White_C = sum(sum(ImagegC));
disp(Black_C);
disp(White_C);
Black_D = sum(sum(ImagegD == 0));
White_D = sum(sum(ImagegD));
disp(Black_D);
disp(White_D);
if (((Black_C - Black_A) > 50) || ((White_C - White_A) > 50))
disp('right side');
a.digitalWrite(10,1);
else
disp('no person on right side');
a.digitalWrite(10,0);
end
if (((Black_D - Black_B) > 50) || ((White_D - White_B) > 50))
disp('left side');
a.digitalWrite(9,1);
else
disp('no person on left side');
a.digitalWrite(9,0);
end
J = imsubtract(ImagegA,ImagegC);
K = imsubtract(ImagegB,ImagegD);
subplot(3,2,1);subimage(ImagegA)
subplot(3,2,2);subimage(ImagegB)
subplot(3,2,3);subimage(ImagegC)
subplot(3,2,4);subimage(ImagegD)
subplot(3,2,5);plot(J)
subplot(3,2,6);plot(K)
%light intensity
voltage = a.analogRead(0); %ldr_read

51
voltage = voltage/64;
voltage = voltage*voltage;
voltage = round(voltage);
a.analogWrite(3,voltage);
pause(0.5);
%gas sensor
gas = a.digitalRead(8);
a.digitalWrite(2,gas);
pause(1);
%gate
gate_1 = a.digitalRead(6);
gate_2 = a.digitalRead(7);
if ((gate_1 == 0) && (gate_2 == 0))
a.digitalWrite(4,0);
a.digitalWrite(5,1);
pause(1.5);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
end
if ((gate_1 == 1) && (gate_2 == 0))
a.digitalWrite(4,1);
a.digitalWrite(5,0);
pause(1.5);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
end
if ((gate_1 == 0) && (gate_2 == 1))
a.digitalWrite(4,1);
a.digitalWrite(5,0);
pause(1.5);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
end
if ((gate_1 == 1) && (gate_2 == 1))
a.digitalWrite(4,1);
a.digitalWrite(5,0);
pause(1.5);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
end
end

52
CHAPTER 8
RESULT

8.1 Applications
 Heating, ventilation and air conditioning (HVAC): it is possible to have
remote
control of all home energy monitors over the internet incorporating a simple
and
friendly user interface.
53
 Lighting control system

 Occupancy-aware control system: it is possible to sense the occupancy of


the home
using smart meters and environmental sensors like CO2 sensors, which can be
integrated into the building automation system to trigger automatic responses
for
energy efficiency and building comfort applications.

 Appliance control and integration with the smart grid and a smart meter,
taking
advantage, for instance, of high solar panel output in the middle of the day
to run
washing machines.

 Security: a household security system integrated with a home automation


system
can provide additional services such as remote surveillance of security
cameras over
the Internet, or central locking of all perimeter doors and windows.

 Leak detection, smoke and CO detectors

 Indoor positioning systems

 Home automation for the elderly and disabled

8.2 Advantages
 Adds safety through appliances and lighting control.

 Secures Home Through Automated Door Locks

 Increases Awareness Through Security Cameras

 Increases Convenience Through Temperature Adjustment

 Saves time

 Saves Money and Increases Convenience

 Contributes to Economy

 Increases Peace of Mind

 Allows You Control When Out of Town

8.3 Disadvantages

The more advanced the system; the cost of the system will be very high as it has
the more
advantages and more new features. As there is a gradual growth in developing the
home

54
automated devices price the cost is going to reduce. But as of now, because of the
unpopularity of the home automated devices the cost is very high. Current
technology is
unable to reach the desired task. Human errors also lead to destructions of the
machine.
Then there will be a huge system crash. The main disadvantages of this home
automation
are :

1.Human System: Human System crashes due to any damage in the interconnection: If
there is any damage due to rupturing of cables or the fibers the entire system gets
crashed.
This will not be the case of radio signals or the other signals. Here there will be
a problem
of signal receiving. The wiring of the system results in crash in most of the
systems.

2.Errors: If the human does Equipment and installation costs: Automation of the
home is
widely related to the financial costs. The total cost depends on the equipments you
install
in your house and on how much it takes to Almost everyone is aware of the
advantages of
home automation, but apart from the advantages it also has some disadvantages.

3.Reliability: In very rare cases, the reliability of the home automated devices
varies
(decreases). It depends mostly on the technology used and the advancements being
done.

CHAPTER 9
FUTURE SCOPE
The next phase for the Home automation market will occur based on a few key
improvements in the technology available in Automation, such as improvement in
Wireless
Automation solutions as well as lowering of price points as the market begins to
accept
Home automation usage in larger volumes. Some trends that we foresee for this phase
of
the industry are

55
1. Big companies like Philips, Siemens & Schneider will eventually bring out fairly
mass
market automation products with appealing user interface but at a lower price point
than
today, and more people will be able to afford the
products
2. Solution offerings will slowly move to a more user friendly design, where aside
from a
few key components, users will be able to buy and use the Automation products
themselves
without the aid of any technical
expert
3. Some foreign players will have niche in high end automation and focus on the
premium
market (>20 Lakh ticket size).

4. We foresee that all major players will have a presence leading to competition in
prices
and lower margins

5. The products themselves will reach a ‘plug and play’ type of usability, where
users can
simply purchase pieces from the store and use it themselves without any support
from
professionals

6. Many (most) houses will incorporate some aspect of Automation in the home, from
Lighting, security or HVAC elements. Home Automation will be as commonplace as
having a Fridge or Television in the house.

CHAPTER 10
CONCLUSION

I learned a lot in the process of making this project, and I hope it will encourage
many of
you to consider bringing home automation into your own lives. I'll admit that
wiring up
light switches is not the easiest of tasks for someone who hasn't done it before,
but the
plug-in devices are a snap to set up and make for an easy entry-point to working
with the
technology.
Most people are very timid the first time they have to replace a component in their
PC and,
in the same way, there is a learning curve to home automation. And although the

56
components you're dealing with are not as sensitive as those inside a computer,
there is a
risk anytime you are working near electric circuits (in this case more of a risk to
yourself).
Once I finished with the installation, the only signs of the work I'd done was a
set of nicer
lights and a handful of LDR used in the project. I won't try claiming that anyone
can
manage a home automation installation, so if you're uncomfortable around
electronics,
don't know what you're doing in a breaker box, or are particularly accident-prone,
don't
even risk it. I would think that if you've soldered wires before, though, then you
probably
have enough knowledge and common sense to take on a task like this.
In the future, I plan to add a controlled thermostat, tie into a security system,
add a wireless
controller , and add more controlled lights.

REFRENCES

1."What is smart home - Basic Idea". cctvinstitute.co.uk. Retrieved 2016-10-29.


2. .Hill, Jim (12 September 2015). "The smart home: a glossary guide for the
perplexed".
T3. Retrieved 27 March 2017.
3."5 Open Source Home Automation Projects We Love". Fast Company. 2014-12-01.
Retrieved 2016-11-22.
4."Best Home Automation System - Consumer Reports". www.consumerreports.org.
Retrieved 2016-02-14.
5."Wireless Sensor Networks: Concepts, Applications, Experimentation and Analysis".
2016. p. 108. ISBN 9811004129. The use of standardized, with open standards over
proprietary protocols provides the industry with the freedom to choose between
suppliers
with guaranteed interoperability. Standardized solutions usually have a much longer
lifespan than proprietary solutions.

57
6. "Research and Markets: Global Home Automation and Control Market 2014-2020 -
Lighting Control, Security & Access Control, HVAC Control Analysis of the $5.77
Billion
Industry". Reuters. 2015-01-19. Archived from the original on 2016-05-05.
7. Home Automation & Wiring (1 ed.). New York: McGraw-Hill/TAB Electronics. 1999-
03-31. ISBN 9780070246744.
8. Rye, Dave (October 1999). "My Life at X10". AV and Automation Industry
eMagazine.
AV and Automation Industry eMagazine. Retrieved October 8, 2014.
9."1.5 Million Home Automation Systems Installed in the US This Year".
www.abiresearch.com. Retrieved 2016-11-22.
10. Li, Rita Yi Man; Li, Herru Ching Yu; Mak, Cho Kei; Tang, Tony Beiqi.
"Sustainable
Smart Home and Home Automation: Big Data Analytics Approach" (PDF). International
Journal of Smart Home. 10 (8): 177–198. doi:10.14257/ijsh.2016.10.8.18.

58