Professional Documents
Culture Documents
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.5 CD Loader
2.2.6 Ldr
2.2.7 DC Motor
2.2.8 Led
2
2.3 Block Diagram
3
CHAPTER 3
HARDWARE DESCRIPTION
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
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.
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
7
Figure 3.2 Concentration of gas
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. Its like a
switch.
9
Figure 3.3 Pin diagram of L293D
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 voltageby 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).
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.
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.
12
Figure 3.5 Variation in resistance with changing light intensity
LDRs 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 LDRs 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, LDRs 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.
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.
15
3.5.4 Applications Of LDR
There are many applications for Light Dependent Resistors. These include:
Cost: LDRs 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
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
(ARDUINO BASED)
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.
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:
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.
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
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.
4.4.1 Features
23
Up to 16 MIPS Throughput at 16 MHz
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
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.
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.
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.
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.
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)
These are additional function that pin can perform other than I/O. Some of them are
ADC (ADC0 - ADC7 on PORTA)
28
4.4.6 Block Diagram
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
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.
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 worlds 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.
The goal of this minimum session (also called starting and exiting sessions) is to learn the
first steps:
How to log on
Invoke 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:
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.
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
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:
>> x = 10;
>> 5x
??? 5x
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.
Lets 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 =
>> 1+2*3
ans =
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+23 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.
First The contents of all parentheses are evaluated first, starting from the
36
innermost parentheses and working outward.
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
>> 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.
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.
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 oers many predened mathematical functions for technical computing which
38
constant values. A list of the most common values is given in Table
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
Drive DC, servo, and stepper motors (also supports Adafruit Motor Shield)
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.
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 MATLABs 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.
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)
< .
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.
45
detection is a basic tool in image processing, machine vision and computer envisage,
particularly in the areas of feature reveal and feature extraction.
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 slidersjust 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
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
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.
8.2 Advantages
Adds safety through appliances and lighting control.
Saves time
Contributes to Economy
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
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): 177198. doi:10.14257/ijsh.2016.10.8.18.
58