Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views63 pages

Sais Document

Uploaded by

Bhanu Varma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views63 pages

Sais Document

Uploaded by

Bhanu Varma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

A

MINI PROJECT REPORT

ON

“SMART ROAD SAFETY AND VEHICLE ACCIDENT PREVENTION


SYSTEM FOR MOUNTAIN AREAS”

Submitted in partial fulfillment of the Requirements


For the award of degree of
BACHELOR OF
TECHNOLOGY IN
ELECTRONICS AND COMMUNICATION ENGINEERING

By
MADIREDDY SAI 21R91A04E0
K. CHANDANA 21R91A049B7
G. VIGNESH 21R91A0483
G. JEEVAN 21R91A0475

Under the guidance of


Mrs. B. Rekha
Associate Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING TEEGALA KRISHNA REDDY ENGINEERING COLLEGE
Medbowli, Meerpet, Saroor Nagar, Hyderabad-
097 Affiliated to JNTUH, Hyderabad
2021-2025
CERTIFICATE

This is to certify that the Mini Project work entitled “SMART ROAD SAFETY

AND VEHICLE ACCIDENT PREVENTION SYSTEM FOR MOUNTAIN


AREAS”. That is being submitted by MADIREDDY SAI (21R91A04E0), K. CHANDANA
(21R91A04B7), G. VIGNESH (21R91A0483) & G. JEEVAN (21R91A0475). In partial
fulfillment of the requirements for the award of BACHELOR OF TECHNOLOGY

in ELECTRONICS AND COMMUNICATION ENGINEERING in J.N.T.U.H,


during the academic year 2024- 2025.

PROJECT GUIDE PROJECT COORDINATOR


Mrs. B. Rekha Dr. E. RADHAMMA
ASSISTANT PROFESSOR ASSOCIATE PROFESSOR

HEAD OF THE DEPARTMENT EXTERNAL


EXAMINER Dr. SK. UMAR FARUQ
PROFESSOR AND HEAD
DECLARATION

We, MADIREDDY SAI (21R91A04E0),K.CHANDANA (21R91A04B7) ,G.VIGNESH


(21R91A0483) & G.JEEVAN (21R91A0475) hereby declare that the work embodied in this
Mini project entitled “SMART ROAD SAFETY AND VEHICLE ACCIDENT

PREVENTIONS SYSTEM FOR MOUNTAIN AREAS ” submitted to Jawaharlal


Nehru Technological University, Hyderabad, for partial fulfillment of the Award of
BACHELOR OF TECHNOLOGY in ELECTRONICS AND COMMUNICATION
ENGINEERING by J.N.T.U.H, during the Academic year 2024-25 has been carried out by us
under the supervision of Mrs. B. Rekha, Associate Professor. To the best of our knowledge,
this work has not been submitted for any other degree in any University.

MADIREDDI SAI 21R91A04E0


K. CHANDANA 21R91A04B7
G. VIGNESH 21R91A0483
G. JEEVAN 21R91A0475
ACKNOWLEDGEMENT

The satisfaction and euphoria the 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 crowned our efforts with success.
First, We would like to thank our Mini Project guide Mrs. B. Rekha, Associate Professor in
Department of E.C.E., for her inspiration, adroit guidance and constructive criticism for completion of
our degree.
We would like to convey our special thanks to the Minor Project Co-Ordinator Mrs. Dr. E.
RADHAMMA, Associate Professor in Department of E.C.E., for her valuable guidance and
suggestions in analyzing and testing throughout the period, till the end of this work completion.
Also, we would like to express our sincere gratitude to Dr. SK. UMAR FARUQ. Professor Head
of Department in Electronics & Communication Engineering during the progress of the Project work,
for his timely suggestions and help in spite of his busy schedule.
We would like to convey our special gratitude to the Vice-Principal and Dean of Academics at
Teegala Krishna Reddy Engineering College Dr. B. SRINIVASA RAO, Professor in Department of
ECE., for his inspiration, adroit guidance and constructive criticism for completion of this work.
Our acknowledgement extended to Principal Dr. K.V. MURALI MOHAN, Principal of
TEEGALA KRISHNA REDDY ENGINEERING COLLEGE for his
consistent help and encouragement to complete the research work.

We are very much thankful to TKR EDUCATIONAL SOCIETY on behalf of our beloved
Chairman Sri TEEGALA KRISHNA REDDY Garu for their help in providing good facilities in our
college.

MADIREDDY SAI 21R91A04E0


K. CHANDANA 21R91A04B7
G. VIGNESH 21R91A0483
G. JEEVAN 21R91A0475
TABLE OF CONTENT

ABSTRACT
LIST OF FIGURES
CHAPTER 1: INTRODUCTION 1-2

1.1 Introduction of the Project. 1

1.1.1 The main objectives of project 1

1.2 Project overview 2

1.3 Thesis 2

CHAPTER 2: BLOCK DIAGRAM 3-4

2.1 Introduction of block diagram. 3

2.2 Schematic diagram 4

CHAPTER 3: HARDWARE DESCRIPTION 5-36

3.1 Arduino uno Microcontroller 5

3.1.1 Pin description 7

3.1.2 ATmega328 9

3.1.3 AVR CPU core 11

3.2 Adapter power supply. 19

3.2.1 Introduction. 19

3.3.2 Block diagram 20

3.3 LED. 27

3.4 IR sensor. 29

3.5 LCD display 32

i
CHAPTER 4: SOFTWARE DESCRIPTION 37-41

CHAPTER 5: ADVANTAGES, DISADVANTAGES AND APPLICATIONS 42

CHAPTER 6: RESULT 43-44


CONCLUSION 45
FUTURE SCOPE 46
REFERENCES 47
APPENDIX 48-49

ii
ABSTRACT

The main aim of this project is to design a vehicle accident prevention system using Arduino
and IR sensors.
Growth in population has led to growth in technology. People use car on large number and
number of accidents taking place, is increasing day-by-day. Road accidents are undoubtedly the most
frequent happening cases and overall, the cause of the most damage. There are many dangerous roads
in the world like mountain roads, narrow curve roads, T roads. Some mountain roads are very narrow
and they have many curves. The problems in these curve roads are that the drivers are not able to see
the vehicle or obstacles coming from another end of the curve. If the vehicle is in great speed, then it
is difficult to control and there are chances of falling off a cliff. Hence there is a need of many road
safety systems. To avoid these problems in curve roads of mountain areas, we have proposed this
vehicle accident prevention system.

iii
LIST OF FIGURES

2.1 Block diagram 3


2.2 schematic diagram 4
3.1 micro controller 5
3.2 pin diagram 7
3.3 ATmega328 Architecture 10
3.4 Comparison Between ATmega48PA, ATmega88PA, ATmega168PA and ATmega328P
3.5 block diagram of AVR Architecture 12
3.6cristal oscillation connection 16
3.7 Regulated power supply 19
3.8 Circuit diagram of Regulated Power Supply with Led connection
3.9 Step down transformer 21
3.10
3.11 DB107 24
3.12 Construction of capacitor 25
3.13 Electrolyte capacitor 25
3.14 Voltage regulator 26
3.15(a) Inside a LED 27
3.15(B) Parts of LED 27
3.16 Electrical symbol & polarities of LED 28
3.17(a) IR sensor module 29
3.17(b) IR sensor module pin out 29
3.17(c) IR sensor parts 30
3.18(a) LCD pin diagram 32
3.18(b) Schematic diagram 34
4.1 Home page of Arduino IDE software 37
4.2 Installation of page 38
4.3 Board selector page 39
4.4 Tool menu page 40
4.5 Package & Board 40
4.6 Port selector page 41

iv
6.1 Initially Both 42
6.2 Vehicle from left side of the road 43
6.3 vehicle from right side of the road 43
6.4 Both vehicles are each other 44

v
LIST OF ABBREVIATIONS

RADAR - radio aided detection and


ranging RAM - random access memory
JTAG - joint test action group
FPGA - field programmable gate
array JTAG - joint test action group
RTOS - real time operating system
EEPROM - Electrically Erasable Programmable Random Access Memory
PWM - pulse width modulation
ADC - analog to digital converter
GND - ground
ALU - arithmetic logic unit
RISC - reduced instruction set computer
CISC - complexed instruction set computer
Rx - receiver
Tx - transmitter
RPS - regulated power supply
IDE - integrated development environment

vi
CHAPTER 1
INTRODUCTION

1.1 Introduction:

The main aim of this project is to design a vehicle accident prevention system using Arduino
and IR sensors.

Growth in population has led to growth in technology. People use car on large number and
number of accidents taking place, is increasing day-by-day. Road accidents are undoubtedly the most
frequent happening cases and overall, the cause of the most damage. There are many dangerous roads
in the world like mountain roads, narrow curve roads, T roads. Some mountain roads are very narrow
and they have many curves. The problems in these curve roads are that the drivers are not able to see
the vehicle or obstacles coming from another end of the curve. If the vehicle is in great speed, then it
is difficult to control and there are chances of falling off a cliff. Hence there is a need of many road
safety systems. To avoid these problems in curve roads of mountain areas, we have proposed this
vehicle accident prevention system.

The main controlling device of the project is Arduino UNO Microcontroller. This project
makes a use of IR sensors, green and red LED lights. When two cars pass from the opposite side of a
mountain curve the IR sensor senses the car and process this signal to the microcontroller then the
microcontroller turn on the RED LED which can gives the indication of oppositive side of the vehicle.
And then it changes one LED color into green to allow the one car to pass and then the other LED
color turns green. In this way we can prevent the accidents of curved road. The status of the project
will display on LCD. To achieve this task Arduino loaded program written in embedded C language.

1.1.1 The main objectives of the project are:

1. Design a vehicle accident prevention system using IR sensor.


2. Green, RED LED indications.
3. Visible alerts using LCD display.

1
1.2 Project Overview:

An embedded system is a combination of software and hardware to perform a dedicated task.


Some of the main devices used in embedded products are Microprocessors and Microcontrollers.
Microprocessors are commonly referred to as general purpose processors as they simply
accept the inputs, process it and give the output. In contrast, a microcontroller not only accepts the
data as inputs but also manipulates it, interfaces the data with various devices, controls the data and
thus finally gives the result.
The project Smart Road Safety and Vehicle Accident Prevention System for Mountain
Roads using Arduino UNO Microcontroller is an exclusive project that can prevent the vehicle
accidents in hill areas using IR sensors and LEDs. Which side the vehicle comes will be displayed on
the LCD.
1.3 Thesis Overview:

The thesis explains the implementation of “Smart Road Safety and Vehicle Accident
Prevention System for Mountain Roads” using Arduino uno microcontroller. The organization of
the thesis is explained here with:

Chapter 1 Presents introduction to the overall thesis and the overview of the project. In the project
overview a brief introduction of Smart Road Safety and Vehicle Accident Prevention System for
Mountain Roads and its applications are discussed.

Chapter 2 Presents the topic embedded systems. It explains the about what is embedded systems,
need for embedded systems, explanation of it along with its applications.

Chapter 3 Presents the hardware description. It deals with the block diagram of the project and
explains the purpose of each block. In the same chapter the explanation of microcontroller, power
supplies, IR transmitter and IR receiver, LCD display and LEDs are considered.

Chapter 4 Presents the software description. It explains the implementation of the project using
Arduino IDE Compiler software.

Chapter 5 Presents the project Circuit diagram.

Chapter 6 Presents the advantages, disadvantages and applications of the project.

Chapter 7 Presents the results, conclusion and future scope of the project.

2
CHAPTER 2

BLOCK DIAGRAM
2.1 Introduction:

The block diagram of the project and design aspect of independent modules are considered.
Block diagram is shown in fig: 2.1:

FIG 2.1: Block diagram of Smart Road Safety and Vehicle Accident Prevention System for
Mountain Roads

2.2 Schematic diagram

In this chapter, schematic diagram and interfacing of Arduino uno microcontroller with each
module is considered.

3
Fig 2.2: Schematic diagram of Smart Road Safety and Vehicle Accident Prevention System for
Mountain Roads

The above schematic diagram of Smart Road Safety and Vehicle Accident Prevention System
for Mountain Roads system explains the interfacing section of each component with micro controller
and IR sensors.

4
CHAPTER 3
HARDWARE DESCRIPTION

The main blocks of this project are:


 Arduino uno micro-Controller.
 Adapter Power Supply
 Green, Red LED indicators.
 IR sensors
 LCD display.
3.1 Arduino uno micro-Controller.

Fig 3.1 Micro controller

 The Arduino Uno is a microcontroller board which has ATmega328 from the AVR family.
There are 14 digital input/output pins, 6 Analog pins and 16MHz ceramic resonator.
 USB connection, power jack and also a reset button is used. Its software is supported by
a number of libraries, which makes the programming easier.

ATMEGA328:

Features

• High Performance, Low Power AVR® 8-Bit Microcontroller

5
• Advanced RISC Architecture

– 131 Powerful Instructions – Most Single Clock Cycle Execution

– 32 x 8 General Purpose Working Registers

– Fully Static Operation

– Up to 20 MIPS Throughput at 20 MHz

– On-chip 2-cycle Multiplier

• High Endurance Non-volatile Memory Segments

– 4/8/16/32K Bytes of In-System Self-Programmable Flash progam memory

(ATmega48PA/88PA/168PA/328P)

– 256/512/512/1K Bytes EEPROM (ATmega48PA/88PA/168PA/328P)

– 512/1K/1K/2K Bytes Internal SRAM (ATmega48PA/88PA/168PA/328P)

– 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

• Special Microcontroller Features

– Power-on Reset and Programmable Brown-out Detection

– Internal Calibrated Oscillator

– External and Internal Interrupt Sources

– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby,

6
and Extended Standby

• I/O and Packages

– 23 Programmable I/O Lines

– 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF

• Operating Voltage:

– 1.8 - 5.5V for ATmega48PA/88PA/168PA/328P

• Temperature Range:

– -40°C to 85°C

• Speed Grade:

– 0 - 20 MHz @ 1.8 - 5.5V

3.1.1 Pin Descriptions

Fig 3.2 pin diagram

7
VCC Digital

 supply voltage.

GND

 Ground.

Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2

Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each it).
The Port B output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if
the clock is not running. Depending on the clock selection fuse settings, PB6 can be used as input to
the inverting Oscillator amplifier and input to the internal clock operating circuit. Depending on the
clock selection fuse settings, PB7 can be used as output from the inverting Oscillator amplifier.

If the Internal Calibrated RC Oscillator is used as chip clock source, PB7.6 is used as
TOSC2.1 input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set. The various
special features of Port B are elaborated in” Alternate Functions of Port B” on page 82 and” System
Clock and Clock Options” on page 26.

Port C (PC5:0)

Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each it).
The PC5.0 output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if
the clock is not running.

PC6/RESET

If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the electrical
characteristics of PC6 differ from those of the other pins of Port C. If the RSTDISBL Fuse is un

8
programmed, PC6 is used as a Reset input. A low level on this pin for longer than the minimum pulse
length will generate a Reset, even if the clock is not running.

The minimum pulse length is given in Table 28-3 on page 318. Shorter pulses are not
guaranteed to generate a Reset. The various special features of Port C are elaborated in” Alternate
Functions of Port C” on page 85.

Port D (PD7:0)

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
The Port D output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if
the clock is not running. The various special features of Port D are elaborated in” Alternate Functions
of Port D” on page88.

AVCC

AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should be
externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected
to VCC through a low-pass filter. Note that PC6.4 use digital supply voltage, VCC.

AREF

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

ADC 7:6 (TQFP and QFN/MLF Package Only)

In the TQFP and QFN/MLF package, ADC7:6 serve as analog inputs to the A/D converter.
These pins are powered from the analog supply and serve as 10-bit ADC channels.

3.1.2 ATmega328

Overview

The ATmega48PA/88PA/168PA/328P is a low-power CMOS 8-bit microcontroller based on


the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the

9
ATmega48PA/88PA/168PA/328P achieves throughputs approaching 1 MIPS per MHz allowing the
system designer to optimize power consumption versus processing speed.

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

Fig 3.3 ATmega328 Architecture

The ATmega48PA/88PA/168PA/328P provides the following features: 4K/8K bytes of In-


System Programmable Flash with Read-While-Write capabilities, 256/512/512/1K bytes EEPROM,
512/1K/1K/2K bytes SRAM, 23 general purpose I/O lines, 32 general purpose working registers,

1
three flexible Timer/Counters with compare modes, internal and external interrupts, a serial
programmable

1
USART, a byte-oriented 2-wire Serial Interface, an SPI serial port, a 6-channel 10-bit ADC (8
channels in TQFP and QFN/MLF packages), a programmable Watchdog Timer with internal
Oscillator, and five software selectable power saving modes. The Idle mode stops the CPU while
allowing the SRAM, Timer/Counters, USART, 2-wire Serial Interface, SPI port, and interrupt system
to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator,
disabling all other chip functions until the next interrupt or hardware reset.

The ATmega48PA/88PA/168PA/328P AVR is supported with a full suite of program and


system development tools including: C Compilers, Macro Assemblers, Program
Debugger/Simulators, In-Circuit Emulators, and Evaluation kits.

Fig 3.4 Comparison Between ATmega48PA, ATmega88PA, ATmega168PA and ATmega328P

ATmega88PA, ATmega168PA and ATmega328P support a real Read-While-Write Self-


Programming mechanism. There is a separate Boot Loader Section, and the SPM instruction can only
execute from there. In ATmega48PA, there is no Read-While-Write support and no separate Boot
Loader Section. The SPM instruction can execute from the entire Flash.

3.1.3 AVR CPU Core


Overview
This section discusses the AVR core architecture in general. The main function of the CPU
core is to ensure correct program execution. The CPU must therefore be able to access memories,
perform calculations, control peripherals, and handle interrupts.

1
Fig 3.5 block diagram of AVR architecture

In order to maximize performance and parallelism, the AVR uses a Harvard architecture –
with separate memories and buses for program and data. Instructions in the program memory are
executed with a single level pipelining. While one instruction is being executed, the next instruction is
pre-fetched from the program memory. This concept enables instructions to be executed in every
clock cycle. The program memory is In-System Reprogrammable Flash memory.

The fast-access Register File contains 32 x 8-bit general purpose working registers with a
single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a
typical ALU operation, two operands are output from the Register File, the operation is executed, and
the result is stored back in the Register File – in one clock cycle. Six of the 32 registers can be used as
three 16- bit indirect address register pointers for Data Space addressing – enabling efficient address
calculations. One of these address pointers can also be used as an address pointer for look up tables in
Flash program
1
memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this
section.

The ALU supports arithmetic and logic operations between registers or between a constant and
a register. Single register operations can also be executed in the ALU. After an arithmetic operation,
the Status Register is updated to reflect information about the result of the operation.

Program flow is provided by conditional and unconditional jump and call instructions, able to
directly address the whole address space. Most AVR instructions have a single 16-bit word format.
Every program memory address contains a 16- or 32-bit instruction.

Program Flash memory space is divided in two sections, the Boot Program section and the
Application Program section. Both sections have dedicated Lock bits for write and read/write
protection. The SPM instruction that writes into the Application Flash memory section must reside in
the Boot Program section.

During interrupts and subroutine calls, the return address Program Counter (PC) is stored on
the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the Stack
size is only limited by the total SRAM size and the usage of the SRAM. All user programs must
initialize the SP in the Reset routine (before subroutines or interrupts are executed). The Stack Pointer
(SP) is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five
different addressing modes supported in the AVR architecture.

The memory spaces in the AVR architecture are all linear and regular memory maps.

A flexible interrupt module has its control registers in the I/O space with an additional Global
Interrupt Enable bit in the Status Register. All interrupts have a separate Interrupt Vector in the
Interrupt Vector table. The interrupts have priority in accordance with their Interrupt Vector position.

The I/O memory space contains 64 addresses for CPU peripheral functions as Control Registers,

SPI, and other I/O functions. The I/O Memory can be accessed directly, or as the Data Space
locations following those of the Register File, 0x20 - 0x5F. In addition, the
ATmega48PA/88PA/168PA/328P has Extended I/O space from 0x60 - 0xFF in SRAM where only
the ST/STS/STD and LD/LDS/LDD instructions can be used.

1
ALU – Arithmetic Logic Unit

The high-performance AVR ALU operates in direct connection with all the 32 general purpose
working registers. Within a single clock cycle, arithmetic operations between general purpose
registers or between a register and an immediate are executed. The ALU operations are divided into
three main categories – arithmetic, logical, and bit-functions. Some implementations of the
architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and
fractional format. See the “Instruction Set” section for a detailed description.

Status Register

The Status Register contains information about the result of the most recently executed
arithmetic instruction. This information can be used for altering program flow in order to perform
conditional operations. Note that the Status Register is updated after all ALU operations, as specified
in the Instruction Set Reference. This will in many cases remove the need for using the dedicated
compare instructions, resulting in faster and more compact code. The Status Register is not
automatically stored when entering an interrupt routine and restored when returning from an interrupt.
This must be handled by software.

AVR Memories

Overview

This section describes the different memories in the ATmega48PA/88PA/168PA/328P. The


AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. In
addition, the ATmega48PA/88PA/168PA/328P features an EEPROM Memory for data storage. All
three memory spaces are linear and regular.

In-System Reprogrammable Flash Program Memory

The ATmega48PA/88PA/168PA/328P contains 4/8/16/32K bytes On-chip In-System


Reprogrammable Flash memory for program storage. Since all AVR instructions are 16 or 32 bits
wide, the Flash is organized as 2/4/8/16K x 16. For software security, the Flash Program memory
space is divided into two sections, Boot Loader Section and Application Program Section in
ATmega88PA and ATmega168PA. See SELFPRGEN description in section” SPMCSR – Store
Program Memory Control and Status Register” on page 292 for more details.

1
The Flash memory has an endurance of at least 10,000 write/erase cycles. The
ATmega48PA/88PA/168PA/328P Program Counter (PC) is 11/12/13/14 bits wide, thus addressing
the 2/4/8/16K program memory locations. The operation of Boot Program section and associated
Boot Lock bits for software protection are described in detail in” Self-Programming the Flash,
ATmega48PA” on page 269 and” Boot Loader Support – Read-While-Write Self-Programming,
ATmega88PA, ATmega168PA and ATmega328P” on page 277.” Memory Programming” on page
294 contains a detailed description on Flash Programming in SPI- or Parallel Programming mode.

Constant tables can be allocated within the entire program memory address space (see the
LPM – Load Program Memory instruction description).

SRAM Data Memory

The ATmega48PA/88PA/168PA/328P is a complex microcontroller with more peripheral


units than can be supported within the 64 locations reserved in the Opcode for the IN and OUT
instructions. For the Extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and
LD/LDS/LDD instructions can be used. The lower 768/1280/1280/2303 data memory locations
address both the Register File, the I/O memory, Extended I/O memory, and the internal data SRAM.
The first 32 locations address the Register File, the next 64 location the standard I/O memory, then
160 locations of Extended I/O memory, and the next 512/1024/1024/2048 locations address the
internal data SRAM.

The five different addressing modes for the data memory cover: Direct, Indirect with
Displacement, Indirect, Indirect with Pre-decrement, and Indirect with Post-increment. In the Register
File, registers R26 to R31 feature the indirect addressing pointer registers.

The direct addressing reaches the entire data space. The Indirect with Displacement mode
reaches 63 address locations from the base address given by the Y- or Z-register.

When using register indirect addressing modes with automatic pre-decrement and post-
increment, the address registers X, Y, and Z are decremented or incremented. The 32 general purpose
working registers, 64 I/O Registers, 160 Extended I/O Registers, and the 512/1024/1024/2048 bytes of
internal data SRAM in the ATmega48PA/88PA/168PA/328P are all accessible through all these
addressing modes.

1
EEPROM Data Memory

The ATmega48PA/88PA/168PA/328P contains 256/512/512/1K bytes of data EEPROM


memory. It is organized as a separate data space, in which single bytes can be read and written. The
EEPROM has an endurance of at least 100,000 write/erase cycles. The access between the EEPROM
and the CPU is described in the following, specifying the EEPROM Address Registers, the EEPROM
Data Register, and the EEPROM Control Register.

EEPROM Read/Write Access

The EEPROM Access Registers are accessible in the I/O space.

Let’s the user software detect when the next byte can be written. If the user code contains instructions
that write the EEPROM, some precautions must be taken. In heavily filtered power supplies, VCC is
likely to rise or fall slowly on power-up/down. This causes the device for some period of time to run
at a voltage lower than specified as minimum for the clock frequency used. In order to prevent
unintentional EEPROM writes, a specific write procedure must be followed. Refer to the description
of the EEPROM Control Register for details on this. When the EEPROM is read, the CPU is halted
for four clock cycles before the next instruction is executed. When the EEPROM is written, the CPU
is halted for two clock cycles before the next instruction is executed.

Low Power Crystal Oscillator

Pins 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. This Crystal Oscillator is a low power oscillator, with reduced voltage swing on the XTAL2
output.

It gives the lowest power consumption, but is not capable of driving other clock inputs, and may be
more susceptible to noise in noisy environments. 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.

1
Fig 3.5 Crystal oscillator connection

Watchdog Timer

Features

• Clocked from separate On-chip Oscillator

• 3 Operating modes

o Interrupt

o System Reset

o Interrupt and System Reset

• Selectable Time-out period from 16ms to 8s

• Possible Hardware fuse Watchdog always on (WDTON) for fail-safe mode

Overview

ATmega48PA/88PA/168PA/328P has an Enhanced Watchdog Timer (WDT). The WDT is a


timer counting cycles of a separate on-chip 128 kHz oscillator. The WDT gives an interrupt or a
system reset when the counter reaches a given time-out value. In normal operation mode, it is required
that the system uses the WDR - Watchdog Timer Reset - instruction to restart the counter before the
time-out value is reached. If the system doesn't restart the counter, an interrupt or system reset will be
issued.

In Interrupt mode, the WDT gives an interrupt when the timer expires. This interrupt can be
used to wake the device from sleep-modes, and also as a general system timer. One example is to limit

1
the maximum time allowed for certain operations, giving an interrupt when the operation has run
longer

1
than expected. In System Reset mode, the WDT gives a reset when the timer expires. This is typically
used to prevent system hang-up in case of runaway code. The third mode, Interrupt and System Reset
mode, combines the other two modes by first giving an interrupt and then switch to System Reset
mode. This mode will for instance allow a safe shutdown by saving critical parameters before a
system reset.

The Watchdog always on (WDTON) fuse, if programmed, will force the Watchdog Timer to
System Reset mode. With the fuse programmed the System Reset mode bit (WDE) and Interrupt
mode bit (WDIE) are locked to 1 and 0 respectively. To further ensure program security, alterations to
the Watchdog set-up must follow timed sequences. The sequence for clearing WDE and changing
time-out configuration is as follows:

1. In the same operation, write a logic one to the Watchdog change enable bit (WDCE) and WDE. A
logic one must be written to WDE regardless of the previous value of the WDE bit.

2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP) as desired,
but with the WDCE bit cleared. This must be done in one operation.

The following code example shows one assembly and one C function for turning off the
Watchdog Timer. The example assumes that interrupts are controlled (e.g. by disabling interrupts
globally) so that no interrupts will occur during the execution of these functions.

8-bit Timer/Counter0 with PWM

Features

 Two Independent Output Compare Units

 Double Buffered Output Compare Registers

 Clear Timer on Compare Match (Auto Reload)

 Glitch Free, Phase Correct Pulse Width Modulator (PWM)

 Variable PWM Period

 Frequency Generator

 Three Independent Interrupt Sources (TOV0, OCF0A, and OCF0B)

2
Overview

Timer/Counter0 is a general purpose 8-bit Timer/Counter module, with two independent


Output Compare Units, and with PWM support. It allows accurate program execution timing (event
management) and wave generation.

CPU accessible I/O Registers, including I/O bits and I/O pins, are shown in bold.

3.2 ADAPTER POWER SUPPLY:

3.2.1 Introduction:

Power supply is a supply of electrical power. A device or system that supplies


electrical or other types of energy to an output load or group of loads is called a power supply unit or
PSU. The term is most commonly applied to electrical energy supplies, less often to mechanical ones,
and rarely to others.

A power supply may include a power distribution system as well as primary or


secondary sources of energy such as

 Conversion of one form of electrical power to another desired form and voltage, typically
involving converting AC line voltage to a well-regulated lower-voltage DC for electronic devices.
Low voltage, low power DC power supply units are commonly integrated with the devices they
supply, such as computers and household electronics.
 Batteries.
 Chemical fuel cells and other forms of energy storage systems.
 Solar power.
 Generators or alternators.
3.2.2 Block Diagram:

Fig 3.7 Regulated Power Supply

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

Fig 3.8 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.

Transformers:

A transformer is a device that transfers electrical energy from one circuit to another
through inductively coupled conductors without changing its frequency. A varying current in the first
or primary winding creates a varying magnetic flux in the transformer's core, and thus a

2
varying magnetic field through the secondary winding. This varying magnetic field induces a
varying electromotive force (EMF) or "voltage" in the secondary winding. This effect is called mutual
induction.

If a load is connected to the secondary, an electric current will flow in the secondary winding
and electrical energy will be transferred from the primary circuit through the transformer to the load.
This field is made up from lines of force and has the same shape as a bar magnet.

If the current is increased, the lines of force move outwards from the coil. If the current is
reduced, the lines of force move inwards.

If another coil is placed adjacent to the first coil then, as the field moves out or in, the moving
lines of force will "cut" the turns of the second coil. As it does this, a voltage is induced in the second
coil. With the 50 Hz AC mains supply, this will happen 50 times a second. This is called MUTUAL
INDUCTION and forms the basis of the transformer.

The input coil is called the PRIMARY WINDING; the output coil is the SECONDARY
WINDING. Fig: 3.9 shows step-down transformer.

Fig 3.9: Step-Down Transformer

The voltage induced in the secondary is determined by the TURNS RATIO.

For example, if the secondary has half the primary turns; the secondary will have half
the
primary voltage.

2
Another example is if the primary has 5000 turns and the secondary has 500 turns, then the
turn’s ratio is 10:1.

If the primary voltage is 240 volts then the secondary voltage will be x 10 smaller = 24 volts.
Assuming a perfect transformer, the power provided by the primary must equal the power taken by a
load on the secondary. If a 24-watt lamp is connected across a 24 volt secondary, then the primary
must supply 24 watts.

To aid magnetic coupling between primary and secondary, the coils are wound on a metal
CORE. Since the primary would induce power, called EDDY CURRENTS, into this core, the core is
LAMINATED. This means that it is made up from metal sheets insulated from each other.
Transformers to work at higher frequencies have an iron dust core or no core at all.

Note that the transformer only works on AC, which has a constantly changing current and
moving field. DC has a steady current and therefore a steady field and there would be no induction.

Some transformers have an electrostatic screen between primary and secondary. This is to
prevent some types of interference being fed from the equipment down into the mains supply, or in
the other direction. Transformers are sometimes used for IMPEDANCE MATCHING.

We can use the transformers as step up or step down.

Step Up transformer:

In case of step-up transformer, primary windings are every less compared to secondary
winding. Because of having more turns secondary winding accepts more energy, and it releases more
voltage at the output side.

Step down transformer:

In case of step-down transformer, Primary winding induces more flux than the secondary
winding, and secondary winding is having a smaller number of turns because of that it accepts a
smaller number of fluxes, and releases less amount of voltage.

2
Rectification:

The process of converting an alternating current to a pulsating direct current is called as rectification.
For rectification purpose we use rectifiers

Bridge full wave rectifier:

The Bridge rectifier circuit is shown in fig: 3.10, 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 RL 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 3.10: Bridge rectifier: a full-wave rectifier using 4 diodes

2
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.11.

Features:

 Good for automation insertion


 Surge overload rating - 30 amperes peak
 Ideal for printed circuit board
 Reliable low-cost construction utilizing molded
 Glass passivated device
 Polarity symbols molded on body
 Mounting position: Any
 Weight: 1.0 gram

Fig 3.11: DB107

Filtration:

The process of converting a pulsating direct current to a pure direct current using filters is
called as filtration.

Filters:

Electronic filters are electronic circuits, which perform signal-processing functions, specifically
to remove unwanted frequency components from the signal, to enhance wanted ones.

2
Introduction to Capacitors:

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.12 and 3.13 respectively.

Fig 3.12:Construction Of a Capacitor Fig 3.13:Electrolytic Capaticor

Regulation:

The process of converting a varying voltage to a constant regulated voltage is called as

2
regulation. For the process of regulation, we use voltage regulators.

2
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.14 shows voltage regulator.

Fig 3.14: Voltage Regulator

Resistors:

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

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

Resistors can be made to control the flow of current, to work as Voltage dividers, to dissipate
power and it can shape electrical waves when used in combination of other components. Basic unit is
ohms.

3.3. LED:

A light-emitting diode (LED) is a semiconductor light source. LEDs are used as indicator
lamps in many devices, and are increasingly used for lighting. Introduced as a practical electronic
component in 1962, early LEDs 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.15(a) and 3.15(b) respectively.

Fig 3.15(a): Inside a LED Fig 3.15(b): Parts of a LED

3
Working:

The structure of the LED light is completely different than that of the light bulb. Amazingly, the LED
has a simple and strong structure. The light-emitting semiconductor material is what determines the
LED's color. The LED is based on the semiconductor diode.

When a diode is forward biased (switched on), electrons are able to recombine with holes
within the device, releasing energy in the form of photons. This effect is called electroluminescence
and the color of the light (corresponding to the energy of the photon) is determined by the energy gap
of the semiconductor. An LED is usually small in area (less than 1 mm 2), and integrated optical
components are used to shape its radiation pattern and assist in reflection. LED’s present many
advantages over incandescent light sources including lower energy consumption, longer lifetime,
improved robustness, smaller size, faster switching, and greater durability and reliability. However,
they are relatively expensive and require more precise current and heat management than traditional
light sources. Current LED products for general lighting are more expensive to buy than fluorescent
lamp sources of comparable output. They also enjoy use in applications as diverse as replacements for
traditional light sources in automotive lighting (particularly indicators) and in traffic signals. The
compact size of LED’s has allowed new text and video displays and sensors to be developed, while
their high switching rates are useful in advanced communications technology. The electrical symbol
and polarities of led are shown in fig: 3.16.

Fig 3.16: Electrical Symbol & Polarities of LED

LED lights have a variety of advantages over other light sources:

 High-levels of brightness and intensity


3
 High-efficiency
 Low-voltage and current requirements
 Low radiated heat
 High reliability (resistant to shock and vibration)
 No UV Rays
 Long source life
 Can be easily controlled and programmed

Applications of LED fall into three major categories:

 Visual signal application where the light goes more or less directly from the LED to the
human eye, to convey a message or meaning.
 Illumination where LED light is reflected from object to give visual response of these objects.
 Generate light for measuring and interacting with processes that do not involve the human
visual system.

3.4 IR sensor:
IR Sensor Module:

Fig 3.17(a) IR Sensor Module Fig 3.17(b) IR Sensor Module Pinout

3
Pin Configuration:

Pin Name Description

VCC Power Supply Input

GND Power Supply Ground

OUT Active High Output

IR Sensor Module Features:

 5VDC Operating voltage


 I/O pins are 5V and 3.3V compliant
 Range: Up to 20cm
 Adjustable Sensing range
 Built-in Ambient Light Sensor
 20mA supply current
 Mounting hole

Brief about IR Sensor Module:

Fig 3.17(c) IR sensor parts

3
The IR sensor module consists mainly of the IR Transmitter and Receiver, Op-amp, Variable
Resistor (Trimmer pot), output LED in brief.

IR LED Transmitter:

IR LED emits light, in the range of Infrared frequency. IR light is invisible to us as its
wavelength (700nm – 1mm) is much higher than the visible light range. IR LEDs have light emitting
angle of approx. 20-60 degree and range of approx. few centimeters to several feet’s, it depends upon
the type of IR transmitter and the manufacturer. Some transmitters have the range in kilometers. IR
LED white or transparent in color, so it can give out amount of maximum light.

Photodiode Receiver:

Photodiode acts as the IR receiver as its conducts when light falls on it. Photodiode is a
semiconductor which has a P-N junction, operated in Reverse Bias, means it start conducting the
current in reverse direction when Light falls on it, and the amount of current flow is proportional to
the amount of Light. This property makes it useful for IR detection. Photodiode looks like a LED,
with a black colour coating on its outer side, Black colour absorbs the highest amount of light.

IR Sensor Module Features

 5VDC Operating voltage


 I/O pins are 5V and 3.3V compliant
 Range: Up to 20cm
 Adjustable Sensing range
 Built-in Ambient Light Sensor
 20mA supply current
 Mounting hole
Applications

 Obstacle Detection
 Industrial safety devices
 Wheel encoder

3
3.5 LCD display:

LCD Background:

One of the most common devices attached to a micro controller is an LCD display. Some of the most
common LCDs 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

Fig 3.18(a) 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

3
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)
3
3
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:

Fig 3.18(b) LCD schematic diagram

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.

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

4
CHAPTER 4
SOFTWARE DESCRIPTION

Learn the basics of uploading a sketch in Arduino IDE:

1. Open Arduino IDE


2. Connect the board to your computer
3. Board package installation
4. Select board and port
5. Upload a sketch

What you’ll need:

 A computer running Windows, macOS or Linux


 Arduino IDE
 An Arduino board
 A compatible data USB cable

1. Open Arduino IDE


If you haven’t done so already, download Arduino IDE from the software page. You can
find installation instructions here.

2. Connect the board to your computer

Fig:4.1 Home page of Arduino IDE software

4
Next, connect to board to your computer with a USB cable. This will both power the board and
allow the IDE to send instructions to the board. You’ll need a data USB cable (a charge-only cable
will not work), with connectors that fit both the board and your computer.

Arduino boards use different USB connectors:

 USB-B (UNO Rev3, UNO WIFI Rev2, Mega boards)


 Mini-B USB (Nano)
 Micro-B (Nano Family boards (except the classic Nano), MKR Family boards)
 USB-C (Portenta boards, UNO Mini Limited Edition)

The most common USB connector is USB-A, but newer laptop computers may only have USB-C.

3. Install board package

To compile and upload sketches for your board Arduino IDE needs a collection of files for that
board called a board package.

When Arduino IDE detects a board with a missing board package, it may ask you to install the
missing files:

 In IDE 2, click Yes.

Fig 4.2 Installation page

If no prompt appears, proceed with the next step. If you at any point need to manually find and
add a missing board package, see Add boards to Arduino IDE.

4. Select board and port

Port and board selection can be managed in two ways:

4
 Using the board selector (requires IDE 2)
 Using the Tools menu

Using the board selector

Follow these steps to use a connected board:

1. Find the board selector and click to open.


2. A list of ports will be displayed. If a board could be identified, the board name will
be displayed, otherwise, it will display “Unknown”.

Fig 4.3 Board selector page

3 Click on a port to select it.

When you select a board, the following may occur:

 If it is unknown, the “Select Other board and port” dialog will open. See Select board and
port in Arduino IDE for details.
 If the board could be identified, but you are missing the board platform, you may be
asked to install it:
 Select Yes to automatically install the board package in the background.
 Select Install manually to view the package in the Board Manager.

To learn more about installing boards, see Add a board to Arduino IDE.

4
Using the Tools menu
Select board:

1. Click on Tools in the menu bar and find the Board row. If a board is currently selected
it will be displayed here.

Fig 4.4 Tool menu page

2. Hover over the Board row to reveal the installed board packages. These packages
contain some popular boards:

Fig 4.5 Package and Board

3. Click on a board to select it.

SELECT PORTS:

1. Click on Tools in the menu bar and find the Port row. If a board is currently selected it will be
displayed here.

4
Fig 4.6 port selector page
2 Hover over the Port to reveal all ports. For Arduino devices, the board name
will typically be displayed after the port, for example:


COM3 (Arduino Uno)

/dev/cu.usbmodem14101 (Arduino Uno)

/dev/ttyACM0 (Arduino Uno)
3.Click on a port to select it. If the port with your board is already selected you don’t have to do
anything. If you don’t see your board in the list, see If your board does not appear in the port menu.

5. Upload a sketch

1. Write a sketch, or use an Example such as Blink (File > Examples > 01.Basics > Blink).
2. Optional: Click the Verify button to try compiling the sketch and check for errors.
3. Click the Upload button to program the board with the sketch.

Your sketch will start running on the board. It will run again each time the board is reset.

Troubleshooting

 Make sure you’ve followed the steps before, especially selecting the board and
port correctly.
 If you can’t find your board in the port menu, or if the Tools > Port port menu is missing,
see If your board does not appear in the port menu.
 If you get an upload error, see Errors when uploading a sketch.

4
CHAPTER 5
ADVANTAGES AND DISADVANTAGES &APPLICATION’S

Advantages:

• Automated vehicle prevention system.

• Sensor based detection of vehicle in hill areas.

• Visible alert using LEDs.

• By using this project, we can reduce the vehicle accidents.

• Efficient and low-cost design.

• Low power consumption.

Disadvantages:

Improper installation of IR sensor leads to wrong operation of the vehicle presence

Applications:

This system can be used in real time


• Hill areas.
• Mountain Roads
• Narrow Curve Roads
• T Roads

4
CHAPTER 6
RESULTS

The project “Smart Road Safety and Vehicle Accident Prevention System for Mountain
Roads” was designed a vehicle accident prevention system for hill areas. The sensing of vehicle
arrival and departure is done using IR sensor and give the alert indication with LEDs. The project has
been implemented successfully and matched the expected results.

Fig:6.1 Initially Both side vehicles are allowed

Initially no vehicle is detected in the figure LED indicates green on both sides.

The above figure in left side detected the vehicle therefore it indicates the right side red LED and left
side should pass first

Fig:6.2 vehicle from left side of the road

4
The above figure in right side detected the vehicle therefore it indicates the left side red LED and
right side should pass first

Fig:6.3 vehicle from right side of the road

4
CONCLUSION

In conclusion, the implementation of a smart road safety and accident prevention system for
mountain roads is essential to enhance safety for drivers and passengers. By incorporating real-time
monitoring, warning systems, automated response mechanisms, emergency communication, data
analysis, and fostering collaboration, such a system can effectively reduce accidents and improve
overall road safety in mountainous regions.

Integrating features of all the hardware components used have been developed in it. Presence
of every module has been reasoned out and placed carefully, thus contributing to the best working of
the unit. Secondly, using highly advanced IC’s with the help of growing technology, the project has
been successfully implemented. The project has been successfully designed and tested.

4
FUTURE SCOPE

 The project can be extended using laser and LDR (Light Dependent resistor) which gives
better performance than IR sensors.

 The project can be extended using solar energy, street lights and LDR for intensity control of
street lights.

5
REFERENCES

1. Jessen Joseph Leo., R. Monisha, et.al., Vehicle movement control and accident avoidance in
hilly track, IEEE Int. Conf. on Electronics and Communication Systems (ICECS).pp. 1-
5(2014).

2. AnandBalajiP , Hill Road Safety Assistance using Piezoelectric Sensor, International


Conference on Energy, Communication, Data Analytics and Soft Computing (ICECDS)
2017.

3. Anuradha A, Kasangottuwar, Implementation of Critical Intimation System for Avoiding


Accidents in Hairpin Curves & Foggy Areas, International Journal of Science Technology
& Engineering, Vol. 5, Issue 5 November 2018.

Links:
a) https://nevonprojects.com/smart-road-safety-and-vehicle-accident-prevention-system-for-
mountain-roads/

5
APPENDIX

CODE:

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define ir1 8
#define ir2 9
#define r1 10
#define g1 11
#define r2 12
#define g2 13
void setup() {
// Initialize serial communication and pins
Serial.begin(9600);
pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(r1, OUTPUT);
pinMode(g1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(g2, OUTPUT);
digitalWrite(r1, LOW);
digitalWrite(g1, LOW);
digitalWrite(r2, LOW);
digitalWrite(g2, LOW);
// Initialize LCD
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Welcome To The");
lcd.setCursor(0, 1);
lcd.print(" Project ");
delay(2000);
lcd.clear();
}
void loop() {

int i1 = digitalRead(ir1);
int i2 = digitalRead(ir2);
if (i1 == 0) {
digitalWrite(r1, HIGH); // Turn on red LED
digitalWrite(g1, LOW); // Turn off green LED
lcd.setCursor(0, 0);
lcd.print("Right Side: STOP");
} else {
digitalWrite(r1, LOW); // Turn off red LED
digitalWrite(g1, HIGH); // Turn on green LED
lcd.setCursor(0, 0);
lcd.print("Right Side: GO ");

5
}
// Check the status of the second IR sensor (right side)
if (i2 == 0) {
digitalWrite(r2, HIGH); // Turn on red LED
digitalWrite(g2, LOW); // Turn off green LED
lcd.setCursor(0, 1);
lcd.print("Left Side: STOP");
} else {
digitalWrite(r2, LOW); // Turn off red LED
digitalWrite(g2, HIGH); // Turn on green LED
lcd.setCursor(0, 1);
lcd.print("Left Side: GO ");
}
delay(100); // Small delay to stabilize readings
}

You might also like