Uploaded by Abdulaziz Aminov

Development of Motion Detection Unit Usi

advertisement
MOI UNIVERSITY
SCHOOL OF INFORMATION SCIENCES
(Department of Information Technology)
DEVELOPMENT OF SIMPLE MOTION SENSING COMPONENT
Supervisor,
Dr. Austin Owino
(Bsc. Msc. PhD)
Submitted by,
Ochieng, Francis Omondi
IS/50/12
Monday, 16th May 2016
This research project is submitted in partial fulfilment of the requirements for the award of
the degree of Bachelor of Science in Information Sciences of Moi University
i
DECLARATION OF ORIGINALITY
This project, as presented in this report, is my original work and has not been presented for any
other University award. Any works of other authors used in it are well acknowledged at the
point of their use. No part of this thesis may be reproduced without the prior written permission
of the author and/or Moi University.
Ochieng, Francis Omondi
Signature
Date
…………..
………….
Declaration by Supervisor
This thesis has been submitted for examination with my approval as University Supervisor.
Dr. Owino
Moi University, Eldoret
………….
……………
ii
DEDICATION
I dedicate this project to my family. I thank you all for walking with me to this far. Your
innovative ideas and realistic relevant challenges you posed to me at all times made me think
far in regard to my education. Your financial and spiritual support is highly appreciated
throughout this period. May the Almighty bless you.
iii
ABSTRACT
The detection of motion has its roots in astronomy. The necessity to have devices that can work
on their own with minimal human control and at the same time can be controlled remotely
inspired the development of a simple motion detector component. This component employs
infrared technology for motion sensing. This project involves the implementation of software
and hardware. For the hardware part, PIR sensor, Piezzo buzzer and a laptop are connected to
each other by an ATMega328 on Arduino UNO microcontroller which acts as the central
processing unit of the whole component. PIR sensor aids in detecting presence of someone,
Piezzo buzzer is used as an alarm unit that beeps when someone is detected. The laptop is used
to program the Arduino UNO but when the component is working as programmed, it is used
to power the microcontroller and also as the status indicator module. For the software part, C
programming language was used to program the microcontroller through the Arduino software.
When motion is detected, the Piezzo buzzer beeps, the LED pin on the microcontroller lights
and “MOTION DETECTED” message is printed on the laptop screen. The working of the
piezzo buzzer and the LED is concurrent for five seconds and the message is printed once
during the same time interval. When no motion is detected the devices remain mum as
programmed. Communication between the Arduino UNO and other devices is through voltage
signals which are carriers of information. The motion detector component that has been
developed is very flexible and easy to use by users, who can as well customize and improve it
further to satisfy their varying needs.
Keywords
Infrared, ATMega328, C, Arduino UNO, PIR sensor, Piezzo Buzzer
iv
TABLE OF CONTENTS
DECLARATION OF ORIGINALITY
i
DEDICATION
ii
ABSTRACT
iii
TABLE OF CONTENTS
iv
LIST OF ABBREVIATIONS AND ACRONYMS
vii
LIST OF TABLES
viii
LIST OF FIGURES
IX
ACKNOWLEDGEMENT
X
CHAPTER ONE: INTRODUCTION
1
1.1 Background
1.2 Problem Statement
1.3 Aim of the Project
1.4 Objectives
1.5 Research Questions
1.6 Significance and Justification of the Study
1.7 The Proposed Solution
1
2
2
2
2
2
3
CHAPTER TWO: LITERATURE REVIEW
4
2.1 Introduction
2.2 Embedded Systems
2.2.1 Embedded Systems versus General Purpose Systems
2.2.2 Design Issues in Embedded Systems
2.2.3 Development Tool in Embedded Systems
2.2.4 Trends in Embedded Systems
2.2.4.1 Application Specific Integrated Circuits (ASIC)
2.2.4.2 Systems on a Chip (SOC)
2.2.5 Challenges with Embedded Systems Design
2.3 Motion Sensors
2.3.1 Types of Motion Sensors
2.3.1.1 Passive Infrared Type of sensors
2.3.1.2 Area Reflective Type of Sensors
2.4 Arduino UNO Microcontroller
2.4.1 Technical Specifications
2.4.2 Programming
2.4.3 Difference with other boards
2.4.4 Power
4
4
4
5
6
6
6
7
7
7
8
8
9
9
10
10
10
11
v
2.4.5 Memory
2.4.6 Input and Output
2.4.7 Communication
2.5 Embedded Development Cycle
11
12
13
13
CHAPTER THREE: METHODOLOGY
3.0 Introduction
3.1 Project Planning
3.2 Project Block Diagram
3.3 Project Description
3.4 The Sensor Module
3.5 The Motion Detector System
3.6 Software Development
3.7 Programming Tools
3.7.1 Connecting PIR Sensor to Arduino UNO
3.7.2 Connecting Piezzo Buzzer to Arduino UNO
16
16
16
18
18
19
19
20
21
25
25
CHAPTER FOUR: RESULTS AND DISCUSSION
4.1 Introduction
4.2 Testing Development
4.2.1 Testing the Sensor Module
4.2.2 Testing the Alarm Module
4.2.3 Testing the Status Indicator Module
4.3 Discussion
4.4 Project justification of Results
26
26
26
28
28
29
30
31
CHAPTER FIVE: CONCLUSION ND RECOMMENDATIONS
5.1 Conclusion
5.2 Obstacles Encountered in the Project
5.3 Recommendations for the Project
32
32
32
33
REFERENCES
BIBLIOGRAPHY
APPENDICES
34
35
36
vi
LIST OF ABBREVIATIONS AND ACRONYMS
EDA
Electronic Design Automation
ASIC
Application Specific Integrated Circuits
SOC
Systems on a Chip
PWM
Pulse Width Modulation
EEPROM
Electrically Erasable Programmable Read Only Memory
ADC
Analog-Digital converter
SRAM
Static Random Access Memory
GND
Ground
ROM
Read Only Memory
RAM
Random Access Memory
vii
LIST OF TABLES
Table 2.4.2:
Technical specifications for Arduino UNO
viii
LIST OF FIGURES
Figure 2.3.1.1.1:
Graphical description of passive infrared type of sensors
Figure 2.3.1.2.1:
Graphical description of area reflective type of sensors
Figure 2.4.1:
Arduino UNO Rev3 microcontroller
Figure 3.1.1:
Project planning flowchart
Figure 3.2.1:
Block Diagram for Motion Detector System
Figure 3.4.1:
PIR Sensor
Figure 3.6.1
Flowchart for the motion detector system
Figure 3.7.1:
Loading of Arduino Software
Figure 3.7.2
Configuration for connecting Arduino UNO microcontroller with a
computer
Figure 3.7.3:
Selecting the Arduino UNO Board
Figure 3.7.4:
Selecting COM29 port
Figure 3.7.5:
Programming Motion Detector system using Arduino Software
Figure 3.7.6:
Uploading the Source Code to the Arduino
Figure 3.7.7:
PIR Sensor and Piezzo Buzzer connected to the Arduino UNO
Figure 3.7.2.1:
Piezzo Buzzer
Figure 4.1.1:
The Motion Detector System
Figure 4.2.1
Project testing flowchart
Figure 4.2.1.2:
Testing the PIR Sensor
Figure 4.2.2.2:
Testing the Piezzo Buzzer
Figure 4.2.3.2:
Motion detector system and serial monitor
ix
ACKNOWLEDGEMENT
Hereby, I render my sincere gratitude to all who contributed towards the successful completion
of this project.
First, I thank the Almighty God for his divine mercy, graces, gift of life, strength and wisdom
that enabled me come up with this project.
To my academic supervisor, thanks for believing in this project from the start and also believing
in me in pursuit for the development of the component above.
I cannot forget to thank Mr. Titus Koech, a fifth year BEng. Electronics and Communications
Engineering student for his immense support in understanding circuits and aid in acquisition
of devices used in the project.
To my classmates and friends, thank you for your expert advice and constructive criticism.
1
CHAPTER 1: INTRODUCTION
1.1 Background
The detection of motion finds its roots in astronomy, which goes back thousands of years ago.
Early farmers looked to the heavens and used the movement of stars to determine when to plant
crops and when to harvest them.
The first motion detection system; radar, was pioneered by Heinrich Hertz. Hertz studied the
properties of waves and found that waves could bounce off of objects and had different speeds.
This revelation was a breakthrough and as Furnish (2007) cites, the increased demand for
detection and monitoring during World War II generated technological advances in motion
sensing. And in 1940s, radar technology was sufficiently advanced that the military could
detect attacks in advance and guide aircraft, Huebsch (2014).
Although the development of radar systems was a great achievement, its applications were
limited to military use, then. One of the first applications of motion sensing outside the military
was developed by Samuel Bagno in the mid-1940s. Using his knowledge of radar and newly
developed electrical components, Bagno began doing research on an ultrasonic alarm, which
worked similarly to radar. His ultrasonic alarm created "a web of ultrasonic waves inside a
room" and detected the motion of a person, Cerruti (1995).
The invention of the ultrasonic alarm generated a demand for other non-military applications
of this technology, especially infrared technology. Although infrared detection had been
invented in the mid-1800s, its applications were limited to astronomy then, Cerruti (1995), but
over time, its scope of application has grew tremendously.
Passive Infrared, commonly known as PIR is the technology of motion detectors that is used
to detect people by sensing the thermal infrared radiation emitted by the human body. PIR
motion detectors always use thermal sensors, detecting the small temperature increase when
the sensor element is exposed to radiation and absorbs it.
2
1.2 Problem Statement
Automation is a field that incorporates computer science and electronics heavily. The growing
need to have systems that can be controlled remotely and can be attached to almost every
appliance and furniture has seen the development of new age of computing referred to as
Internet of Things (I0T). People today need systems that can work independently and send
feedback (results of processing; output) to them and can as well monitor various processes in
their homes, offices etc. It is this need that inspires the development of a simple motion
detection unit that its use can be customized to domestic usage for unique needs.
1.3 Aim of the project
This project aims to develop a simple motion detector component that will in turn relay
feedback immediately after motion is detected.
1.4 Objectives of the Project
The following are the project objectives:
a) To develop a system that utilizes infrared technology for motion detection
b) To design the motion sensing component
c) To program ATmega328 on Arduino Uno Rev3 Board microcontroller as the central
processing unit of the component.
1.5 Research Questions
The study shall be guided by the following research questions
a) How does motion sensors work?
b) How can one make several devices work simultaneously?
c) Is motion sensing an effective way in security, tallying and remote distance processing
1.6 Significance and justification of the study
Over time, there have been a growing need to have systems that can work independently and
can be controlled remotely. Internet has contributed to this because of its ever decreasing cost
on connection. Leased line connections such as fibre optic connections, as well as the ADSL
(Asymmetric Digital Subscriber Line) connections tend to replace PSTN (Public Switched
Telephone Network) and ISDN (Integrated Services Digital Network) connections for
everyday use.
3
Previous studies have shown challenges in implementing intelligent embedded systems with
human rights groups always on the watch out demanding for health implication of radiations
that such devices emit when in operation.
The motion sensor component being developed in this project will instead tap infrared
radiations instead of generating them to detect motion.
1.7 The proposed solution
The setup shall be able to detect movement of animals and inanimate objects then react by
printing a message on a serial screen of a computer, switch on the buzzer and LED light already
grounded on the Arduino Uno microcontroller.
4
CHAPTER 2: LITERATURE REVIEW
2.1 Introduction
This chapter offers a brief background into the areas that are related to the research performed
in this report as well as the areas that support the reasons for performing this research.
The first section takes a look at embedded systems, the issues and tools involved in their design,
current trends and the challenges in embedded systems design.
The second section examines motion sensors and the Arduino UNO microcontroller.
Section third which is also the final section of this chapter discusses embedded development
cycle.
Simply put, the proposed outcome of this chapter is a clearer understanding of the important
variables of research as they relate to motion detection.
2.2 Embedded Systems
Embedded systems have become a buzz word in the last five years. However, embedded
systems and processors have been around for much longer than that, Stepner (1999). One only
needs to look around to see embedded systems everywhere: cell phones, alarm clocks, personal
data assistants (PDAs), automobile subsystems such as ABS and cruise control, etc.
2.2.1 Embedded Systems versus General Purpose Systems
An embedded system is usually classified as a system that has a set of predefined, specific
functions to be performed and in which the resources are constrained. Each embedded design
satisfies its own set of functions and constraints.
This is different from general purpose systems, such as the computer that sits on a desk in an
office. The processor running that computer is termed a “general purpose” processor because
it was “designed to perform many different tasks well,” Collins (2000) as opposed to an
embedded system that has been built to perform a few specific tasks either very well or within
very strict parameters.
5
2.2.2: Design Issues in Embedded Systems
As mentioned above, embedded systems are defined by their functions and their constraints.
These constraints are almost as varied as the number of embedded systems themselves, but a
few of the more prevalent ones are response time accuracy, size, power consumption, and cost,
Stepner (1999). All of these poses difficult decisions which an embedded system designer must
make.
Response time is a critical factor in many embedded systems; whether it is a specific time that
an embedded system tasks needs to be run or the time between tasks that is important. The
most difficult task for an embedded system designer to do is to quantify time deadlines, decide
whether these deadlines are firm, and recognize what the consequences are if these deadlines
are not met, Collins (2000).
Size is also an important decision in many embedded systems. Many embedded systems
designed today are bought and sold simply because they are smaller than the last
implementation of that product. A living example is mobile phones.
Another design issue concerning today’s embedded system designers is power consumption.
Many of embedded systems are usually very small that are handheld devices that are made to
be mobile hence; they must have a battery. Since the designer does not want the user to be
forced to plug in or recharge the device every five minutes, the designer must make important
choices in his design decisions and balance a feature’s merits against the power that the feature
will consume, Collins (2000).
A final consideration that embedded designers need to deal with is cost. Regardless of any
choice of the above issues made, an embedded product is not going to sell if its cost is
exorbitant. Most end users will sacrifice a small amount of performance, or a slightly less
amount of battery time, for an embedded product that is less costly than all of its competitors.
This demands that the designer must consider the cost of adding a particular modification to
the design and whether or not the end user will be willing to pay that additional cost for that
additional feature, Collins (2000).
6
2.2.3: Development Tools in Embedded Systems
Embedded development tools have traditionally been behind the tools for the development of
general systems as stated by Stepner (1999). Distinct to general systems, the design space for
embedded systems is extremely large making it a challenge to contain all the facilities required
to specify, design, and test embedded systems.
However, there is hope in embedded systems development because they have garnered more
interest in the research community as well as their increased need. Microprocessor companies
are now delving into this interesting field. Intel, a leading processor manufacturer has a keen
eye in embedded systems that has seen it manufacture varied microcontrollers and sponsoring
research towards the realisation of Internet of Things (IoT).
This is a motivation to embedded designers because embedded systems tools are now catching
up with regular system design tools, and they have become more readily available and diverse
in their area of coverage, Stepner (1999).
Stepner (1999) opens further by stating that tools that were not available five to ten years ago
are now available as part of “common EDA development suites”. Also, there are tools that are
now available for the development of embedded system application software as well as the
development of real-time operating systems in normal computer programming languages with
C Language taking the lead.
2.2.4 Trends in Embedded System
With the increasing interest and research, embedded systems are experiencing a plethora of
new design trends. Five years from today, embedded systems of that time won’t bear much
resemblance to the systems of today other than their basic functionalities, which may even be
replaced in prospective times.
Two of the trends currently hot in the world of embedded systems that are discussed here are
that of application specific integrated circuits (ASICs) and systems on a chip (SOC).
2.2.4.1 Application Specific Integrated Circuits
Smith (1997) suggests that the best way to define an application specific integrated
circuit (ASIC) is by saying what it is not: “an integrated circuit designed for multiple
7
uses. Like the title suggests, this is an IC that has been designed for a specific
application”.
Examples of ICs that are not ASICs are standard computer parts such as RAM, ROM,
multiprocessors, etc. Examples of ICs that are ASICs are a chip designed for a toy robot
or a chip designed to examine sun spots from a satellite, Smith (1997).
2.2.4.2 System on a Chip
System on a chip (SOC) is exactly what it sounds like i.e. “hardware designers have
taken the normally separate pieces of a complete system; the CPU, memory controller,
main memory, I/O control, and the various buses and interconnects, and placed many
or all of them on a single piece of silicon” Collins (2000). This explains why there is
reduction in size, power, cost and drop time delay.
2.2.5 Challenges with Embedded System Design
One of the problems with embedded systems, and more specifically ASICs and SOCs, is that
it is no longer possible to obtain debug information that was readily available in systems with
discrete components. Those signals that are contained only in the silicon, such as information
across the memory bus, never leave the silicon. The only way to debug them is to either probe
the silicon itself, or to add additional logic to the chip that brings the signal off the chip, and
even that option is limited by the number of physical pins that can be put on a chip and spared
for simple debug and evaluation purposes. Also, with the speeds that some of today’s
embedded processors are running, it becomes difficult to find a logic analyser that can keep up
with the processors, not to mention costing tens to hundreds of thousands of dollars, Gwennap
(1998) and Kozyrakis (1997). If there were another method to test these systems, both valuable
time and money could be saved.
2.3 Motion sensors
A motion sensor is an infrared human detection sensor, which, as opposed to factory
automation sensors that are used with factory equipment, is designed to be incorporated into
various devices that exist around us in daily life.
8
Motion sensing systems involve processing of analog data to digital data for an efficient
relevant mechanical output. Therefore, they belong to a certain category of information
systems.
2.3.1 Types of motion sensors
Motion sensors are divided into two parts
i)
Passive infrared type
ii)
Area reflective type sensors.
2.3.1.1 Passive infrared type
Designed to cover a wide area, this sensor detects human presence. The sensor, rather
than emitting light such as from LEDs, detects the amount of change in infrared rays
that occurs when a person (object), whose temperature is different from the
surroundings, moves.
Figure 2.3.1.1.1 Graphical description of passive
infrared type of sensors. (Source: Google Images)
All objects on the earth emit light in accordance with their temperature and
surface characteristics. Naturally, light (infrared radiation) is also emitted from
our bodies. (This radiation is emitted from the body surface, and is centred on a
wave-length of 10μm.) When a person enters the detection area of the sensor,
the amount of infrared radiation incident on the sensor varies by the amount
corresponding to the difference in temperature between the body surface and
background. These sensors detect the human body by detecting the change in
incident infrared radiation. That is, the sensor is actuated by the difference in
9
temperature between human body (which is a heat source) and floor, walls and
other objects forming the background. The same also applies to inanimate
objects such as rolling ball. This is because, when those objects move, friction
acts on them thus generating heat. This heat emits infrared radiation which the
passive infrared type can detect.
2.3.1.2 Area reflective type of sensors
These sensors detect the human body via the area reflection system.
Figure 2.3.1.2.1 Graphical description of area reflective type of sensors.
(Source: Google Images)
The sensor sends out a ray of light toward the human body from an LED then
uses the reflected light to measure the distance and determine whether the
person is within a given distance of the sensor. If the sensor decides that there
is a person within the given distance, it sets an output non-contact switch to ON.
2.4 Arduino Uno Microcontroller
Figure 2.4.1: Arduino UNO Rev3 microcontroller (Source: www.ardino.cc)
10
The Arduino UNO is the best board to get started with electronics and coding.
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 i.e. it can simply be connected to
a computer with a USB cable or powered with an AC-to-DC adapter or battery to get started.
As found in Arduino forum, Arduino UNO microcontroller has the following specifications:
2.4.1 Technical Specifications
Table 2.4.1 Technical specifications for Arduino UNO
Source: Arduino Forum (www.arduino.cc)
2.4.2 Programming
The Uno can be programmed with the Arduino software. The ATmega328 on the Uno comes
pre-programmed with a boot-loader that allows one to upload a new code to it without the use
of an external hardware programmer.
The Uno has a resettable poly-fuse that protects the user’s computer's USB ports from shorts
and overcurrent.
Although most computers provide their own internal protection, the fuse provides an extra layer
of protection. If more than 500 mA is applied to the USB port, the fuse will automatically break
the connection until the short or overload is removed.
2.4.3 Differences with other boards
The UNO differs from all preceding boards in that it does not use the FTDI USB-to-serial
driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed
as a USB-to-serial converter.
11
2.4.4 Power
The Uno board can be powered via the USB connection or with an external power supply. The
power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm centre-positive plug into the board's power
jack. Leads from a battery can be inserted in the GND and Vin pin headers of the POWER
connector.
The board can operate on an external supply from 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may become unstable. If
using more than 12V, the voltage regulator may overheat and damage the board. The
recommended range is 7 to 12 volts.
The power pins are as follows:

Vin: The input voltage to the Uno board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if supplying voltage via
the power jack, access it through this pin.

5V: This pin outputs a regulated 5V from the regulator on the board. The board
can be supplied with power either from the DC power jack (7 - 12V), the USB
connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the
5V or 3.3V pins bypasses the regulator, and can damage your board. We don't
advise it.

3V3: A 3.3 volt supply generated by the on-board regulator. Maximum current
draw is 50 mA.

GND: Ground pins.

IOREF: This pin on the Uno board provides the voltage reference with which
the microcontroller operates. A properly configured shield can read the IOREF
pin voltage and select the appropriate power source or enable voltage translators
on the outputs to work with the 5V or 3.3V.
2.4.5 Memory
The ATmega328 has 32 KB (with 0.5 KB occupied by the boot-loader. It also has 2 KB of
SRAM and 1 KB of EEPROM.
12
2.4.6 Input and Output
Each of the 14 digital pins on the Arduino Uno can be used as an input or output, using:
pinmode(), digitalwrite(), and digitalread() functions.
They operate at 5V. Each pin can provide or receive 20mA as recommended operating
condition and has an internal pull-up resistor (disconnected by default) of 20-50k ohm.
A maximum of 40mA is the best value that must not be exceeded on any I/O pin to avoid
permanent damage to the microcontroller.
In addition, some pins have specialized functions:

Serial: Pins 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. These pins are connected to the corresponding pins of the
ATmega8U2 USB-to-TTL Serial chip.

External Interrupts: Pins 2 and 3. These pins can be configured to trigger an
interrupt on a low value, a rising or falling edge, or a change in value.

PWM: Pins 3, 5, 6, 9, 10, and 11. They provide 8-bit PWM output with the
analogWrite() function.

SPI: Pins 10, 11, 12 and 13. These pins support SPI communication using the
SPI library.

LED: Pin 13. There is a built-in LED driven by digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it's off.

TWI: Pins A4 or SDA pin and A5 or SCL pin. Support TWI communication
using the Wire library.
The Arduino UNO has 6 analog inputs, labelled A0 through A5, each of which provide 10 bits
of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though it is possible to change the upper end of their range using the AREF pin and the
analogReference() function.
Other pins on the board include:

AREF Reference voltage for the analog inputs. Used with analogReference().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
13
2.4.7 Communication
Arduino UNO has a number of facilities for communicating with a computer, another Uno
board, or other microcontrollers.
The ATmega328 provides serial communication, which is available on digital pins 0 (RX) and
1 (TX). An ATmega16U2 on the board channels this serial communication over USB and
appears as a virtual com port to software on the computer.
The 16U2 firmware uses the standard USB COM drivers thus reducing the need for an external
driver.
The Arduino Software (IDE) includes a serial monitor which allows simple textual data to be
sent to and from the board. The RX and TX LEDs on the board will flash when data is being
transmitted via the USB-to-serial chip and USB connection to the computer. However, this
may not happen (serial communication) for on pins 0 and 1.
2.5 Embedded Development Cycle
According to Byte Craft Ltd, which is a software development company specializing in
embedded systems software development tools for single-chip microcomputers, the
development process for embedded software follows a seven stage cycle which are:
1. Problem specification
2. Tool/chip selection
3. Software plan
4. Device plan
5. Code/debug
6. Test
7. Integrate
Problem Specification
It is a statement of the problem that your program will solve without considering any possible
solutions. Its main objective is explaining in detail what the program will do.
Once the specification of the problem is complete, the developer must examine the system as
a whole. It is at this point that the developer considers specific needs such as those of interrupt
driven or timing-critical systems.
14
Tool/Chip Selection
At this stage, informed on the need, a chip is selected based on memory size, speed, special
feature availability. Issues such as cost and availability are also investigated at this stage.
Availability of tools impacts the decision to develop with a certain microcontroller. It is
essential to determine if the development decisions a developer makes are possible with the
device he or she is considering. For example, if one wishes to use C language, it is fruitful to
select a device that has a C language compiler. It is also useful to investigate the availability of
emulators, simulators and debuggers.
Software Plan
The first step in the software plan is to select an algorithm which solves the problem specified
in the problem specification stage. It is advisable to consider and compare in terms of code
side, speed, difficulty, and ease of maintenance different algorithms.
Once a basic algorithm is chosen the overall problem should be broken down into smaller
problems which are then solved by different devices (modular programming).
Device Plan
At this stage, the routines for hardware specific features are planned. These routines include:
1) Set up the reset vector
2) Set up the interrupt vectors
3) Watch the stack (hardware or software)
4) Interact with peripherals such as timers, serial ports, and analog-digital converters (ADC).
5) Work with I/O ports
Code/Debug
The modules from the software plan stage are coded in the project language. The coded
modules are compiled or assembled and all syntactic error are repaired.
Testing
Each module should be tested to ensure that it is functioning properly. Testing is done using
simulators and/or emulators. It is also important to test the hardware to be used. This is easily
done by writing small programs which test the devices.
15
Integrate
This is the last stage of embedded development cycle. At this stage, the modules are combined
to create a functioning program. At this point, it is important to test routines which are designed
to respond to specific conditions. These routines include interrupt service and watchdog
support routines. The entire program is thoroughly tested.
16
CHAPTER 3: METHODOLOGY
3.0 Introduction
This chapter consists of project planning, project block diagrams and project description. In
this chapter also, all the methods that were used to implement the project is described.
3.1 Project Planning
The progress and development of the project consists of four main parts. The first part focuses
on detailed literature review regarding the sensor system used in this project, ATmega328
microcontroller and anything related to motion detection.
The next part focuses on hardware, software and the component and equipment that will be
used in this project.
And the third part of this chapter dwells on the programming that will be used for co-ordinated
functions of the piezzo buzzer, LED and the serial monitor with the Arduino Uno (ATmega328
microcontroller).
The last part is on modelling for prototyping and test the system to get the result and fix it if it
the results not just like we want.
17
Literature Review for
devices used in the
project
Finding information on
PIR sensor, piezzo
buzzer and Arduino
UNO microcontroller
Develop source code on
Arduino for the sensor
system, alarm system
and status indicator
Development of the
prototype
Modelling
Study on hardware used
(equipments and
component)
System Testing
Study C language to
write a program
Figure 3.1.1: Project planning flowchart
18
3.2 Project Block Diagram
Figure 3.2.1: Block Diagram for Motion Detector System
3.3 Project Description
This is an endeavour to develop a motion detector component that will be core to further
enhancements for relevance applicability by any user.
PIR Sensor, piezzo buzzer and a computer by use of connectors and a USB cable respectively
will be connected to the Arduino UNO microcontroller.
Piezzo buzzer and the serial monitor will be the output devices for the motion detector as the
Arduino Uno board becomes the central processing module. PIR sensor is the input component.
The serial monitor becomes the status indicator module.
19
Hardware implementation in this project consists of PIR Sensor, piezzo Buzzer, Arduino UNO
microcontroller and a computer. The Atmega328 acts like the interface between the PIR sensor
and the piezzo buzzer, computer and the LED on pin 13 of the Arduino UNO microcontroller
because it is the central processing unit that controls the flow of operation between the input
and output modules.
For the software implementation of this project, Arduino software version 1.5.6-r2 has been
used as programming editor to develop a command to the microcontroller to control the piezzo
buzzer, the LED on the microcontroller and the expected message on the serial monitor.
Arduino software allows a user to program the microcontroller by using the C language.
3.4 The sensor module
The sensor module developed in this project is aimed at extending the ability of the overall
motion detector system by detecting abnormal activities happening within the environment of
the module.
PIR sensor has been picked to implement this project. This is because it allows one to sense
motion, by detecting whether a human has moved in or out of the sensors range. They are small,
inexpensive, low-power, easy to use and don't wear out.
Figure 3.4.1: PIR Sensor (Source: Google Images)
This sensor has a sensitivity range of up to 20feet (6 metres) and a 110°X70° detection range
making it a wide lens detection sensor. This means it can measure 110° vertically (from top)
and 70° horizontally (from left to right). However, the PIR sensor can’t count how many people
are around it or how close they are to the sensor because the lens is often fixed to a certain
sweep.
3.5 The Motion Detector System
The motion sensing system consists of all modules that have been developed; the sensor
system, alarm system and the status indicator system. The serial monitor will be used for status
reporting. The alarm module can be connected either along the board or some distance away
from the microcontroller. The alarm subsystem consists of a piezzo buzzer to make a noise
and LED to give some visual indicator to the user.
20
3.6 Software Development
Figure 3.6.1 below is the flow chart of how the motion detector will work in its programming.
The program will have a continuous looping and will continue to execute according to the flow
chart. The program will initialize at first to make sure all the system ready to be function. The
first program to be executed sensor system then followed by the alarm and status indicator
module which will be executed concurrently.
START
Initialize the Motion
Detector System
Motion
Detected?
NO
YES
Piezzo buzzer beep
LED Light ON
Print on Serial Monitor
STOP
Figure 3.6.1 Flowchart for the motion detector system
21
3.7 Programming Tools
The software design for the motion detector system was programed by use of Arduino 1.5.6-r2
software.
The software was first downloaded from the Arduino website (www.arduino.cc) and was then
installed. See Figure 3.7.1 below.
Figure 3.7.1: Loading of Arduino Software
Arduino UNO microcontroller was then connected to the computer via a USB cable, then
followed selection of the microcontroller from the ‘Tools Tab’ and lastly selection of COM 29
from the same tab as shown below in Figure 3.7.2, Figure 3.7.3 and Figure 3.7.4 respectively.
Figure 3.7.2 Configuration for connecting the Arduino UNO microcontroller with a
computer. (Source: Google Images)
22
Figure 3.7.3: Selecting the Arduino UNO Board
Figure 3.7.4: Selecting COM29 port
Thereafter, an Arduino program was loaded on the microcontroller so as to test its functionality
as shown in Figure 3.7.5.
23
Figure 3.7.5: Programming Motion Detector system using Arduino Software
The figure above shows the source code that I developed using the Arduino software. I used C
programming language because it’s easy to understand and that it’s also easier detect a mistake
from the program. In comparison to Assembly language that requires the programmer to know
the inside structure of the microcontroller, C language offers more specific coding and
programs that run on C language are a lot faster than using assembly language.
The advantage with Arduino software is, it can support either Assembly language or C
language thereby giving the user an opportunity to choose the language he or she wants to use.
What followed next was loading the source code to the Arduino UNO by clicking the ‘Upload’
button on the Arduino Software as shown below.
24
Figure 3.7.6: Uploading the Source Code to the Arduino
When upload was successful, the LED on Pin 13 on the Arduino UNO board blinked twice.
Thereafter, I connected the PIR Sensor, piezzo buzzer to the Arduino UNO board. I powered
the Arduino UNO via the USB cable connecting the computer and the board.
Figure 3.7.7: PIR Sensor and Piezzo Buzzer connected to the Arduino UNO
25
3.7.1 Connecting PIR sensor to the Arduino UNO Board
Pin1 of the PIR Sensor is connected to the 5V DC voltage terminal of the Arduino UNO. Pin3
is connected to the ground (GND) pin of the Arduino UNO. Pin2 connects to digital Pin D3.
Here, Pins 1 and 3 are powered with 5V by the Arduino UNO, i.e. it is through these pins
connections that the PIR sensor gets the 5V that it needs to power on and operate.
It is through Pin2 that that the Arduino UNO receives output from the PIR sensor.
3.7.2 Connecting the Piezzo buzzer to the Arduino UNO
The anode terminal (Red cable) of the buzzer is connected to Pin13 of the Arduino UNO
whereas its cathode (black) is connected to the ground (GND) pin of the buzzer.
Figure 3.7.2.1: Piezzo Buzzer Source: Google Images
Piezzo buzzer has the capability of reading analog signals through its analog-digital convertor
(ADC).
26
CHAPTER 4: RESULTS AND DISCUSSION
4.1 Introduction
This chapter contains the results and discussion from the hardware and software part of the
project that have been implemented on the motion detector system. Figure 4.1.1 below shows
the overall system that has been integrated together.
Figure 4.1.1: The Motion Detector System
4.2 Testing development
After successful implementation of the sensor module and the alarm module, with the Arduino
UNO microcontroller to make the motion detector system, the project continued to the next
stage; the testing phase. Project testing will concentrate on several aspects according to
functionality and reliability. This facet is of importance to this project because it will determine
whether this project has achieved its objective or not. This testing development unit will also
involve hardware and software part of the project. Figure 4.2.1 below show the flowchart for
testing phase of the project.
27
Start
Initialize motion detector system
Is the
sensor
system
working?
NO
Fix coding and
connection for the PIR
Sensor
YES
Is the
alarm
system
working?
NO
Fix coding and
connection for the
Piezzo Buzzer
YES
Is the
status
indicator
system
working?
NO
Fix coding of serial
monitor
YES
End Testing
Figure 4.2.1 Project testing flowchart
28
4.2.1 Testing the sensor module
The PIR sensor was connected on the Arduino UNO microcontroller board as stated in section
3.7.1 above. Thereafter, a USB cable was used to connect the Arduino UNO microcontroller
to the computer.
A sample code to test the functionality of the PIR sensor was uploaded to the microcontroller.
Whenever motion was detected, the LED Pin on the Arduino UNO microcontroller blinked for
five seconds before going off. When no motion was detected, the LED pin did not light.
Figure 4.2.1.2: Testing the PIR Sensor. Note that the black cable of the Piezzo Buzzer isn’t
connected to the Arduino UNO
4.2.2 Testing the alarm module
The piezzo buzzer was connected on the Arduino UNO microcontroller as stated in section
3.7.2 in the methodology chapter. Thereafter, a USB cable was used to connect the Arduino
UNO microcontroller board to the computer.
A sample code to test the functionality of the buzzer was uploaded to the microcontroller to
test its functionality in seamless concurrence with the PIR Sensor.
Again, whenever motion was detected, the piezzo buzzer beeped for five seconds before going
off. At LED Pin also lit for five seconds. When no motion was detected, it didn’t beep and the
LED Pin didn’t light.
29
Figure 4.2.2.2: Testing the Piezzo Buzzer
4.2.3 Testing the status indicator module
To enhance the efficiency and effectiveness of the system, a status indicator component was
needed. To achieve this, a serial monitor ability from the Arduino software was employed. The
serial monitor acts as a virtual monitor to the Arduino UNO microcontroller making it print a
pre-programmed message on it.
Only the printing command was added to the existing source code. The program was later
uploaded to the Arduino UNO board.
As programmed, anytime motion was detected, the piezzo buzzer beeped for five seconds, the
LED pin on the Arduino UNO board lit for the same time and “MOTION DETECTED”
message was printed on the serial monitor once.
When no motion was detected, the piezzo buzzer didn’t beep, the LED on the Arduino UNO
board did not light and no message was printed on the serial monitor.
30
Figure 4.2.3.2: Motion detector system and serial monitor
4.3 Discussion
When the PIR sensor detects an obstacle within its detection range, it picks the analog signal
then converts it to a digital signal which it then passes it to the Arduino Uno board as a voltage
signal. The received digital signal, whose status is HIGH (3volts), triggers the LED installed
on its Pin13 to light and the piezzo buzzer connected on the same pin to buzz. At the same
time, the message ‘MOTION DETECTED’ is printed on the serial monitor once.
When no motion is detected, the output from the PIR Sensor is low and gives off practically
no voltage signal. It is through Pin2 of the PIR Sensor that the Arduino receives output from
the PIR sensor in form of an electric signal.
The lines of code below controls the behaviour of the LED pin, piezzo buzzer and the serial
monitor:
void loop() {
value = digitalRead(switchPin);
if (HIGH == value) {
digitalWrite(ledPin, HIGH);
digitalWrite (buzzerPin,HIGH);
Serial.println ("MOTION DETECTED");
delay (10000);
counter++;
Serial.println(counter);
}
Serial.println (“MOTION DETECTED”);
else {
digitalWrite(ledPin, LOW);
}
31
I used C programming language because it’s easy to understand and that it’s also easier detect
a mistake from the program. In comparison to Assembly language that requires the programmer
to know the inside structure of the microcontroller, C language offers more specific coding and
programs that run on C language are a lot faster than using assembly language.
The advantage with Arduino software is, it can support either Assembly language or C
language thereby giving the user an opportunity to choose the language he or she wants to use.
4.4 Project Justification of Results
From the results above i.e. from the sensor module, alarm module and status indicator module
that I got after testing the motion detector system, I can conclude that the development of
simple motion detector component was successful.
Even though I encountered some problems in testing the system, the flow chart that I developed
for testing the system was very useful as it gave me less time to debug the system. Also, the
flow chart gave me an easier way to detect any mistake and corrected it relevantly.
32
CHAPTER 5: CONCLUSION AND RECOMMENDATIONS
5.1 Conclusion
The task for developing the motion sensor system using infrared technology was successful
and achieved the objective for the overall project.
From this project, I can confirm that infrared technology is key in motion sensing. The alarm
module and the status indicator component helped make the system more efficient as the
Arduino UNO microcontroller played the central processing unit (CPU) role.
To enable coordinated functioning of the various components of the system, the
microcontroller ATmega328 on the Arduino UNO microcontroller board was programmed to
execute commands for the piezzo buzzer, LED pin and the serial monitor.
The potential application of this technology in future is relevant in security, tallying and can
be enhanced further into imaging technology at a more reliable and cheaper cost.
The serial monitor in the project was as a platform to give readable notifications.
5.2 Obstacles encountered in the project.
When making something new, it’s obvious that one faces several problems. The first problem
that I encountered was making the PIR Sensor work with the Arduino UNO board and also
making all the components work in a coordinated manner.
The hardest part on the project was in the programming part because I ventured into embedded
programming, a fact that made me to tirelessly read and practice this unique, fairly hard but
interesting nerve of systems development. It was a challenge making mechanical devices work
and on several occasions I had to consult Titus Koech, a friend who takes BEng. Electrical and
Communications Engineering from the School of Engineering in order to understand circuits.
33
It was a challenge working on the project with borrowed devices from a friend who at the same
time was also working on his project. This is because of the cost, especially of the Arduino
UNO board as very few retailers of electronics are aware of it and they only make few
purchases thus making them increase its buying price.
5.3 Recommendations for the project.
With the results that have successfully been got after testing the system, there are several
recommendations that can make the motion detector system more reliable and efficient for the
future.
1. Use of GSM Modem: This will increase the ability of remotely receiving a notification
and controlling a set of actions. For example, if used in a home, the user can make the
system switch on a CD player that will create an impression that someone is inside the
house.
2. Making GUI (Graphical User Interface): To make this motion sensor system more
user friendly.
3. Using a more powerful sensor: It will enhance the system by giving it the counting
ability.
4. Using spy Cameras: For taking pictures that will be sent to the user in order to know
the kind of object that has been detected within the detection range.
5. Using an ultrasonic-sensor: For distance measuring capability.
34
REFERENCES
Byte Craft Limited. First Steps in Embedded Systems, Ontario: 2002. Available
www.bytecraft.com 18th April, 2016.
Collins, M., “An Evaluation of Embedded System Behavior Using Full-System Software
Emulation” Msc. Thesis. University of Maryland, College Park, 2000.
Gwennap, L., "New Processor Paradigm: V-IRAM." Journal of Microprocessor Report, Vol.
12, No. 3 (1998) pp. 17-19.
Kozyrakis, C., et al. "Scalable Processors in the Billion-Transistor Era: IRAM." IEEE
Computer, Vol. 30, No. 9, (1997) pp. 75-78.
Smith, M.. Application-Specific Integrated Circuits. Addison-Wesley: Reading,
Massachusetts, 1997.
Stepner, D., et al. “Embedded application design using a real-time OS.” DAC 99: New
Orleans LA, 1999.
Internet Sources
Cerruti, L.,"Dante's Bones." Archimedes; The Sciences in the European Periphery During the
Enlightenment, (1995) pp. 95-178.
Motion Sensors. Illumin. Hp. 2007. Motion Sensors. Furnish, T., Available
www.illumin.usc.edu 9th Dec.2015
History of Motion Detectors. Hp. 2014. Heubsch, Russel., Available
www.ehow.com/about_5516868_history-motion-detectors.html 11th Dec 2015
www.media.digikey.com/pdf/data%20sheets/panasonic%20electric%20works%20pdfs/amn
%20design%20manual.pdf
www.arduino.cc
35
BIBLIOGRAPHY
Abeni, L., and Buttazzo, G., "Integrating multimedia applications into hard real-time
systems." In Proc. IEEE Real-Time Systems Symposium (RTSS), 1998.
Adafruit Learning Systems. PIR Motion Sensor Created by Lady Ada. Available
www.learn.adafruit.com 30th March, 2016.
Ball. S., Embedded Microprocessor Systems: Real-World Design. Newnes: ButterworthHeinemann, Boston MA, 1996.
Ganssle, J. G., "The challenges of real-time programming." Embedded Systems
Programming, Vol. 11, No. 7, (1997) pp. 20-26.
Kalinsky, D., "A survey of task schedulers." In Embedded Systems Conference. San Jose CA,
1999.
Lee, A., and Seshia, A., Introduction to Embedded Systems: A Cyber-Physical Systems
Approach. UC Berkley, 2011. Available www.leeseshia.org 16th March 2016.
Liu, J., Real-Time Systems. Prentice Hall: Upper Saddle River NJ, 2000.
Samingan B.L., “Radio Frequency Identification and Global System for Mobile
Communication Application for Anti- Theft Car Security System”. Bsc. Thesis. Universiti
Teknologi Malaysia, Skudai, 2014.
36
APPENDICES
APPENDIX I: System Source Code
/*Motion Detector Code Developed by Francis Omondi Bsc. Information Sciences
For
more
information,
Call
0728
521
742
or
Email
omondi.francis@students.mu.ac.ke */
int ledPin = 13; // Pin 13 is set as output.default LED pin of ArduinoUno
int switchPin = 2; //Pin 2 is set asINPUT pint for motion detected.
int buzzerPin=13; // Pin 13 is set as output terminal. Buzzer connected here
int value = 0;
// Initialization i.e no motion detected
int counter; // variable for counting the number of times motion is detected
void setup() {
// Setup code for the system. Runs once only
pinMode(ledPin, OUTPUT);
// output point of LED in this case Pin 13
pinMode(switchPin, INPUT);
// Input point of PIR sensor
pinMode (buzzerPin, OUTPUT); // output point of Piezzo Buzzer
Serial.begin (9600);
}
/* This loop part will run over and over again as long as the Arduino has
power*/
/* this block of code reads the input value and assigns it to the integer
value.*/
void loop() {
value = digitalRead(switchPin);
if (HIGH == value) {
// HIGH means motion detected
digitalWrite(ledPin, HIGH);
// LED Lights for 5 seconds
digitalWrite (buzzerPin,HIGH);
// Buzzer buzzes for 5 seconds
Serial.println ("MOTION DETECTED");
delay (10000);
//Waits for 10seconds but is adjustable. Syntax 1000ms=1sec
counter++;
Serial.println(counter);
}
else {
digitalWrite(ledPin, LOW); //LOW means no motion detected, LED & Buzzer off
}
}
37
APPENDIX II: SOURCE CODE TO TEST PIR SENSOR
int ledPin = 13;
int switchPin = 2;
int value = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
value = digitalRead(switchPin);
if (HIGH == value) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
APPENBIX III: SOURCE CODETO TEST PIEZZO BUZZER
int ledPin = 13;
int switchPin = 2;
int buzzerPin=13;
int value = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode (buzzerPin, OUTPUT);
}
void loop() {
value = digitalRead(switchPin);
if (HIGH == value) {
digitalWrite(ledPin, HIGH);
digitalWrite (buzzerPin,HIGH); //Buzzer buzzes for 5 seconds
}
else {
digitalWrite(ledPin, LOW);
}
}
38
APPENDIX IV: CIRCUIT DIAGRAM OF FULL CONNECTION
APPENDIX V: SERIAL MONITOR SHOWING SEVEN COUNTS OF MOTION
DETECTION
Download