Major Project b10

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 72

A

Major Project Report on

GSM-BASED SMART HELMET DROWSY DETECTION SYSTEM

Submitted for partial fulfilment of the requirements for the award of the degree of

BACHELOR OF TECHNOLOGY

In

ELECTRONICS AND COMMUNICATION ENGINEERING


By

MAHENDAR REDDY KONGOLLA 20K81A0492


NITHIN REDDY SAMA 20K81A04A6
NAVEEN REDDY VENNAPUREDDY 20K81A04B8
CHAITANYA REDDY YEMPALLA 20K81A04B9

Under the Guidance of

Dr.M.Tirupathi

Associate Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

St. MARTIN'S ENGINEERING COLLEGE


UGC Autonomous
Affiliated to JNTUH, Approved by AICTE,
Accredited by NBA & NAAC A+, ISO 9001:2008
Certified
Dhulapally, Secunderabad - 500 100
www.smec.ac.in

March - 2024
St. MARTIN'S ENGINEERING COLLEGE
UGC Autonomous
NBA& NAAC A+ Accredited
Dhulapally, Secunderabad - 500
100

Certificate

This is to certify that the project entitled “GSM-BASED SMART HELMET


DROWSY DETECTION SYSTE” is being submitted by K.MAHENDAR
REDDY(20K81A0492), S.NITHIN REDDY (20K81A04A6),V.NAVEEN R
EDDY (20K81A04B8), Y. CHAITANYA REDDY (20K81A04B9) in fulfilm
ent of the requirement for the award of degree of BACHELOR OF TEC
HNOLOGY IN ELECTRONICS AND COMMUNICATION ENGINN
ERING is recorded of bonafide work carried out by them.The result embodied
in this report have been verified and found satisfacto.

Signature of Guide Signature Head of the Department


Dr.M.Thirupathi Dr. B. Hari Krishna
Assistant Professor Professor & Head
Department of ECE Department of ECE

Internal Examiner External Examiner

Date:

Place:
St. MARTIN'S ENGINEERING COLLEGE
UGC Autonomous
NBA& NAAC A+ Accredited
Dhulapally, Secunderabad - 500
100
www.smec.ac.in
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
ENGINEERING

DECLARATION

We, the students of ‘Bachelor of Technology in Department of Electronics and


Communication Engineering’, session: 2020 - 2024, St. Martin’s Engineering
College, Dhulapally, Kompally, Secunderabad, hereby declare that the work
presented in this Project Work entitiled GSM-BASED SMART HELMET
DROWSY DETECTION SYSTEM is the outcome of our own bonafide work
and is correct to the best of our knowledge and this work has been undertaken
taking care of Engineering Ethics. The result embodied in this project report has
not been submitted in any university for award of any degree.

1.Mahendar Reddy Kongolla (20K81A04A8)

2.Nithin Reddy Sama (20K81A0495)

3.Naveen Reddy Vennapureddy (20K81A0490)

4.Chaithanya Reddy Yempalla (20K81A0493)


ACKNOWLEDGEMENT

The satisfaction and euphoria that accompanies the successful completion of


any task would be incomplete without the mention of the people who made it possible
and whose encouragement and guidance have crowded our efforts with success.

First and foremost, we would like to express our deep sense of gratitude and
indebtedness to our College Management for their kind support and permission to use
the facilities available in the Institute.

We especially would like to express our deep sense of gratitude and


indebtedness to Dr. P. SANTOSH KUMAR PATRA, Group Director, St. Martin’s
Engineering College Dhulapally, for permitting us to undertake this project.

We wish to record our profound gratitude to Dr. M. SREENIVAS RAO,


Principal, St. Martin’s Engineering College, for his motivation and encouragement.

We are also thankful to Dr. B. HARI KRISHNA, Head of the Department,


Electronics and communication engineering, St. Martin’s Engineering College,
Dhulapally, Secunderabad. for his support and guidance throughout our project as well
as Project Coordinator Mr. Venkanna Mood Naik, associate professor, department of
Electronics and Communication Engineering, department for his valuable support.

We would like to express our sincere gratitude and indebtedness to our project supervisor
Dr.M.Thirupathi assistant Professor, electronics and communication engineering, St. Martins
Engineering College, Dhulapally, for his support and guidance throughout our project.

Finally, we express thanks to all those who have helped us successfully


completing this project. Furthermore, we would like to thank our family and friends for
their moral support and encouragement. We express thanks to all those who have
helped us in successfully completing the project.

K.MAHENDAR 20K81A0492

S.NITHIN REDDY 20K81A04A6

V. NAVEEN 20K81A04B8

Y.CHAITHANYA 20K81A04B9

i
ABSTRACT

The abstract describes a Smart Helmet for Drowsy Detection System incorporating
advanced technologies such as GPS, GSM, ESP CAM, and a Vibration Sensor. This
innovative helmet aims to enhance road safety by detecting and preventing instances of
drowsiness in the wearer. The GPS technology enables real-time location tracking, while
GSM facilitates instant communication capabilities. The integration of ESP CAM provides
visual data for analysis. Additionally, a Vibration Sensor is employed for accurate
drowsiness detection. When drowsiness is detected, the system triggers an alert, ensuring
timely intervention to prevent potential accidents. This Smart Helmet represents a
comprehensive solution for promoting road safety through the fusion of cutting-edge
technologies.

ii
LIST OF FIGURES

Figure No. Figure Title Page No.

4.1 Proposed block diagram 27

4.2 Schematic pin Diagram 31

5.1 A modern example of embedded system 31

5.3.4 Network communication embedded systems 32

5.3 Automatic coffee makes equipment 32

4.3.4.1 Fax machine 33

4.3.4.2 Printing machine 34


Robot
4.3.4.3 35

4.4 Computer networking 36

4.4.2.1 Cell Phone 38

4.4.2.2 Web camera 38

6.10.2 Microcontrollers 57

6.10.3 Architecture 58

7.2 ARDUINO Development Board 64

7.3.1 crystal oscillator 65

7.3.2 AVR Architecture 65

7.3.3 PIN DIAGRAM OF ATMEGA328 66

7.3.4 PIN DIAGRAM OF ATMEGA328 66

7.3.5 Block diagram of power supply 67


Power supply circuit diagram
7.3.6 67
7.3.7 Regulated Power Supply 68
Circuit diagram of Regulated Power Supply with Led
connection
Bridge rectifier: a full-wave rectifier using 4 diodes
DB107
Construction Of a Capacitor
Electrolytic
Voltage regulator
Resistor
Color Bands In Resistor
Inside a LED
Parts of a LED
Picture of buzzer
LCD Pin diagram
Global System for Mobile Communication (GSM)
Global Positioning System
Mercury switch
D.C. Motor
Simple electrical diagram of DC motor

Operation of a DC Motor
Diagram of DC shunt motor
Diagram of DC series motor
Diagram of DC series motor graph representation
Diagram of DC compound motor
ESP32-CAM
ESP32-CAM Pinout

iii
LIST OF TABLES

Table Table Name Page No.


No.
6.9 Character LCD pins with Microcontroller 18

iv
CONTENTS

ACKNOWLEDGEMENT i

ABSTRACT ii
LIST OF iii
FIGURES LIST iv
OF TABLES
CHAPTER 1 INTRODUCTION 1
1.1 GPS Technology
1.2 GSM Communication
1.3 ESP CAM for Visual Data
1.4 Vibration Sensor for Drowsiness Detection

CHAPTER 2 LITERATURE SURVEY 5

CHAPTER 3 EXISTING SYSTEM 24

CHAPTER 4 PROPOSED METHOD 27


CHAPTER 5 EMBEDDED SYSTEMS 39

5.1 Embedded Systems 39


5.2 Need For Embedded Systems 39
5.3 Explanation of Embedded Systems 40
5.4 APPLICATIONS OF EMBEDDED SYSTEMS 40
CHAPTER 6 HARDWARE DESCRIPTION 47
Micro controller
6.1 47
6.2 AVR-ARDUINO MICROCONTROLLER 47
6.3 Crystal Oscillator 49
6.4 Architecture 50
6.5 Microcontroller 51
6.6 Regulated Power Supply 52
6.7 Purpose 52
6.8 Python 53
6.9 Modules used in project 53
6.10 How to Install Python on windows and Mac 56
6.10.1 Installation of Python 59
6.10.2 Verify the Python Installation 60
6.10.3 Check how the python IDLE works 61
CHAPTER 7 RESULTS AND DISCUSSIONS 63
7.1 Implementation Description 63
7.2 Dataset Description 64
7.3 Results Description 65
CHAPTER 8 CONCLUSION 70
Future scope 70
References 71
APPENDIX 72
CHAPTER 1
INTRODUCTION

Introduction:

In recent years, the increasing prevalence of road accidents has underscored the urgent need for innovative
solutions to enhance road safety. Among the various contributing factors to accidents, driver drowsiness
stands out as a significant concern. Fatigue-related incidents can lead to delayed reaction times and
impaired decision-making, posing a serious threat to both drivers and others on the road. In response to
this critical issue, the development of a Smart Helmet for Drowsy Detection System has emerged as a
promising solution, integrating cutting-edge technologies to mitigate the risks associated with drowsy
driving.
Road safety has been a global concern, with millions of lives lost and injuries sustained each year due to
traffic accidents. The World Health Organization (WHO) reports that road traffic injuries are a leading
cause of death for individuals aged 15 to 29 years. Among the various factors contributing to accidents,
driver fatigue and drowsiness have gained significant attention for their adverse effects on driving
performance. The National Highway Traffic Safety Administration (NHTSA) estimates that drowsy
driving results in thousands of crashes annually in the United States alone.

Traditional approaches to address drowsy driving have included awareness campaigns, regulations on
driving hours for commercial drivers, and periodic breaks during long journeys. However, the limitations
of these strategies have prompted the exploration of technological interventions to actively detect and
prevent drowsiness in real-time. The integration of emerging technologies, such as GPS, GSM, ESP CAM,
and Vibration Sensors, into a Smart Helmet presents a multifaceted solution to tackle this pervasive issue.

The primary objective of this project is to design, develop, and implement a Smart Helmet for Drowsy
Detection System that leverages state-of-the-art technologies. The helmet aims to go beyond traditional
methods by providing a proactive approach to mitigate the risks associated with driver drowsiness. The
incorporation of GPS enables real-time location tracking, while GSM ensures instant communication
capabilities. The integration of ESP CAM introduces visual data for comprehensive analysis, and a
Vibration Sensor serves as a reliable mechanism for detecting signs of drowsiness.
The significance of this project lies in its potential to significantly reduce road accidents caused by drowsy
driving. By creating a wearable device that actively monitors the driver's state and triggers alerts in the
presence of drowsiness, the Smart Helmet seeks to enhance overall road safety. The use of advanced
technologies ensures a comprehensive and real-time approach, offering a level of sophistication not
achievable with conventional methods.

1. GPS Technology:
The incorporation of GPS technology in the Smart Helmet serves as a foundational element for the project.
GPS allows for precise real-time location tracking of the wearer. This feature not only contributes to
overall safety by enabling tracking and monitoring but also facilitates additional functionalities, such as
route optimization and emergency location sharing in the event of an accident.

2. GSM Communication:
The integration of GSM communication in the Smart Helmet enables seamless connectivity. Through
GSM, the helmet can transmit data, receive commands, and send alerts to predefined contacts. In situations
where the system detects signs of drowsiness, the GSM module plays a crucial role in notifying relevant
parties, such as emergency services or designated contacts of the wearer.

3. ESP CAM for Visual Data:


The ESP CAM module enhances the capabilities of the Smart Helmet by introducing visual data. This
component comprises a camera system capable of capturing and transmitting images or video footage. The
visual data can be instrumental in assessing the wearer's condition, validating instances of drowsiness, and
providing additional context for analysis.

4. Vibration Sensor for Drowsiness Detection:


A Vibration Sensor is a key component designed to detect subtle signs of drowsiness. Placed strategically
within the helmet, the sensor monitors head movements and vibrations associated with drowsiness or
fatigue. When the sensor identifies patterns indicative of drowsiness, the system activates a series of
predefined responses, such as alerts, vibrations, or visual cues, to bring the wearer's attention back to an
alert state.

The innovative integration of GPS, GSM, ESP CAM, and Vibration Sensor technologies in the Smart
Helmet for Drowsy Detection System represents a significant leap forward in addressing the challenges
posed by drowsy driving. The combination of these advanced components creates a comprehensive and
proactive solution, moving beyond reactive approaches to actively prevent potential accidents.

Unlike traditional methods that rely on reactive measures after drowsiness has already set in, the Smart
Helmet takes a proactive approach. By continuously monitoring the wearer's condition through the
Vibration Sensor and utilizing real-time data from GPS and GSM modules, the system can detect early
signs of drowsiness. This allows for timely intervention, preventing accidents before they occur.

The inclusion of GSM technology ensures real-time communication capabilities for the Smart Helmet. In
the event of detected drowsiness, the system can instantly send alerts to predefined contacts, enabling
prompt assistance. This real-time communication feature is crucial for enhancing the effectiveness of the
helmet as a preventive safety measure.

The ESP CAM module introduces a visual element to the drowsy detection system, offering an additional
layer of data for analysis. The captured images or video footage can be used to corroborate signs of
drowsiness detected by the Vibration Sensor. This comprehensive data analysis contributes to the accuracy
of the system in identifying and responding to drowsiness.

The Smart Helmet is designed to be wearable and user-friendly, ensuring widespread acceptance and
adoption. The integration of advanced technologies does not compromise the comfort or usability of the
helmet. The aim is to create a device that seamlessly integrates into the routine of drivers, providing an
unobtrusive yet effective solution for drowsiness detection.
CHAPTER 2
LITERATURE SURVEY

The system automatically detects motorcycle riders and determines that they are wearing safety helmets or
not. The system extracts moving objects and classifies them as a motorcycle or other moving objects based
on features extracted from their region properties using K-Nearest Neighbour (KNN) classifier. The heads
of the riders on the recognized motorcycle are then counted and segmented based on projection profiling.
The system classifies the head as wearing a helmet or not using KNN based on features derived from 4
sections of segmented head region. Experiment results show an average correct detection rate for near
lane, far lane, and both lanes as 84%, 68%, and 74%, respectively [3]. The helmet is the main safety
equipment of motorcyclists, but many drivers do not use it. If an motorcyclist is without helmet an
accident can be fatal. This paper aims to explain and illustrate an automatic method for motorcycles
detection and classification on public roads and a system for automatic detection of motorcyclists without
helmet. For this, a hybrid descriptor for features extraction is proposed based in Local Binary Pattern,
Histograms of Oriented Gradients and the Hough Transform descriptors. Traffic images captured by
cameras were used [4]. It is known that head gesture and brain activity can reflect some human behaviours
related to a risk of accident when using machine-tools. The research presented in this paper aims at
reducing the risk of injury and thus increase worker safety. Instead of using camera, this paper presents a
Smart Safety Helmet (SSH) in order to track the head gestures and the brain activity of the worker to
recognize anomalous behavior. Information extracted from SSH is used for computing risk of an accident
(a safety level) for preventing and reducing injuries or accidents. The SSH system is an inexpensive, non-
intrusive, non- invasive, and non-vision-based system, which consists of an Inertial Measurement Unit
(IMU) and dry EEG electrodes. A heptic device, such as vibrotactile motor, is integrated to the helmet in
order to alert the operator when computed risk level (fatigue, high stress or error) reaches a threshold.
Once the risk level of accident breaks the threshold, a signal will be sent wirelessly to stop the relevant
machine tool or process[5]. A smart helmet is a special idea which makes motorcycle driving safer than
before. This is implemented using GSM and GPS technology. The working of this smart helmet is very
simple, vibration sensors are placed in different places of helmet where the probability of hitting is more
which are connected to microcontroller board. So when the rider crashes and the helmet hit the ground,
these sensors sense and gives to the microcontroller board, then controller extract GPS data using the GPS
module that is interfaced to it. When the data exceeds minimum stress limit then GSM module
automatically sends message to ambulance or family members[6]. This project is specially developed as to
improve the safety of the motorcycle’s rider. Motorcyclist will be alarmed when the speed limit is
exceeded. A Force Sensing Resistor (FSR) and BLDC Fan are used for detection of the rider’s head and
detection of motorcycle’s speed respectively. A 315 MHz Radio Frequency Module as wireless link which
able to communicate between transmitter circuit and receiver circuit. PIC16F84a is a microcontroller to
control the entire component in the system. Only when the rider buckled the helmet then only the
motorcycle’s engine will start. A LED will flash if the motor speed exceeds 100 km/hour[7]. Intelligent
Safety Helmet for Motorcyclist is a project undertaken to increase the rate of road safety among
motorcyclists. The idea is obtained after knowing that the increasing number of fatal road accidents over
the years is cause for concern among motorcyclists. Through the study identified, it is caused the helmets
used is not in safety features such as not wearing a helmet string and not use the appropriate size.
Therefore, this project is designed to introduce security systems for the motorcyclist to wear the helmet
properly. With the use of RF transmitter and RF receiver circuit, the motorcycle can move if there is
emission signal from the helmet, in accordance with the project title Intelligent Safety Helmet for
Motorcyclist. Security system applied in this project meet the characteristics of a perfect rider and the
application should be highlighted. The project is expected to improve safety and reduce accidents,
especially fatal to the motorcyclist[8].
CHAPTER 3
EXISTING SYSTEM

In the current state of helmet technology, there is a notable absence of systems designed to detect the
drowsiness of the rider. In traditional helmets, the onus is entirely on the rider to recognize signs of
drowsiness and take proactive measures, such as pulling over to rest. This inherent reliance on the rider's
self-awareness introduces a potential safety gap.

Under the existing paradigm, riders must personally acknowledge their drowsy state, and failure to do so
could have severe consequences, possibly resulting in accidents. The lack of a built-in mechanism for
detecting drowsiness means that riders may unknowingly jeopardize their safety and the safety of others
on the road. The reliance on self-identification poses a considerable risk, especially in situations where
fatigue or drowsiness may impair the rider's judgment or reaction time without their awareness.
Consequently, the need for a technological intervention that can autonomously and proactively detect
drowsiness becomes increasingly evident.

The absence of a drowsiness detection system in conventional helmets underscores the critical need for
innovation in helmet design and safety technology. By introducing a Smart Helmet equipped with
advanced features like a Vibration Sensor, GPS, GSM, and ESP CAM, the proposed solution aims to
bridge this gap and significantly enhance rider safety by addressing the limitations of the current helmet
systems. This shift from passive reliance on rider awareness to an active, technology-driven approach
represents a crucial step towards preventing accidents caused by drowsy riding.
CHAPTER 4
PROPOSED SYSTEMS
The provided diagram illustrates the block components of the Smart Helmet Drowsiness Detection
System. This intricate system encompasses crucial elements such as a regulated power supply, vibration
sensor, GPS module, GSM modem, ESP Cam, drowsy detection sensor, LCD display, buzzer, and a DC
motor. Central to the control and coordination of this multifaceted system is the Raspberry Pi Pico
microcontroller.

The ESP Cam, in conjunction with the drowsy detection sensor, plays a pivotal role in identifying signs of
drowsiness in the rider. Simultaneously, the vibration sensor is employed to detect subtle movements or
irregularities. In the event of an accident or if the system detects the rider's drowsiness, a series of
synchronized actions are triggered.

A distinctive feature of this system is the integration of safety mechanisms. Upon detection of an accident
or drowsiness, the buzzer activates, conveying an audible alert to the rider. Additionally, relevant
information is displayed on the LCD screen. Furthermore, a proactive safety measure involves sending an
SMS alert to a pre-registered contact, providing real-time location information.

In the unfortunate event of a collision, the system incorporates an engine cut-off mechanism. This
immediate response adds an extra layer of safety by preventing further movement of the bike post-
accident. The comprehensive design of the Smart Helmet Drowsiness Detection System ensures a swift
and synchronized reaction to potential threats, amalgamating advanced technologies for an enhanced level
of rider safety and accident prevention.

Schematic Pin Diagram:


This is the pin diagram where all the hardware components are been connected components. This
ARDUINO microcontroller has 28 pins. In which 14 GPIO pins as digital pins and 6 GPIO pins. 16MHz
crystal oscillator connected internally. The step-down transformer, Bridge rectifier capacitor with 1000f
Resisters and LED are connected to a Regulated power supply which provides the 5v to the Arduino and
all input/output modules.
16*2 LCD Monitor is connected with the Digital pins 2, 3, 4, 5, 6, 7.
IOT ESP cam is connected to Digital Pins D0, D1 internal Transmitter and receiver pins.
DC motor is connected to D8 pin of the Arduino microcontroller.
Vibration sensor is connected to D9 pin of the Arduino microcontroller.
Eye blink sensor is connected to A0 pin of the Arduino microcontroller.
GSM is connected to pins A4 and A5 of the Arduino microcontroller.
Buzzer alarm connected to digital pin 13 of the Arduino microcontroller.
CHAPTER 5
EMBEDDED SYSTEMS

5.1 Embedded Systems:


An embedded system is a computer system designed to perform one or a few dedicated
functions often with real-time computing constraints. It is embedded as part of a complete device often
including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal
computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems
control many devices in common use today.
Embedded systems are controlled by one or more main processing cores that are typically
either microcontrollers or digital signal processors (DSP). The key characteristic, however, is being
dedicated to handle a particular task, which may require very powerful processors. For example, air traffic
control systems may usefully be viewed as embedded, even though they involve mainframe computers and
dedicated regional and national networks between airports and radar sites. (Each radar probably includes
one or more embedded systems of its own.)
Since the embedded system is dedicated to specific tasks, design engineers can optimize it to
reduce the size and cost of the product and increase the reliability and performance. Some embedded
systems are mass-produced, benefiting from economies of scale.
Physically embedded systems range from portable devices such as digital watches and MP3
players, to large stationary installations like traffic lights, factory controllers, or the systems controlling
nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with
multiple units, peripherals and networks mounted inside a large chassis or enclosure.
In general, "embedded system" is not a strictly definable term, as most systems have some
element of extensibility or programmability. For example, handheld computers share some elements with
embedded systems such as the operating systems and microprocessors which power them, but they allow
different applications to be loaded and peripherals to be connected. Moreover, even systems which don't
expose programmability as a primary feature generally need to support software updates. On a continuum
from "general purpose" to "embedded", large application systems will have subcomponents at most points
even if the system as a whole is "designed to perform one or a few dedicated functions", and is thus
appropriate to call "embedded". A modern example of embedded system is shown in fig: 2.1.

Fig 5.1:A modern example of embedded system


Labeled parts include microprocessor (4), RAM (6), flash memory (7).Embedded systems
programming is not like normal PC programming. In many ways, programming for an embedded system is
like programming PC 15 years ago. The hardware for the system is usually chosen to make the device as
cheap as possible. Spending an extra dollar a unit in order to make things easier to program can cost
millions. Hiring a programmer for an extra month is cheap in comparison. This means the programmer
must make do with slow processors and low memory, while at the same time battling a need for efficiency
not seen in most PC applications. Below is a list of issues specific to the embedded field.
5.1.1 History:
In the earliest years of computers in the 1930–40s, computers were sometimes dedicated to
a single task, but were far too large and expensive for most kinds of tasks performed by embedded
computers of today. Over time however, the concept of programmable controllers evolved from
traditional electromechanical sequencers, via solid state devices, to the use of computer technology.
One of the first recognizably modern embedded systems was the Apollo Guidance
Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. At the project's
inception, the Apollo guidance computer was considered the riskiest item in the Apollo project as it
employed the then newly developed monolithic integrated circuits to reduce the size and weight. An early
mass-produced embedded system was the Autonetics D-17 guidance computer for the Minuteman missile,
released in 1961. It was built from transistor logic and had a hard disk for main memory. When the
Minuteman II went into production in 1966, the D-17 was replaced with a new computer that was the first
high-volume use of integrated circuits.
2.1.2 Tools:
Embedded development makes up a small fraction of total programming. There's also a
large number of embedded architectures, unlike the PC world where 1 instruction set rules, and the Unix
world where there's only 3 or 4 major ones. This means that the tools are more expensive. It also means
that they're lowering featured, and less developed. On a major embedded project, at some point you will
almost always find a compiler bug of some sort.
Debugging tools are another issue. Since you can't always run general programs on your
embedded processor, you can't always run a debugger on it. This makes fixing your program difficult.
Special hardware such as JTAG ports can overcome this issue in part. However, if you stop on a
breakpoint when your system is controlling real world hardware (such as a motor), permanent equipment
damage can occur. As a result, people doing embedded programming quickly become masters at using
serial IO channels and error message style debugging.
5.1.3 Resources:
To save costs, embedded systems frequently have the cheapest processors that can do the
job. This means your programs need to be written as efficiently as possible. When dealing with large data
sets, issues like memory cache misses that never matter in PC programming can hurt you. Luckily, this
won't happen too often- use reasonably efficient algorithms to start, and optimize only when necessary. Of
course, normal profilers won't work well, due to the same reason debuggers don't work well.
Memory is also an issue. For the same cost savings reasons, embedded systems usually
have the least memory they can get away with. That means their algorithms must be memory efficient
(unlike in PC programs, you will frequently sacrifice processor time for memory, rather than the reverse).
It also means you can't afford to leak memory. Embedded applications generally use deterministic memory
techniques and avoid the default "new" and "malloc" functions, so that leaks can be found and eliminated
more easily. Other resources programmers expect may not even exist. For example, most embedded
processors do not have hardware FPUs (Floating-Point Processing Unit). These resources either need to be
emulated in software, or avoided altogether.

5.1.4 Real Time Issues:


Embedded systems frequently control hardware, and must be able to respond to them in real
time. Failure to do so could cause inaccuracy in measurements, or even damage hardware such as motors.
This is made even more difficult by the lack of resources available. Almost all embedded systems need to
be able to prioritize some tasks over others, and to be able to put off/skip low priority tasks such as UI in
favor of high priority tasks like hardware control.
5.2 Need For Embedded Systems:
The uses of embedded systems are virtually limitless, because every day new products are
introduced to the market that utilizes embedded computers in novel ways. In recent years, hardware such
as microprocessors, microcontrollers, and FPGA chips have become much cheaper. So when
implementing a new form of control, it's wiser to just buy the generic chip and write your own custom
software for it. Producing a custom-made chip to handle a particular task or set of tasks costs far more
time and money. Many embedded computers even come with extensive libraries, so that "writing your
own software" becomes a very trivial task indeed. From an implementation viewpoint, there is a major
difference between a computer and an embedded system. Embedded systems are often required to provide
Real-Time response. The main elements that make embedded systems unique are its reliability and ease in
debugging.
5.2.1 Debugging:
Embedded debugging may be performed at different levels, depending on the facilities
available. From simplest to most sophisticate they can be roughly grouped into the following areas:
 Interactive resident debugging, using the simple shell provided by the embedded operating system (e.g.
Forth and Basic)
 External debugging using logging or serial port output to trace operation using either a monitor in flash or
using a debug server like the Remedy Debugger which even works for heterogeneous multi core systems.
 An in-circuit debugger (ICD), a hardware device that connects to the microprocessor via a JTAG or Nexus
interface. This allows the operation of the microprocessor to be controlled externally, but is typically
restricted to specific debugging capabilities in the processor.
 An in-circuit emulator replaces the microprocessor with a simulated equivalent, providing full control over
all aspects of the microprocessor.
 A complete emulator provides a simulation of all aspects of the hardware, allowing all of it to be
controlled and modified and allowing debugging on a normal PC.
 Unless restricted to external debugging, the programmer can typically load and run software through the
tools, view the code running in the processor, and start or stop its operation. The view of the code may be
as assembly code or source-code.
Because an embedded system is often composed of a wide variety of elements, the
debugging strategy may vary. For instance, debugging a software(and microprocessor) centric embedded
system is different from debugging an embedded system where most of the processing is performed by
peripherals (DSP, FPGA, co-processor). An increasing number of embedded systems today use more than
one single processor core. A common problem with multi-core development is the proper synchronization
of software execution. In such a case, the embedded system design may wish to check the data traffic on
the busses between the processor cores, which requires very low-level debugging, at signal/bus level, with
a logic analyzer, for instance.
5.2.2 Reliability:
Embedded systems often reside in machines that are expected to run continuously for years
without errors and in some cases recover by them if an error occurs. Therefore the software is usually
developed and tested more carefully than that for personal computers, and unreliable mechanical moving
parts such as disk drives, switches or buttons are avoided.
Specific reliability issues may include:
 The system cannot safely be shut down for repair, or it is too inaccessible to repair. Examples include
space systems, undersea cables, navigational beacons, bore-hole systems, and automobiles.
 The system must be kept running for safety reasons. "Limp modes" are less tolerable. Often backups are
selected by an operator. Examples include aircraft navigation, reactor control systems, safety-critical
chemical factory controls, train signals, engines on single-engine aircraft.
 The system will lose large amounts of money when shut down: Telephone switches, factory controls,
bridge and elevator controls, funds transfer and market making, automated sales and service.
A variety of techniques are used, sometimes in combination, to recover from errors—both
software bugs such as memory leaks, and also soft errors in the hardware:
 Watchdog timer that resets the computer unless the software periodically notifies the watchdog
 Subsystems with redundant spares that can be switched over to
 software "limp modes" that provide partial function
 Designing with a Trusted Computing Base (TCB) architecture[6] ensures a highly secure & reliable
system environment
 An Embedded Hypervisor is able to provide secure encapsulation for any subsystem component, so that a
compromised software component cannot interfere with other subsystems, or privileged-level system
software. This encapsulation keeps faults from propagating from one subsystem to another, improving
reliability. This may also allow a subsystem to be automatically shut down and restarted on fault detection.
 Immunity Aware Programming
5.3 Explanation of Embedded Systems:
5.3.1 Software Architecture:
There are several different types of software architecture in common use.
 Simple Control Loop:
In this design, the software simply has a loop. The loop calls subroutines, each of which
manages a part of the hardware or software.
 Interrupt Controlled System:
Some embedded systems are predominantly interrupting controlled. This means that tasks
performed by the system are triggered by different kinds of events. An interrupt could be generated for
example by a timer in a predefined frequency, or by a serial port controller receiving a byte. These kinds
of systems are used if event handlers need low latency and the event handlers are short and simple.
Usually these kinds of systems run a simple task in a main loop also, but this task is not
very sensitive to unexpected delays. Sometimes the interrupt handler will add longer tasks to a queue
structure. Later, after the interrupt handler has finished, these tasks are executed by the main loop. This
method brings the system close to a multitasking kernel with discrete processes.
 Cooperative Multitasking:
A non-preemptive multitasking system is very similar to the simple control loop scheme,
except that the loop is hidden in an API. The programmer defines a series of tasks, and each task gets its
own environment to “run” in. When a task is idle, it calls an idle routine, usually called “pause”, “wait”,
“yield”, “nop” (stands for no operation), etc.The advantages and disadvantages are very similar to the
control loop, except that adding new software is easier, by simply writing a new task, or adding to the
queue-interpreter.
 Primitive Multitasking:
In this type of system, a low-level piece of code switches between tasks or threads based on
a timer (connected to an interrupt). This is the level at which the system is generally considered to have an
"operating system" kernel. Depending on how much functionality is required, it introduces more or less of
the complexities of managing multiple tasks running conceptually in parallel.
As any code can potentially damage the data of another task (except in larger systems using
an MMU) programs must be carefully designed and tested, and access to shared data must be controlled by
some synchronization strategy, such as message queues, semaphores or a non-blocking synchronization
scheme.
Because of these complexities, it is common for organizations to buy a real-time operating
system, allowing the application programmers to concentrate on device functionality rather than operating
system services, at least for large systems; smaller systems often cannot afford the overhead associated
with a generic real time system, due to limitations regarding memory size, performance, and/or battery
life.
 Microkernels And Exokernels:
A microkernel is a logical step up from a real-time OS. The usual arrangement is that the
operating system kernel allocates memory and switches the CPU to different threads of execution. User
mode processes implement major functions such as file systems, network interfaces, etc.
In general, microkernels succeed when the task switching and intertask communication is
fast, and fail when they are slow. Exokernels communicate efficiently by normal subroutine calls. The
hardware and all the software in the system are available to, and extensible by application programmers.
Based on performance, functionality, requirement the embedded systems are divided into three categories:
5.3.2 Stand Alone Embedded System:
These systems takes the input in the form of electrical signals from transducers or
commands from human beings such as pressing of a button etc.., process them and produces desired
output. This entire process of taking input, processing it and giving output is done in standalone mode.
Such embedded systems comes under stand alone embedded systems
Eg: microwave oven, air conditioner etc..
5.3.3 Real-time embedded systems:
Embedded systems which are used to perform a specific task or operation in a specific time
period those systems are called as real-time embedded systems. There are two types of real-time
embedded systems.
 Hard Real-time embedded systems:
These embedded systems follow an absolute dead line time period i.e.., if the tasking is not
done in a particular time period then there is a cause of damage to the entire equipment.
Eg: consider a system in which we have to open a valve within 30 milliseconds. If this valve is not
opened in 30 ms this may cause damage to the entire equipment. So in such cases we use embedded
systems for doing automatic operations.
 Soft Real Time embedded systems:
These embedded systems follow a relative dead line time period i.e.., if the task is not done
in a particular time that will not cause damage to the equipment.
Eg: Consider a TV remote control system , if the remote control takes a few milliseconds delay it
will not cause damage either to the TV or to the remote control. These systems which will not cause
damage when they are not operated at considerable time period those systems comes under soft real-time
embedded systems.
5.3.4 Network communication embedded systems:
A wide range network interfacing communication is provided by using embedded systems.
Eg:
 Consider a web camera that is connected to the computer with internet can be used to spread
communication like sending pictures, images, videos etc.., to another computer with internet connection
throughout anywhere in the world.
 Consider a web camera that is connected at the door lock.
Whenever a person comes near the door, it captures the image of a person and sends to the
desktop of your computer which is connected to internet. This gives an alerting message with image on to
the desktop of your computer, and then you can open the door lock just by clicking the mouse. Fig: 5.2
show the network communications in embedded systems.

Fig 5.2: Network communication embedded systems


5.3.5 Different types of processing units:
The central processing unit (c.p.u) can be any one of the following microprocessor,
microcontroller, digital signal processing.
 Among these Microcontroller is of low cost processor and one of the main advantage of microcontrollers
is, the components such as memory, serial communication interfaces, analog to digital converters etc.., all
these are built on a single chip. The numbers of external components that are connected to it are very less
according to the application.
 Microprocessors are more powerful than microcontrollers. They are used in major applications with a
number of tasking requirements. But the microprocessor requires many external components like memory,
serial communication, hard disk, input output ports etc.., so the power consumption is also very high when
compared to microcontrollers.
 Digital signal processing is used mainly for the applications that particularly involved with processing of
signals
5.4 APPLICATIONS OF EMBEDDED SYSTEMS:
5.4.1 Consumer applications:
At home we use a number of embedded systems which include microwave oven, remote
control, vcd players, dvd players, camera etc….

Fig5.3: Automatic coffee makes equipment


5.4.2 Office automation:
We use systems like fax machine, modem, printer etc…

Fig5.4: Fax machine Fig5.5: Printing machine

5.4.3. Industrial automation:


Today a lot of industries are using embedded systems for process control. In industries we
design the embedded systems to perform a specific operation like monitoring temperature, pressure,
humidity ,voltage, current etc.., and basing on these monitored levels we do control other devices, we can
send information to a centralized monitoring station.

Fig5.6: Robot
In critical industries where human presence is avoided there we can use robots which are
programmed to do a specific operation.
5.4.5 Computer networking:
Embedded systems are used as bridges routers etc..

Fig5.7: Computer networking

5.4.6 Tele communications:

Cell phones, web cameras etc.

Fig5.8: Cell Phone Fig5.9: Web camera


CHAPTER 6
HARDWARE DESCRIPTION

6.1 Micro controller:

Fig: 6.1 Microcontrollers


6.1.1 Introduction to Microcontrollers:
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.

Fig: 6.2 Architecture

That was a prerequisite for production of microprocessors, and the first computers were made by
adding external peripherals such as memory, input-output lines, timers and other. Further increasing of the
volume of the package resulted in creation of integrated circuits. These integrated circuits contained both
processor and peripherals. That is how the first chip containing a microcomputer, or what would later be
known as a microcontroller came about.

Microprocessors and microcontrollers are widely used in embedded systems products.


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

Figure 6.3 ARDUINO Development Board

The AVR is a modified Harvard architecture 8-bit RISC single chip microcontroller which was
developed by Atmel in 1996. The AVR was one of the first microcontroller families to use on-chip flash
memory for program storage, as opposed to One-Time Programmable ROM, EPROM, or EEPROM used
by other microcontrollers at the time.

6.3 Crystal Oscillator:


XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can be configured
for use as an On-chip Oscillator, Either a quartz
Crystal or a ceramic resonator may be used. The CKOPT Fuse selects between two different
Oscillator amplifier modes. When CKOPT is programmed, the Oscillator output will oscillate a full rail-
to-rail swing on the output. This mode is suitable when operating in a very noisy environment or when the
output from XTAL2 drives a second clock buffer. This mode has a wide frequency range. When CKOPT
is unprogrammed, the Oscillator has a smaller output swing. This reduces power consumption
considerably.

Figure 6.4 crystal oscillator

This mode has a limited frequency range and it cannot be used to drive other clock buffers. For
resonators, the maximum frequency is 8 MHz with CKOPT unprogrammed and 16 MHz with CKOPT
programmed. C1 and C2 should always be equal for both crystals and resonators. The optimal value of the
capacitors depends on the crystal or resonator in use, the amount of stray capacitance, and the
electromagnetic noise of the environment. For ceramic resonators, the capacitor values given by the
manufacturer should be used. The Oscillator can operate in three different modes, each optimized for a
specific frequency range. The operating mode is selected by the fuses CKSEL3..1

6.4 Architecture:
Memory: It has 8 Kb of Flash program memory (10,000 Write/Erase cycles durability), 512 Bytes of
EEPROM (100,000 Write/Erase Cycles). 1Kbyte Internal SRAM
I/O Ports: 23 I/ line can be obtained from three ports; namely Port B, Port C and Port D.
Interrupts: Two External Interrupt source, located at port D. 19 different interrupt vectors supporting 19
events generated by internal peripherals.
Timer/Counter: Three Internal Timers are available, two 8 bit, one 16 bit, offering various operating
modes and supporting internal or external clocking.
SPI (Serial Peripheral interface): ATmega8 holds three communication devices integrated. One of
them is Serial Peripheral Interface. Four pins are assigned to Atmega8 to implement this scheme of
communication.
USART: One of the most powerful communication solutions is USART and ATmega8 supports both
synchronous and asynchronous data transfer schemes. It has three pins assigned for that. In many projects,
this module is extensively used for PC-Micro controller communication.
TWI (Two Wire Interface): Another communication device that is present in ATmega8 is Two Wire
Interface. It allows designers to set up a commutation between two devices using just two wires along with
a common ground connection, As the TWI output is made by means of open collector outputs, thus
external pull up resistors are required to make the circuit.
Analog Comparator: A comparator module is integrated in the IC that provides comparison facility
between two voltages connected to the two inputs of the Analog comparator via External pins attached to
the micro controller.
Analog to Digital Converter: Inbuilt analog to digital converter can convert an analog input signal into
digital data of 10bit resolution. For most of the low end application, this much resolution is enough.

FIG 6.5 AVR Architecture


Microcontroller: Microcontroller can be termed as a single on chip computer which includes
number of peripherals like RAM, EEPROM, Timers etc., required to perform some predefined task.
The computer on one hand is designed to perform all the general purpose tasks on a single machine
like you can use a computer to run a software to perform calculations or you can use a computer to store
some multimedia file or to access internet through the browser, whereas the microcontrollers are meant to
perform only the specific tasks, for e.g., switching the AC off automatically when room temperature drops
to a certain defined limit and again turning it ON when temperature rises above the defined limit.
There are number of popular families of microcontrollers which are used in different applications
as per their capability and feasibility to perform the desired task, most common of these
are 8051, AVR and PIC microcontrollers. In this article we will introduce you with AVR family of
microcontrollers.
AVR was developed in the year 1996 by Atmel Corporation. The architecture of AVR was
developed by Alf-Egil Bogen and Vegard Wollan. AVR derives its name from its developers and stands
for Alf-Egil Bogen Vegard Wollan RISC microcontroller, also known as Advanced Virtual RISC. The
AT90S8515 was the first microcontroller which was based on AVR architecture however the first
microcontroller to hit the commercial market was AT90S1200 in the year 1997.
AVR microcontrollers are available in three categories:
1. TinyAVR – Less memory, small size, suitable only for simpler applications
2. MegaAVR – These are the most popular ones having good amount of memory (upto 256 KB),
higher number of inbuilt peripherals and suitable for moderate to complex applications.
3. XmegaAVR – Used commercially for complex applications, which require large program memory
and high speed.

Device architecture
Flash, EEPROM, and SRAM are all integrated onto a single chip, removing the need for external
memory in most applications. Some devices have a parallel external bus option to allow adding additional
data memory or memory-mapped devices. Almost all devices (except the smallest TinyAVR chips) have
serial interfaces, which can be used to connect larger serial EEPROMs or flash chips.
Program memory
Program instructions are stored in non-volatile flash memory. Although the MCUs are 8-bit, each
instruction takes one or two 16-bit words.
The size of the program memory is usually indicated in the naming of the device itself (e.g., the
ATmega64x line has 64 kB of flash while the ATmega32x line has 32 kB).
There is no provision for off-chip program memory; all code executed by the AVR core must reside in the
on-chip flash. However, this limitation does not apply to the AT94 FPSLIC AVR/FPGA chips.
Internal data memory
The data address space consists of the register file, I/O registers, and SRAM.
Internal registers
The AVRs have 32 single-byte registers and are classified as 8-bit RISC devices.
In most variants of the AVR architecture, the working registers are mapped in as the first 32
memory addresses (000016–001F16) followed by the 64 I/O registers (002016–005F16).
Actual SRAM starts after these register sections (address 0060 16). (Note that the I/O register space
may be larger on some more extensive devices, in which case the memory mapped I/O registers will
occupy a portion of the SRAM address space.)
Even though there are separate addressing schemes and optimized opcodes for register file and I/O register
access, all can still be addressed and manipulated as if they were in SRAM.
In the XMEGA variant, the working register file is not mapped into the data address space; as such,
it is not possible to treat any of the XMEGA's working registers as though they were SRAM. Instead, the
I/O registers are mapped into the data address space starting at the very beginning of the address space.
Additionally, the amount of data address space dedicated to I/O registers has grown substantially to 4096
bytes (000016–0FFF16). As with previous generations, however, the fast I/O manipulation instructions can
only reach the first 64 I/O register locations (the first 32 locations for bitwise instructions). Following the
I/O registers, the XMEGA series sets aside a 4096 byte range of the data address space which can be used
optionally for mapping the internal EEPROM to the data address space (1000 16–1FFF16). The actual
SRAM is located after these ranges, starting at 200016.
EEPROM
Almost all AVR microcontrollers have internal EEPROM for semi-permanent data storage. Like
flash memory, EEPROM can maintain its contents when electrical power is removed.
In most variants of the AVR architecture, this internal EEPROM memory is not mapped into the
MCU's addressable memory space. It can only be accessed the same way an external peripheral device is,
using special pointer registers and read/write instructions which makes EEPROM access much slower than
other internal RAM.
However, some devices in the SecureAVR (AT90SC) family use a special EEPROM mapping to
the data or program memory depending on the configuration. The XMEGA family also allows the
EEPROM to be mapped into the data address space.
Since the number of writes to EEPROM is not unlimited — Atmel specifies 100,000 write cycles in their
datasheets — a well designed EEPROM write routine should compare the contents of an EEPROM
address with desired contents and only perform an actual write if the contents need to be changed.
Note that erase and write can be performed separately in many cases, byte-by-byte, which may also
help prolong life when bits only need to be set to all 1s (erase) or selectively cleared to 0s (write).
Program execution
Atmel's AVRs have a two stage, single level pipeline design. This means the next machine
instruction is fetched as the current one is executing. Most instructions take just one or two clock cycles,
making AVRs relatively fast among eight-bit microcontrollers.
The AVR processors were designed with the efficient execution of compiled C code in mind and have
several built-in pointers for the task.
MCU speed
The AVR line can normally support clock speeds from 0 to 20 MHz, with some devices reaching
32 MHz. Lower powered operation usually requires a reduced clock speed. All recent (Tiny, Mega, and
Xmega, but not 90S) AVRs feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Some AVRs also have a system clock prescaler that can divide down the system clock
by up to 1024. This prescaler can be reconfigured by software during run-time, allowing the clock speed to
be optimized.
Since all operations (excluding literals) on registers R0 - R31 are single cycle, the AVR can
achieve up to 1 MIPS per MHz, i.e. an 8 MHz processor can achieve up to 8 MIPS. Loads and stores
to/from memory take two cycles, branching takes two cycles. Branches in the latest "3-byte PC" parts such
as ATmega2560 are one cycle slower than on previous devices
Features:
• High-performance, Low-power Atmel®AVR® 8-bit Microcontroller
• Advanced RISC Architecture
– 130 Powerful Instructions – Most Single-clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16MIPS Throughput at 16MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
– 8Kbytes of In-System Self-programmable Flash program memory
– 512Bytes EEPROM
– 1Kbyte Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C(1)
– Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– Programming Lock for Software Security
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
– Real Time Counter with Separate Oscillator
– Three PWM Channels
– 8-channel ADC in TQFP and QFN/MLF package
Eight Channels 10-bit Accuracy
– 6-channel ADC in PDIP package
Six Channels 10-bit Accuracy
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and
Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
• Operating Voltages
– 2.7V - 5.5V (ATmega8L)
– 4.5V - 5.5V (ATmega8)
• Speed Grades
– 0 - 8MHz (ATmega8L)
– 0 - 16MHz (ATmega8)
• Power Consumption at 4Mhz, 3V, 25oC
– Active: 3.6mA
– Idle Mode: 1.0mA
– Power-down Mode: 0.5µA
Brown-out Detector:
If the Brown-out Detector is not needed in the application, this module should be turned off. If the
Brown-out Detector is enabled by the BODEN Fuse, it will be enabled in all sleep modes, and hence,
always consume power. In the deeper sleep modes, this will contribute significantly to the total current
consumption. Refer to “Brown-out Detection” on page 38 for details on how to configure the Brown-out
Detector.
Internal Voltage Reference the Internal Voltage Reference will be enabled when needed by the
Brown-out Detector, the Analog Comparator or the ADC. If these modules are disabled as described in the
sections above, the internal voltage reference will be disabled and it will not be consuming power. When
turned on again, the user must allow the reference to start up before the output is used. If the reference is
kept on in sleep mode, the output can be used immediately. Refer to “Internal Voltage Reference” on page
40 for details on the start-up time. Watchdog Timer If the Watchdog Timer is not needed in the
application, this module should be turned off.
If the Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence, always
consume power. In the deeper sleep modes, this will contribute significantly to the total current
consumption. Refer to “Watchdog Timer” on page 41 for details on how to configure the Watchdog
Timer. Port Pins When entering a sleep mode, all port pins should be configured to use minimum power.
The most important thing is then to ensure that no pins drive resistive loads. In sleep modes where
the both the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device
will be disabled. This ensures that no power is consumed by the input logic when not needed. In some
cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled. Refer to the
section “Digital Input Enable and Sleep Modes” on page 53 for details on which pins are enabled. If the
input buffer is enabled and the input signal is left floating or have an analog signal level close to VCC/2,
the input buffer will use excessive power.
Power-on Reset:
A Power-on Reset (POR) pulse is generated by an On-chip detection circuit. The detection level is
defined in Table 15. The POR is activated whenever VCC is below the detection level. The POR circuit
can be used to trigger the Start-up Reset, as well as to detect a failure in supply voltage.
A Power-on Reset (POR) circuit ensures that the device is reset from Power-on. Reaching the
Power-on Reset threshold voltage invokes the delay counter, which determines how long the device is kept
in RESET after VCC rise. The RESET signal is activated again, without any delay, when VCC decreases
below the detection level.
External Reset:
An External Reset is generated by a low level on the RESET pin. Reset pulses longer than the
minimum pulse width (see Table 15) will generate a reset, even if the clock is not running. Shorter pulses
are not guaranteed to generate a reset. When the applied signal reaches the Reset Threshold Voltage –
VRST on its positive edge, the delay counter starts the MCU after the time-out period tTOUT has expired.
6.5 Pin diagram:

Fig.6.6 PIN DIAGRAM OF ATMEGA328


Fig.6.7 PIN DIAGRAM OF ATMEGA328

VCC
Digital supply voltage magnitude of the voltage range between 4.5 to 5.5 V for the ATmega8 and 2.7 to
5.5 V for ATmega8L
GND
Ground Zero reference digital voltage supply.
PORTB (PB7.. PB0)
PORTB is a port I / O two-way (bidirectional) 8-bit with internal pull-up resistor can be selected. This port
output buffers have symmetrical characteristics when used as a source or sink. When used as an input, the
pull-pin low externally will emit a current if the pull-up resistor is activated it. PORTB pins will be in the
condition of the tri-state when RESET is active, although the clock is not running.
PORTC (PC5.. PC0)
PORTC is a port I / O two-way (bidirectional) 7-bit with internal pull-up resistor can be selected. This port
output buffers have symmetrical characteristics when used as a source or sink. When used as an input, the
pull-pin low externally will emit a current if the pull-up resistor is activated it. PORTC pins will be in the
condition of the tri-state when RESET is active, although the clock is not running.
PC6/RESET
If RSTDISBL Fuse programmed, PC6 then serves as a pin I / O but with different characteristics. PC0 to
PC5 If Fuse RSTDISBL not programmed, then serves as input Reset PC6. LOW signal on this pin with a
minimum width of 1.5 microseconds will bring the microcontroller into reset condition, although the clock
is not running.
PORTD (PD7.. PD0)
PORTD is a port I / O two-way (bidirectional) 8-bit with internal pull-up resistor can be selected. This port
output buffers have symmetrical characteristics when used as a source or sink. When used as an input, the
pull-pin low externally will emit a current if the pull-up resistor is activated it. PORTD pins will be in the
condition of the tri-state when RESET is active, although the clock is not running.
RESET
Reset input pin. LOW signal on this pin with a minimum width of 1.5 microseconds will bring the
microcontroller into reset condition, although the clock is not running. Signal with a width of less than 1.5
microseconds does not guarantee a Reset condition.
AVCC
AVCC is the supply voltage pin for the ADC, PC3 .. PC0, and ADC7..ADC6. This pin should be
connected to VCC, even if the ADC is not used. If the ADC is used, AVCC should be connected to VCC
through a low-pass filter to reduce noise.
Aref
Analog Reference pin for the ADC.
ADC7 .. ADC6
ADC analog input there is only on ATmega8 with TQFP and QFP packages / MLF.
PORTS
Term "port" refers to a group of pins on a microcontroller which can be accessed simultaneously, or on
which we can set the desired combination of zeros and ones, or read from them an existing status.
Physically, port is a register inside a microcontroller which is connected by wires to the pins of a
microcontroller. Ports represent physical connection of Central Processing Unit with an outside world.
Microcontroller uses them
The Atmega8 has 23 I/O ports which are organized into 3 groups:
 Port B (PB0 to PB7)
 Port C (PC0 to PC6)
 Port D (PD0 to PD7)
We will use mainly 3 registers known as DDRX, PORTX & PINX. We have total four PORTs on my
ATmega16. They are PORTA, PORTB, PORTC and PORTD. They are multifunctional pins. Each of
the pins in each port (total 32) can be treated as input or output pin.
Applications
AVR microcontroller perfectly fits many uses, from automotive industries and controlling home
appliances to industrial instruments, remote sensors, electrical door locks and safety devices. It is also
ideal for smart cards as well as for battery supplied devices because of its low consumption.
EEPROM memory makes it easier to apply microcontrollers to devices where permanent storage of
various parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc.). Low cost,
low consumption, easy handling and flexibility make ATmega8 applicable even in areas where
microcontrollers had not previously been considered (example: timer functions, interface replacement in
larger systems, coprocessor applications, etc.).
In System Programmability of this chip (along with using only two pins in data transfer) makes
possible the flexibility of a product, after assembling and testing have been completed. This capability can
be used to create assembly-line production, to store calibration data available only after final testing, or it
can be used to improve programs on finished products.
6.6 Regulated Power Supply:
A regulated power supply converts unregulated AC (Alternating Current) to a constant DC (Direct
Current). A regulated power supply is used to ensure that the output remains constant even if the input
changes. A regulated DC power supply is also known as a linear power supply; it is an embedded circuit
and consists of various blocks. The regulated power supply will accept an AC input and give a constant
DC output. The figure below shows the block diagram of a typical regulated DC power supply.

Figure 6.8 Block diagram of power supply

Figure 6.9 Power supply circuit diagram

Fig6.10 Regulated Power Supply


The basic circuit diagram of a regulated power supply (DC O/P) with led connected as load
is shown in fig: 3.3.3.

Fig 6.11 Circuit diagram of Regulated Power Supply with Led connection
The components mainly used in above figure are
 230V AC MAINS
 TRANSFORMER
 BRIDGE RECTIFIER(DIODES)
 CAPACITOR
 VOLTAGE REGULATOR(IC 7805)
 RESISTOR
 LED(LIGHT EMITTING DIODE)
The detailed explanation of each and every component mentioned above is as follows:
Transformation: The process of transforming energy from one device to another is called transformation.
For transforming energy we use transformers.
Step down transformer:
Incase of step down transformer, Primary winding induces more flux than the secondary
winding, and secondary winding is having less number of turns because of that it accepts less number of
flux, and releases less amount of voltage.

Bridge full wave rectifier:


The Bridge rectifier circuit is shown in fig:3.8, which converts an ac voltage to dc voltage
using both half cycles of the input ac voltage. The Bridge rectifier circuit is shown in the figure. The
circuit has four diodes connected to form a bridge. The ac input voltage is applied to the diagonally
opposite ends of the bridge. The load resistance is connected between the other two ends of the bridge.
For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas
diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series with the load resistance
RL and hence the load current flows through RL.
For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct whereas, D1
and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load resistance R L and
hence the current flows through R L in the same direction as in the previous half cycle. Thus a bi-
directional wave is converted into a unidirectional wave.
Input Output

Fig 6.12 Bridge rectifier: a full-wave rectifier using 4 diodes


DB107:
Now -a -days Bridge rectifier is available in IC with a number of DB107. In our project we
are using an IC in place of bridge rectifier. The picture of DB 107 is shown in fig: 3.3.8.

Fig 6.13. DB107

Capacitor Filtration:
The process of converting a pulsating direct current to a pure direct current using filters is
called as filtration. Electronic filters are electronic circuits, which perform signal-processing functions,
specifically to remove unwanted frequency components from the signal, to enhance wanted
ones.The Capacitor or sometimes referred to as a Condenser is a passive device, and one which stores
energy in the form of an electrostatic field which produces a potential (static voltage) across its plates. In
its basic form a capacitor consists of two parallel conductive plates that are not connected but are
electrically separated either by air or by an insulating material called the Dielectric. When a voltage is
applied to these plates, a current flows charging up the plates with electrons giving one plate a positive
charge and the other plate an equal and opposite negative charge this flow of electrons to the plates is
known as the Charging Current and continues to flow until the voltage across the plates (and hence the
capacitor) is equal to the applied voltage Vcc. At this point the capacitor is said to be fully charged and
this is illustrated below. The construction of capacitor and an electrolytic capacitor are shown in figures
3.3.9 and 3.3.10 respectively.

Fig 6.14 Construction Of a Capacitor Fig 6.15 Electrolytic

Voltage Regulation:
The process of converting a varying voltage to a constant regulated voltage is called as
regulation. For the process of regulation we use voltage regulators.

Voltage Regulator:
A voltage regulator (also called a ‘regulator’) with only three terminals appears to be a
simple device, but it is in fact a very complex integrated circuit. It converts a varying input voltage into a
constant ‘regulated’ output voltage. Voltage Regulators are available in a variety of outputs like 5V, 6V,
9V, 12V and 15V. The LM78XX series of voltage regulators are designed for positive input. For
applications requiring negative input, the LM79XX series is used. Using a pair of ‘voltage-divider’
resistors can increase the output voltage of a regulator circuit.
It is not possible to obtain a voltage lower than the stated rating. You cannot use a 12V
regulator to make a 5V power supply. Voltage regulators are very robust. These can withstand over-
current draw due to short circuits and also over-heating. In both cases, the regulator will cut off before any
damage occurs. The only way to destroy a regulator is to apply reverse voltage to its input. Reverse
polarity destroys the regulator almost instantly. Fig: 3.3.11 shows voltage regulator.

Fig 6.16. Voltage Regulator


Resistor:
A resistor is a two-terminal electronic component that produces a voltage across its terminals that
is proportional to the electric current passing through it in accordance with Ohm's law:
V = IR
Resistors are elements of electrical networks and electronic circuits and are ubiquitous in most
electronic equipment. Practical resistors can be made of various compounds and films, as well as
resistance wire (wire made of a high-resistivity alloy, such as nickel/chrome).
The primary characteristics of a resistor are the resistance, the tolerance, maximum working
voltage and the power rating. Other characteristics include temperature coefficient, noise, and inductance.
Less well-known is critical resistance, the value below which power dissipation limits the maximum
permitted current flow, and above which the limit is applied voltage. Critical resistance is determined by
the design, materials and dimensions of the resistor.
dissipated by a resistor (or the equivalent resistance of a resistor network) is calculated using the
following:

Fig 6.18 Resistor Fig 6.19 Color Bands In Resistor


LED:
A light-emitting diode (LED) is a semiconductor light source. LED’s are used as indicator
lamps in many devices, and are increasingly used for lighting. Introduced as a practical electronic
component in 1962, early LED’s emitted low-intensity red light, but modern versions are available across
the visible, ultraviolet and infrared wavelengths, with very high brightness. The internal structure and parts
of a led are shown in figures 3.4.1 and 3.4.2 respectively.

Fig.6.20 Inside a LED Fig 6.21. Parts of a LED

6.8 Buzzer
Basically, the sound source of a piezoelectric sound component is a piezoelectric diaphragm. A
piezoelectric diaphragm consists of a piezoelectric ceramic plate which has electrodes on both sides and a
metal plate (brass or stainless steel, etc.). A piezoelectric ceramic plate is attached to a metal plate with
adhesives. Applying D.C. voltage between electrodes of a piezoelectric diaphragm causes mechanical
distortion due to the piezoelectric effect. For a misshaped piezoelectric element, the distortion of the
piezoelectric element expands in a radial direction. And the piezoelectric diaphragm bends toward the
direction. The metal plate bonded to the piezoelectric element does not expand. Conversely, when the
piezoelectric element shrinks, the piezoelectric diaphragm bends in the direction Thus, when AC voltage is
applied across electrodes, the bending is repeated, producing sound waves in the air. To interface a buzzer
the standard transistor interfacing circuit is used. Note that if a different power supply is used for the
buzzer, the 0V rails of each power supply must be connected to provide a common reference.
If a battery is used as the power supply, it is worth remembering that piezo sounders
draw much less current than buzzers. Buzzers also just have one ‘tone’, whereas a
piezo sounder is able to create sounds of many different tones. To switch on buzzer -high 1 To switch off
buzzer -low 1

Fig: 6.22 Picture of buzzer

6.9 LCD DISPLAY


LCD Background:
One of the most common devices attached to a micro controller is an LCD display. Some of the most
common LCD’s connected to the many microcontrollers are 16x2 and 20x2 displays. This means 16
characters per line by 2 lines and 20 characters per line by 2 lines, respectively.
Basic 16x 2 Characters LCD

Figure 6.25 LCD Pin diagram

Pin description:

Pin No. Name Description


Pin no. 1 VSS Power supply (GND)
Pin no. 2 VCC Power supply (+5V)
Pin no. 3 VEE Contrast adjust
0 = Instruction input
Pin no. 4 RS
1 = Data input
0 = Write to LCD module
Pin no. 5 R/W
1 = Read from LCD module
Pin no. 6 EN Enable signal
Pin no. 7 D0 Data bus line 0 (LSB)
Pin no. 8 D1 Data bus line 1
Pin no. 9 D2 Data bus line 2
Pin no. 10 D3 Data bus line 3
Pin no. 11 D4 Data bus line 4
Pin no. 12 D5 Data bus line 5
Pin no. 13 D6 Data bus line 6
Pin no. 14 D7 Data bus line 7 (MSB)
Table 1: Character LCD pins with Microcontroller
The LCD requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The user may
select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit data bus is used
the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus). If an 8-bit data
bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).
The three control lines are referred to as EN, RS, and RW.
The EN line is called "Enable." This control line is used to tell the LCD that we are sending it data. To
send data to the LCD, our program should make sure this line is low (0) and then set the other two control
lines and/or put data on the data bus. When the other lines are completely ready, bring EN high (1) and
wait for the minimum amount of time required by the LCD datasheet (this varies from LCD to LCD), and
end by bringing it low (0) again.
The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data
being sent is text data which should be displayed on the screen. For example, to display the letter "T" on
the screen we would set RS high.
The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus
is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the
LCD. Only one instruction ("Get LCD status") is a read command. All others are write commands--so RW
will almost always be low.
Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the
user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6,
and DB7.
Schematic:

Circuit Description:
Above is the quite simple schematic. The LCD panel's Enable and Register Select is connected to
the Control Port. The Control Port is an open collector / open drain output. While most Parallel Ports have
internal pull-up resistors, there is a few which don't. Therefore by incorporating the two 10K external pull
up resistors, the circuit is more portable for a wider range of computers, some of which may have no
internal pull up resistors.
We make no effort to place the Data bus into reverse direction. Therefore we hard wire the R/W
line of the LCD panel, into write mode. This will cause no bus conflicts on the data lines. As a result we
cannot read back the LCD's internal Busy Flag which tells us if the LCD has accepted and finished
processing the last instruction. This problem is overcome by inserting known delays into our program.
The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with all
the examples, I've left the power supply out. We can use a bench power supply set to 5v or use an onboard
+5 regulator. Remember a few de-coupling capacitors, especially if we have trouble with the circuit
working properly.
SETB RW
Handling the EN control line:
As we mentioned above, the EN line is used to tell the LCD that we are ready for it to execute an
instruction that we've prepared on the data bus and on the other control lines. Note that the EN line must
be raised/ lowered before/after each instruction sent to the LCD regardless of whether that instruction is
read or write text or instruction. In short, we must always manipulate EN when communicating with the
LCD. EN is the LCD's way of knowing that we are talking to it. If we don't raise/lower EN, the LCD
doesn't know we're talking to it on the other lines.

Thus, before we interact in any way with the LCD we will always bring the EN line low with the
following instruction:
CLR EN
And once we've finished setting up our instruction with the other control lines and data bus lines,
we'll always bring this line high:
SETB EN
The line must be left high for the amount of time required by the LCD as specified in its datasheet.
This is normally on the order of about 250 nanoseconds, but checks the datasheet. In the case of a typical
microcontroller running at 12 MHz, an instruction requires 1.08 microseconds to execute so the EN line
can be brought low the very next instruction. However, faster microcontrollers (such as the DS89C420
which executes an instruction in 90 nanoseconds given an 11.0592 MHz crystal) will require a number of
NOPs to create a delay while EN is held high. The number of NOPs that must be inserted depends on the
microcontroller we are using and the crystal we have selected.
The instruction is executed by the LCD at the moment the EN line is brought low with a final CLR
EN instruction.

Checking the busy status of the LCD:


As previously mentioned, it takes a certain amount of time for each instruction to be executed by
the LCD. The delay varies depending on the frequency of the crystal attached to the oscillator input of the
LCD as well as the instruction which is being executed.
While it is possible to write code that waits for a specific amount of time to allow the LCD to execute
instructions, this method of "waiting" is not very flexible. If the crystal frequency is changed, the software
will need to be modified. A more robust method of programming is to use the "Get LCD Status" command
to determine whether the LCD is still busy executing the last instruction received.

The "Get LCD Status" command will return to us two tidbits of information; the information that is
useful to us right now is found in DB7. In summary, when we issue the "Get LCD Status" command the
LCD will immediately raise DB7 if it's still busy executing a command or lower DB7 to indicate that the
LCD is no longer occupied. Thus our program can query the LCD until DB7 goes low, indicating the LCD
is no longer busy. At that point we are free to continue and send the next command.

6.11 GSM
Global System for Mobile Communication (GSM)
Definition:
GSM, which stands for Global System for Mobile communications, reigns (important) as the
world’s most widely used cell phone technology. Cell phones use a cell phone service carrier’s GSM
network by searching for cell phone towers in the nearby area. Global system for mobile communication
(GSM) is a globally accepted standard for digital cellular communication.
GSM is the name of a standardization group established in 1982 to create a common
European mobile telephone standard that would formulate specifications for a pan-European mobile
cellular radio system operating at 900 MHz. It is estimated that many countries outside of Europe will join
the GSM partnership.

MODEM SPECIFICATIONS:
The SIM300 is a complete Tri-band GSM solution in a compact plug-in module.
Featuring an industry-standard interface, the SIM300 delivers GSM/GPRS900/1800/1900Mhz
performance for voice, SMS, data and Fax in a small form factor and with low power consumption.
The leading features of SIM300 make it deal fir virtually unlimited application, such as WLL applications
(Fixed Cellular Terminal), M2M application, handheld devices and much more.
1. Tri-band GSM/GPRS module with a size of 40x33x2.85
2. Customized MMI and keypad/LCD support
3. An embedded powerful TCP/IP protocol stack
4. Based upon mature and field proven platform, backed up by our support service, from definition to design
and production.

General Features:
 Tri-band GSM/GPRS900/1800/1900Mhz
 GPRS multi-slot class 10
 GPRS mobile station class –B
 Complaint to GSM phase 2/2+
i. -class 4(2W @900MHz)
ii. -class 1(1W @/18001900MHz)
 Dimensions: 40x33x2.85 mm
 Weight: 8gm
 7. Control via AT commands
 (GSM 07.07, 07.05 and SIMCOM enhanced AT commands)
 SIM application tool kit
 supply voltage range 3.5…….4.5 v
 Low power consumption
 Normal operation temperature: -20 ’C to +55 ‘C
 Restricted operation temperature : -20 ’C to -25 ‘C and +55 ’C to +70 ‘C
 storage temperature: -40 ‘C to +80 ‘C

6.12. 3.5: GPS MODULE

Global Positioning System


3.5.1. Introduction:

The Global Positioning System (GPS) is a burgeoning technology, which provides unequalled
accuracy and flexibility of positioning for navigation, surveying and GIS data capture. The GPS
NAVSTAR (Navigation Satellite timing and Ranging Global Positioning System) is a satellite-based
navigation, timing and positioning system. The GPS provides continuous three-dimensional positioning 24
hrs a day throughout the world. The technology seems to be beneficiary to the GPS user community in
terms of obtaining accurate data up to about100 meters for navigation, meter-level for mapping, and down
to millimeter level for geodetic positioning. The GPS technology has tremendous amount of applications
in GIS data collection, surveying, and mapping.

The Global Positioning System (GPS) is a U.S. space-based radio navigation system that
provides reliable positioning, navigation, and timing services to civilian users on a continuous worldwide
basis -- freely available to all. For anyone with a GPS receiver, the system will provide location and time.
GPS provides accurate location and time information for an unlimited number of people in all weather,
day and night, anywhere in the world.
The Global Positioning System (GPS) is a satellite-based navigation system made up of a
network of 24 satellites placed into orbit by the U.S. Department of Defense. GPS was originally intended
for military applications, but in the 1980s, the government made the system available for civilian use. GPS
works in any weather conditions, anywhere in the world, 24 hours a day. There are no subscription fees or
setup charges to use GPS.
The GPS is made up of three parts: satellites orbiting the Earth; control and monitoring stations on Earth;
and the GPS receivers owned by users. GPS satellites broadcast signals from space that are picked up and
identified by GPS receivers. Each GPS receiver then provides three-dimensional location (latitude,
longitude, and altitude) plus the time.
Individuals may purchase GPS handsets that are readily available through commercial retailers.
Equipped with these GPS receivers, users can accurately locate where they are and easily navigate to
where they want to go, whether walking, driving, flying, or boating. GPS has become a mainstay of
transportation systems worldwide, providing navigation for aviation, ground, and maritime operations.
Disaster relief and emergency services depend upon GPS for location and timing capabilities in their life-
saving missions. Everyday activities such as banking, mobile phone operations, and even the control of
power grids, are facilitated by the accurate timing provided by GPS. Farmers, surveyors, geologists and
countless others perform their work more efficiently, safely, economically, and accurately using the free
and open GPS signals.
Geo positioning -- Basic Concepts:
By positioning we understand the determination of stationary or moving objects. These can be determined
as follows:
1. In relation to a well-defined coordinate system, usually by three coordinate values and
2. In relation to other point, taking one point as the origin of a local coordinate system.
The first mode of positioning is known as point positioning, the second as relative positioning. If the
object to be positioned is stationary, we term it as static positioning. When the object is moving, we call it
kinematics positioning. Usually, the static positioning is used in surveying and the kinematics position in
navigation.

This is a complete GPS module that is based on the NEO-6M. This unit uses the latest technology to give
the best possible positioning information and includes a larger built-in 25 x 25mm active GPS antenna
with a UART TTL socket. A battery is also included so that you can obtain a GPS lock faster. This is an
updated GPS module that can be used with ardupilot mega v2. This GPS module gives the best possible
position information, allowing for better performance with your Ardupilot or other Multirotor control
platform.
The NEO-6M GPS engine on this board is a quite good one, with the high precision binary output. It has
also high sensitivity for indoor applications. NEO-6M GPS Module has a battery for power backup and
EEPROM for storing configuration settings. The antenna is connected to the module through a ufl cable
which allows for flexibility in mounting the GPS such that the antenna will always see the sky for best
performance. This makes it powerful to use with cars and other mobile applications.
The GPS module has serial TTL output, it has four pins: TX, RX, VCC, and GND. You can download the
u-center software for configuring the GPS and changing the settings and much more.

Features NEO-6M GPS Module:-


 5Hz position update rate

 Operating temperature range: -40 TO 85°CUART TTL socket

 EEPROM to save configuration settings

 Rechargeable battery for Backup

 The cold start time of 38 s and Hot start time of 1 s

 Supply voltage: 3.3 V

 Configurable from 4800 Baud to 115200 Baud rates. (default 9600)

 SuperSense ® Indoor GPS: -162 dBm tracking sensitivity

 Support SBAS (WAAS, EGNOS, MSAS, GAGAN)

 Separated 18X18mm GPS antenna

Vibration TILT sensor

6.4 Mercury switch


A mercury switch is an electrical switch that opens and closes a circuit when a small amount of the liquid
metal mercury connects metal electrodes to close the circuit. There are several different basic designs (tilt,
displacement, radial, etc.) but they all share the common design strength of non-eroding switch contacts.
The most common is the mercury tilt switch. It is in one state (open or closed) when tilted one
direction with respect to horizontal, and the other state when tilted the other direction. This is what older
style thermostats used to turn a heater or air conditioner on or off.

The mercury displacement switch uses a 'plunger' that dips into a pool of mercury, raising the level
in the container to contact at least one electrode. This design is used in relays in industrial applications that
need to switch high current loads frequently. These relays use electromagnetic coils to pull steel sleeves
inside hermetically sealed containers.

Description:

Mercury switches have one or more sets of electrical contacts in a sealed glass envelope that contains a
small quantity of mercury. The envelope may also contain air, an inert gas, or a vacuum. Gravity
constantly pulls the drop of mercury to the lowest point in the envelope. When the switch is tilted in the
appropriate direction, the mercury touches a set of contacts, thus completing an electrical circuit. Tilting
the switch in the opposite direction moves the mercury away from that set of contacts, breaking that
circuit.[1] The switch may contain multiple sets of contacts, closing different sets at different angles,
allowing, for example, single-pole, double-throw (SPDT) operation.

Advantages

Mercury switches offer several advantages over other switch types:

 The contacts are enclosed, so oxidation of the contact points is unlikely.


 In hazardous locations, interrupting the circuit does not emit a spark that could ignite flammable gases.
 Contacts stay clean, and even if an internal arc occurs, the contact surfaces renew on every operation,
so they don't wear out.
 Even a small drop of mercury has low resistance, so switches can carry useful amounts of current in a
small size.[2]
 Sensitivity of the drop to gravity provides a unique sensing function, and lends itself to simple, low-
force mechanisms for manual or automatic operation.
 The switches are quiet, as no contacts abruptly snap together.
 The mass of the moving mercury drop provides an over center effect to avoid chattering as the switch
tilts.
 The envelope can include contacts for two or more circuits.

3.9 D.C. Motor:

A dc motor uses electrical energy to produce mechanical energy, very typically through the
interaction of magnetic fields and current-carrying conductors. The reverse process, producing electrical
energy from mechanical energy, is accomplished by an alternator, generator or dynamo. Many types of

electric motors can be run as generators, and vice versa. The input of a DC motor is current/voltage and its
output is torque (speed).

Fig 3.9.1: DC Motor

The DC motor has two basic parts: the rotating part that is called the armature and the stationary
part that includes coils of wire called the field coils. The stationary part is also called the stator. Figure
shows a picture of a typical DC motor, Figure shows a picture of a DC armature, and Fig shows a picture
of a typical stator. From the picture you can see the armature is made of coils of wire wrapped around the
core, and the core has an extended shaft that rotates on bearings. You should also notice that the ends of
each coil of wire on the armature are terminated at one end of the armature. The termination points are
called the commutator, and this is where the brushes make electrical contact to bring electrical current
from the stationary part to the rotating part of the machine.
Operation:
The DC motor you will find in modem industrial applications operates very similarly to the simple
DC motor described earlier in this chapter. Figure 12-9 shows an electrical diagram of a simple DC
motor. Notice that the DC voltage is applied directly to the field winding and the brushes. The armature
and the field are both shown as a coil of wire. In later diagrams, a field resistor will be added in series
with the field to control the motor speed.

When voltage is applied to the motor, current begins to flow through the field coil from the
negative terminal to the positive terminal. This sets up a strong magnetic field in the field winding.
Current also begins to flow through the brushes into a commutator segment and then through an armature
coil. The current continues to flow through the coil back to the brush that is attached to other end of the
coil and returns to the DC power source. The current flowing in the armature coil sets up a strong
magnetic field in the armature.

Fig 3.9.2: Simple electrical diagram of DC motor

Fig 3.9.3: Operation of a DC Motor

The magnetic field in the armature and field coil causes the armature to begin to rotate. This
occurs by the unlike magnetic poles attracting each other and the like magnetic poles repelling each other.
As the armature begins to rotate, the commutator segments will also begin to move under the brushes. As
an individual commutator segment moves under the brush connected to positive voltage, it will become
positive, and when it moves under a brush connected to negative voltage it will become negative. In this
way, the commutator segments continually change polarity from positive to negative. Since the
commutator segments are connected to the ends of the wires that make up the field winding in the
armature, it causes the magnetic field in the armature to change polarity continually from North Pole to
South Pole. The commutator segments and brushes are aligned in such a way that the switch in polarity of
the armature coincides with the location of the armature's magnetic field and the field winding's magnetic
field. The switching action is timed so that the armature will not lock up magnetically with the field.
Instead the magnetic fields tend to build on each other and provide additional torque to keep the motor
shaft rotating.
When the voltage is de-energized to the motor, the magnetic fields in the armature and the field
winding will quickly diminish and the armature shaft's speed will begin to drop to zero. If voltage is
applied to the motor again, the magnetic fields will strengthen and the armature will begin to rotate again.

Types of DC motors:

1. DC Shunt Motor,

2. DC Series Motor,

3. DC Long Shunt Motor (Compound)

4. DC Short Shunt Motor (Compound)

The rotational energy that you get from any motor is usually the battle between two magnetic fields
chasing each other. The DC motor has magnetic poles and an armature, to which DC electricity is fed, The
Magnetic Poles are electromagnets, and when they are energized, they produce a strong magnetic field
around them, and the armature which is given power with a commutator, constantly repels the poles, and
therefore rotates.

1. The DC Shunt Motor:

In a 2 pole DC Motor, the armature will have two separate sets of windings, connected to a
commutator at the end of the shaft that are in constant touch with carbon brushes. The brushes are static,
and the commutator rotate and as the portions of the commutator touching the respective positive or
negative polarity brush will energize the respective part of the armature with the respective polarity. It is
usually arranged in such a way that the armature and the poles are always repelling.

The general idea of a DC Motor is, the stronger the Field Current, the stronger the magnetic field,
and faster the rotation of the armature. When the armature revolves between the poles, the magnetic field
of the poles induce power in the armature conductors, and some electricity is generated in the armature,
which is called back emf, and it acts as a resistance for the armature. Generally an armature has resistance
of less than 1 Ohm, and powering it with heavy voltages of Direct Current could result in immediate short
circuits. This back emf helps us there.

When an armature is loaded on a DC Shunt Motor, the speed naturally reduces, and therefore the
back emf reduces, which allows more armatures current to flow. This results in more armature field, and
therefore it results in torque.

Fig 3.9.4: Diagram of DC shunt motor

When a DC Shunt Motor is overloaded, if the armature becomes too slow, the reduction of the
back emf could cause the motor to burn due to heavy current flow thru the armature.

The poles and armature are excited separately, and parallel, therefore it is called a Shunt Motor.

2. The DC Series Motor:

Fig: 3.9.5 Diagram of DC series motor

A DC Series Motor has its field coil in series with the armature. Therefore any amount of power
drawn by the armature will be passed thru the field. As a result you cannot start a Series DC Motor without
any load attached to it. It will either run uncontrollably in full speed, or it will stop.
Fig 3.9.6: Diagram of DC series motor graph representation

When the load is increased then its efficiency increases with respect to the load applied. So these
are on Electric Trains and elevators.

3. DC Compound Motor:

A compound of Series and Shunt excitation for the fields is done in a Compound DC Motor. This
gives the best of both series and shunt motors. Better torque as in a series motor, while the possibility to
start the motor with no load.

Fig 3.9.7: Diagram of DC compound motor

Above is the diagram of a long shunt motor, while in a short shunt, the shunt coil will be connected
after the serial coil.

A Compound motor can be run as a shunt motor without connecting the serial coil at all but not
vice versa.

ESP32-CAMERA

ESP32-CAM is the latest small size camera module released by Essence. The module can work
independently as the smallest system, with a size of only 27*40.5*4.5mm, and a deep sleep current as low
as 6mA.

ESP32-CAM can be widely used in various IoT applications, suitable for home smart devices, industrial
wireless control, wireless monitoring, QR wireless identification, wireless positioning system signals and
other IoT applications. It is an ideal solution for IoT applications .

ESP32-CAM adopts DIP package and can be used directly by plugging in the bottom plate, realizing the
rapid production of products, providing customers with high-reliability connection methods, which is
convenient for application in various IoT hardware terminal occasions.

The ESP32-CAM is a very small camera module with the ESP32-S chip that costs approximately Besides
the OV2640 camera, and several GPIOs to connect peripherals, it also features a microSD card slot that
can be useful to store images taken with the camera or to store files to serve to clients.

Image source – Seeed Studio


The ESP32-CAM doesn’t come with a USB connector, so you need an FTDI programmer to upload code
through the U0R and U0T pins (serial pins).

Features

Here is a list with the ESP32-CAM features:

 The smallest 802.11b/g/n Wi-Fi BT SoC module


 Low power 32-bit CPU,can also serve the application processor
 Up to 160MHz clock speed, summary computing power up to 600 DMIPS
 Built-in 520 KB SRAM, external 4MPSRAM
 Supports UART/SPI/I2C/PWM/ADC/DAC
 Support OV2640 and OV7670 cameras, built-in flash lamp
 Support image WiFI upload
 Support TF card
 Supports multiple sleep modes
 Embedded Lwip and FreeRTOS
 Supports STA/AP/STA+AP operation mode
 Support Smart Config/AirKiss technology
 Support for serial port local and remote firmware upgrades (FOTA)

ESP32-CAM Pinout

The following figure shows the ESP32-CAM pinout (AI-Thinker module).

Image source – Seeed Studio


There are three GND pins and two pins for power: either 3.3V or 5V.
GPIO 1 and GPIO 3 are the serial pins. You need these pins to upload code to your board.
Additionally, GPIO 0 also plays an important role, since it determines whether the ESP32 is in flashing
mode or not. When GPIO 0 is connected to GND, the ESP32 is in flashing mode.
The following pins are internally connected to the microSD card reader:

 GPIO 14: CLK


 GPIO 15: CMD
 GPIO 2: Data 0
 GPIO 4: Data 1 (also connected to the on-board LED)
 GPIO 12: Data 2
 GPIO 13: Data 3

Product Features

Using low-power dual-core 32-bit CPU, can be used as an application processor

Main frequency up to 240MHz, computing power up to 600 DMIPS

Built-in 520 KB SRAM, external 8MB PSRAM

Support UART/SPI/I2C/PWM/ADC/DAC and other interfaces


Support OV2640 and OV7670 cameras, built-in flash

Support picture WiFI upload

Support TF card

Support multiple sleep modes.

Embedded Lwip and FreeRTOS

Support STA/AP/STA+AP working mode

Support Smart Config/AirKiss one-click network configuration

Support secondary development

Application scenarios

Home smart device image transmission

Wireless monitoring

Smart agriculture

QR wireless recognition

i
CHAPTER 7
SOFTWARE DESCRIPTION

The Arduino Software (IDE) makes it easy to write code and upload it to the board offline. We
recommend it for users with poor or no internet connection. This software can be used with any Arduino
board. here are currently two versions of the Arduino IDE, one is the IDE 2.0.0.

7.1 Arduino IDE – Compiler


here are currently two versions of the Arduino IDE, one is the IDE 1.x.x and the other is IDE 2.x. The IDE
2.x is new major release that is faster and even more powerful to the IDE 1.x.x. In addition to a more
modern editor and a more responsive interface it includes advanced features to help users with their coding
and debugging.
The following steps can guide you with using the offline IDE (you can choose either IDE 1.x.x or IDE
2.x):
1. Download and install the Arduino Software IDE:
 Arduino IDE 1.x.x (Windows, Mac OS, Linux, Portable IDE for Windows and Linux, ChromeOS).
 Arduino IDE 2.x
2. Connect your Arduino board to your device.
3. Open the Arduino Software (IDE).
The Arduino Integrated Development Environment - or Arduino Software (IDE) - connects to the
Arduino boards to upload programs and communicate with them. Programs written using Arduino
Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file
extension .ino.
Using the offline IDE 1.x.x
The editor contains the four main areas:
1. A Toolbar with buttons for common functions and a series of menus. The toolbar buttons allow you to
verify and upload programs, create, open, and save sketches, and open the serial monitor.
2. The message area, gives feedback while saving and exporting and also displays errors.
3. The text editor for writing your code.
4. The text console displays text output by the Arduino Software (IDE), including complete error
messages and other information.
The bottom right-hand corner of the window displays the configured board and serial port.
The Arduino Software IDE
Now that you are all set up, let’s try to make your board blink!
5. Connect your Arduino or Genuino board to your computer.
6. Now, you need to select the right core & board. This is done by navigating to Tools > Board >
Arduino AVR Boards > Board. Make sure you select the board that you are using. If you cannot find
your board, you can add it from Tools > Board > Boards Manager.

Selecting a board
7. Now, let's make sure that your board is found by the computer, by selecting the port. This is simply
done by navigating to Tools > Port, where you select your board from the list.

Selecting the port


8. Let’s try an example: navigate to File > Examples > 01.Basics > Blink.

Opening an example
9. To upload it to your board, simply click on the arrow in the top left corner. This process takes a few
seconds, and it is important to not disconnect the board during this process. If the upload is successful, the
message "Done uploading" will appear in the bottom output area.
10. Once the upload is complete, you should then see on your board the yellow LED with an L next to it
start blinking. You can adjust the speed of blinking by changing the delay number in the parenthesis to
100, and upload the Blink sketch again. Now the LED should blink much faster.
The editor contains the four main areas:
1. A toolbar with buttons for common functions and a series of menus. The toolbar buttons allow you to
verify and upload programs, create, open, and save sketches, choose your board and port and open the
serial monitor.
2. The Sidebar for regularly used tools. It gives you quick access to board managers, libraries, debugging
your board as well as a search and replacement tool.
3. The text editor for writing your code.
4. Console controls gives control over the output on the console.
5. The text console displays text output by the Arduino Software (IDE), including complete error
messages and other information.
The bottom right-hand corner of the window displays the configured board and serial port.

The Arduino Software IDE


Now that you are all set up, let’s try to make your board blink!
1. Connect your Arduino or Genuino board to your computer.
2. Now, you need to select the right board & port. This is done from the toolbar. Make sure you select
the board that you are using. If you cannot find your board, you can add it from the board manager in the
sidebar.

Selecting a board & port


3. To upload it to your board, simply click on the arrow in the top left corner. This process takes a few
seconds, and it is important to not disconnect the board during this process. If the upload is successful, the
message "Done uploading" will appear in the bottom output area.
CHAPTER 8
SOURCE CODE

========== DECLARATION ===========

#include <LiquidCrystal.h>
#include <stdio.h>
#include <SoftwareSerial.h>
#include "esp_camera.h"
#include <WiFi.h>
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "fb_gfx.h"
#include "soc/soc.h" // disable brownout problems
#include "soc/rtc_cntl_reg.h" // disable brownout problems
#include "esp_http_server.h"

#elif defined(CAMERA_MODEL_AI_THINKER)

#include <LiquidCrystal.h>
#include <stdio.h>

#include <SoftwareSerial.h>
SoftwareSerial mySerial(A4, A5);

LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

int eye = A0;


int relay = 8;
int vib = 12;
int buzzer = 13;
int gps = 10;
int ctg=0;
char hels='x';
unsigned char rcv,count,gchr='x',gchr1='x',robos='s';

char gpsval[50];

int i=0,k=0,lop=0;
int gps_status=0;
float latitude=0;
float logitude=0;
String Speed="";
String gpsString="";
char *test="$GPRMC";

int sti=0;
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete

char eyes='c';
int eye_flag=0;
int cntlmk=0;

========== SETUP =============

void setup()
{
Serial.begin(9600);//serialEvent();
mySerial.begin(9600);

pinMode(eye, INPUT);
pinMode(vib, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);pinMode(shifter, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(cam_pin, INPUT);

digitalWrite(relay, LOW);
digitalWrite(buzzer, HIGH);
digitalWrite(relay, LOW);
digitalWrite(shifter, LOW);

lcd.begin(16, 2);lcd.cursor();
lcd.print("Helmet Drowsiness");
lcd.setCursor(0,1);
lcd.print("Detection System");
delay(2000);

digitalWrite(shifter, HIGH);
lcd.clear();lcd.print("Getting GPS");
//get_gps();
//gps_convert();
delay(15000);
digitalWrite(shifter, LOW);

lcd.clear();
lcd.setCursor(0,0);
for(ii=0;ii<=6;ii++) lcd.write(finallat[ii]);

lcd.setCursor(0,1);
for(ii=0;ii<=7;ii++) lcd.write(finallong[ii]);

delay(1500);
gsminit();

lcd.clear();
lcd.setCursor(0,0);
lcd.print("E:"); //2-3-4-5-6,0
lcd.setCursor(8,0);
lcd.print("H:"); //10-11,0

lcd.setCursor(0,1);
lcd.print("V:"); //2-3-4-5-6,1
}

========== LOGIC ============

void loop()
{
if(digitalRead(eye) == HIGH)
{
lcd.setCursor(2,0);lcd.print("Open ");
eyes='o';
}
if(digitalRead(eye) == LOW)
{
eye_flag=0;
//lcd.setCursor(12,0);lcd.print("Open ");
lcd.setCursor(2,0);lcd.print(" ");
do{
delay(100);
eye_flag++;
lcd.setCursor(2,0);convertk(eye_flag);
if(eye_flag >= 40)
{
goto lpk;
}
}while(digitalRead(eye) == LOW);

lpk:
if(eye_flag >= 35)
{
eyes='c';
lcd.setCursor(2,0);lcd.print("Close");
digitalWrite(relay, LOW);
digitalWrite(buzzer, LOW);
delay(2000);
}
else{eyes='c';}
eye_flag=0;
}

if(eyes == 'c')
{eyes='x';

digitalWrite(relay,LOW);beep();

delay(5000); delay(4000);delay(5000);
Serial.write("AT+CMGS=\"");
Serial.write(pastnumber);
Serial.write("\"\r\n"); delay(3000);
Serial.write("Eye Close ");
Serial.write("https://www.google.co.in/search?client=opera&q=");
for(ii=0;ii<=6;ii++){Serial.write(finallat[ii]);}
Serial.write("%2C");
for(ii=0;ii<=7;ii++){Serial.write(finallong[ii]);}
Serial.write(0x1A);
delay(5000); delay(4000);
}
if(digitalRead(cam_pin) == LOW)
{
lcd.setCursor(10,0);lcd.print("Wear");
hels='w';
}
if(digitalRead(cam_pin) == HIGH)
{
lcd.setCursor(10,0);lcd.print("N.W ");
ctg++;
if(ctg >= 10)
{ctg=0;
hels='n';
beep();
}
}

if(digitalRead(vib) == LOW)
{
lcd.setCursor(2,1);lcd.print("ON ");

digitalWrite(relay,LOW);beep();

delay(5000); delay(4000);delay(5000);
Serial.write("AT+CMGS=\"");
Serial.write(pastnumber);
Serial.write("\"\r\n"); delay(3000);
Serial.write("Vib ON Accident ");
Serial.write("https://www.google.co.in/search?client=opera&q=");
for(ii=0;ii<=6;ii++){Serial.write(finallat[ii]);}
Serial.write("%2C");
for(ii=0;ii<=7;ii++){Serial.write(finallong[ii]);}
Serial.write(0x1A);
delay(4000); delay(4000); delay(5000);
}
if(digitalRead(vib) == HIGH)
{
lcd.setCursor(2,1);lcd.print("OFF");
}

if(digitalRead(vib) == HIGH && hels == 'w' && eyes == 'o')


{
digitalWrite(relay,HIGH);
}

delay(1000);

============ functions ============

void okcheck()
{
unsigned char rcr;
do{
rcr = Serial.read();
}while(rcr != 'K');
}

void send_link()
{
Serial.write("AT+CMGS=\"");
Serial.write(pastnumber);
Serial.write("\"\r\n"); delay(2500);
Serial.write("https://www.google.co.in/search?client=opera&q=");
for(ii=0;ii<=6;ii++){Serial.write(finallat[ii]);}
Serial.write("%2C");
for(ii=0;ii<=7;ii++){Serial.write(finallong[ii]);}
Serial.write(0x1A);delay(4000);delay(4000);
}

void beep()
{
digitalWrite(buzzer,LOW);delay(2000);digitalWrite(buzzer,HIGH);
}

void serialEvent()
{
while(Serial.available())
{
char inChar = (char)Serial.read();
if(inChar == '*')
{
// gchr = Serial.read();
gchr = 's';
}
i

CHAPTER 10
CONCLUSION

In conclusion, the Smart Helmet for Drowsy Detection System presents a pioneering and
comprehensive solution aimed at significantly improving road safety. By incorporating advanced
technologies such as GPS, GSM, ESP CAM, and a Vibration Sensor, this innovative helmet
addresses a critical aspect of road accidents – drowsy driving. The inclusion of GPS allows for
precise real-time location tracking, providing an additional layer of safety and facilitating
emergency responses.

The GSM integration ensures instant communication capabilities, enabling the helmet to transmit
alerts promptly to predefined contacts. This real-time communication feature is crucial for timely
intervention and assistance when drowsiness is detected. The ESP CAM module introduces visual
data, offering valuable insights for in-depth analysis of the wearer's condition. The fusion of these
technologies creates a robust system capable of proactively identifying and preventing instances of
drowsiness.

A standout feature of the Smart Helmet is the utilization of a Vibration Sensor for accurate
drowsiness detection. This sensor, strategically placed within the helmet, monitors subtle
movements and vibrations associated with fatigue, contributing to the system's precision. Upon
detecting signs of drowsiness, the system triggers an immediate alert, ensuring timely intervention
to avert potential accidents.
In essence, this Smart Helmet represents more than just a wearable device; it embodies a
commitment to advancing road safety through the seamless integration of cutting-edge
technologies. By addressing the significant issue of drowsy driving, this comprehensive solution
strives to make a tangible impact on reducing accidents and promoting safer road experiences. The
fusion of GPS, GSM, ESP CAM, and the Vibration Sensor positions this Smart Helmet at the
forefront of innovative safety measures, paving the way for enhanced protection and well-being of
road users.

REFERENCES
[1] http://timesofindia.indiatimes.com/toireporter/author- Dipak-K–Dash–479213512.cms
[2] http://timesofindia.indiatimes.com/toireporter/author- Dipak-K–Dash–10519.cms
[3] Rattapoom Waranusast, Nannaphat Bundon, Vasan Timtong and Chainaron Tangnoi,“Machine
Vision Techniques for Motorcycle Safety Helmet Detection,” 2013,28th International Conference
on Image and Vision Computing New Zealand.
[4] Romuere Silva, Kelson Aires, Thiago Santos, Kalyf Abdala, Rodrigo Veras “Atomatic detection
of motorcyclists without Helmet,”Departamento de Computaco Universidade Federal do Piaui
Teresina, Brazil. [5] Ping Li, Ramy Meziane, Martin J,Hassan Ezzaidi,Philippe Cardou, “A Smart
Safety Helmet using IMU and EEG sensors for worker fatigue detection,” REPARTI Center, Laval
University Quebec,Canada.
[6] Manjesh N, Prof. Sudarshan Raj,”Smart Helmet Using GSM &GPS Technology for Accident
Detection and Reporting System,” International Journal of Electrical and Electronics Research
ISSN 2348-6988 (online) Vol. 2, Issue 4.
[7] Mohd Khairul Afiq Mohd Rasli, Nina Korlina Madzhi, Juliana Johari ,“Smart Helmet Sensors
for Accident Prevention,” 2013 International Conference on Electrical Electronics and System
Engineering.
[8] Faezah Binti Hashim, “Intelligent Safety Helmet For Motorcyclist,” Faculty of Electronic and
Computer Engineering Universiti Teknikal Malaysia Melaka,2011.

You might also like