Arduino Based Road Crossing Safety Signal System1
Arduino Based Road Crossing Safety Signal System1
SYSTEM
A PROJECT REPORT
Submitted by
AKSHAY.N.M
MOHAMED SHAMIL NALAKATH
RISHIRAJ.A.R
SANOOP.E.S
JUNE 2022
ANNA UNIVERSITY: CHENNAI 600 025
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
Dr. N.Kaleeswari Prof.G.RANJITH KUMAR
HEAD OF THE DEPARTMENT SUPERVISOR
DEPARTMENT OF ELECTRICAL DEPARTMENT OF ELECTRICA
&ELECTRONICS ENGINEERING & ELECTRONICS ENGINEERING
EASA COLLAGE OF ENGINEERING EASA COLLAGE OF
ENGINEERING
AND TECHNOLOGY AND TECHNOLOGY
We take this opportunity to express our gratitude and deep regard to our
guide Mr. G.Ranjith Kumar, Associate Professor, Department of
Electrical and Electronics Engineering, for his guidance, monitoring and
constant encouragement throughout the course of this project. His
invaluable guidance and immense help are embodied in this dissertation.
We also express our sincere gratitude to Dr. N.Kaleeswari, Head of the
Department, Department of Electrical and Electronics Engineering for
her keen interest and unfailing inspiration throughout the course of the
project.
We are thankful to the staff of Department of Electrical and Electronics
Engineering for providing all kinds of support in the lab and helping us
throughout the work.
We are also grateful to the institute's laboratory and other facilities for
providing us with required resources for the completion of this project.
Finally we thank all those who are involved, directly or indirectly,
throughout the course of the project.
ABSTRACT
iii
TABLE OF CONTENTS
1 INTRODUCTION 1
1.1 Arduino UNO 1
1.2 ATMEGA 328p 4
1.2.1 Technical specification 4
1.2.2 Pin configuration 5
1.2.2.1 ADC pins 5
1.2.2.2 Pinout - Digital pins 6
1.2.3 Software 12
1.2.3.1 IDE 13
1.2.3.2 IDE 2.0 14
1.2.3.3 SKETCH 15
1.2.3.4 Communication 16
iv
1.2.3.5 Automatic (Software) 16
Reset
2 LITERATURE REVIEW 17
3 COMPONENTS 18
3.1 PIR sensor 18
3.1.1 Principle 21
3.1.2 Advantages 21
3.1.3 Disadvantages 22
3.2 Ultrasonic sensor 23
(HC-SR04)
3.2.1 Functioning 25
3.2.2 HC-SR04 into Arduino 26
3.3 HC-05 Core Bluetooth 27
Module
3.3.1 Features 30
3.3.2 Specifications 30
3.4 Buck Converter 31
4 PROGRAMMING 33
4.1 Pedestrian side 33
4.2 Vehicle side 35
5 WORKING PRINCIPLE 38
5.1 Pedestrian side 39
v
5.2 Vehicle side 40
5.3 Stimulation Result 41
6 CONCLUSION 42
REFRENCES 43
vi
LIST OF FIGURES
vii
LIST OF TABLES
viii
LIST OF ABBREVIATION
GND : Ground
TXD : Transmitting Data
RXD : Receiving Data
SCK : Serial clock
MISO : Master In Slave Out
ICSP : In-Circuit Serial Programming
SCL : Serial Clock Pin
SPI : Serial Peripheral Interface
MOSI : Master Out Slave I
ix
CHAPTER 1
INTRODUCTION
2
Fig 1.1. Arduino UNO
The Arduino board exposes most of the microcontroller’s I/O pins for
use by other circuits. The Diecimila, Duemilanove, and current Uno
provide 14 digital I/O pins, six of which can produce pulse-width
modulated signals, and six analog inputs, which can also be used as six
digital I/O pins. These pins are on the top of the board, via female 0.1-
inch (2.54 mm) headers. Several plug-in application shields are also
commercially available. The Arduino Nano, and Arduino-compatible
Bare Bones Board and Boarduino boards may provide male header pins
on the underside of the board that can plug into solderless breadboards.
Many Arduino-compatible and Arduino-derived boards exist. Some are
functionally equivalent to an Arduino and can be used interchangeably.
Many enhance the basic Arduino by adding output drivers, often for use
3
in school-level education, to simplify making buggies and small robots.
Others are electrically equivalent, but change the form factor, sometimes
retaining compatibility with shields, sometimes not. Some variants use
different processors, of varying compatibility.
The Arduino Uno has 6 analog pins, which utilize ADC (Analog to
Digital converter). These pins serve as analog inputs but can also
function as digital inputs or digital outputs.
5
by 1,024 digital levels. The ADC converts voltage into bits which the
microprocessor can understand.
Pins 0-13 of the Arduino Uno serve as digital input/output pins. Pin 13
of the Arduino Uno is connected to the built-in LED. In the Arduino
Uno – pins 3, 5,6,9,10,11 have PWM capability. It’s important to note
that:
On the Arduino, When the digital pins are configured as output, they are
set to 0 or 5 volts. When the digital pins are configured as input, the
6
voltage is supplied from an external device. This voltage can vary
between 0-5 volts which is converted into digital representation (0 or 1).
To determine this, there are 2 thresholds:
When connecting a component to a digital pin, make sure that the logic
levels match. If the voltage is in between the thresholds, the returning
value will be undefined.
o Voltage Regulator
The voltage regulator converts the input voltage to 5V. The primary
function of voltage regulator is to regulate the voltage level in the
Arduino board. For any changes in the input voltage of the regulator, the
output voltage is constant and steady.
7
The USB Interface is used to plug-in the USB cable. It allows the board
to connect to the computer. It is essential for the programming of the
Arduino UNO board.
o RESET
It is used to add a Reset button to the connection.
o SCK
It stands for Serial Clock. These are the clock pulses, which are used to
synchronize the transmission of data.
o MISO
It stands for Master Input/ Slave Output. The save line in the MISO pin
is used to send the data to the master.
o VCC
It is the modulated DC supply voltage, which is used to regulate the IC’s
used in the connection. It is also called as the primary voltage for IC’s
present on the Arduino board. The Vcc voltage value can be negative or
positive with respect to the GND pin.
o Crystal Oscillator
The Crystal oscillator has a frequency of 16MHz, which makes the
Arduino UNO a powerful board.
o ICSP
8
It stands for In-Circuit Serial Programming. The users can program the
Arduino board’s firmware using the ICSP pins. The program or
firmware with the advanced functionalities is received by
microcontroller with the help of the ICSP header. The ICSP header
consists of 6 pins. The structure of the ICSP header is shown below:
o SDA
It stands for Serial Data. It is a line used by the slave and master to send
and receive data. It is called as a data line, while SCL is called as a clock
line.
o SCL
It stands for Serial Clock. It is defined as the line that carries the clock
data. It is used to synchronize the transfer of data between the two
devices. The Serial Clock is generated by the device and it is called as
master.
9
o SPI
It stands for Serial Peripheral Interface. It is popularly used by the
microcontrollers to communicate with one or more peripheral devices
quickly. It uses conductors for data receiving, data sending,
synchronization, and device selection (for communication).
o MOSI
It stands for Master Output/ Slave Input. The MOSI and SCK are driven
by the Master.
o SS
It stands for Slave Select. It is the Slave Select line, which is used by the
master. It acts as the enable line.
o I2C
It is the two-wire serial communication protocol. It stands for Inter
Integrated Circuits. The I2C is a serial communication protocol that uses
SCL (Serial Clock) and SDA (Serial Data) to receive and send data
between two devices. 3.3V and 5V are the operating voltages of the
board.
10
Pin Category Pin Name Details
Power Vin, 3.3V, 5V, GND Vin: Input voltage to
Arduino when using
an external power
source.
5V: Regulated power
supply used to power
microcontroller and
other components on
the board.
3.3V: 3.3V supply
generated by on-board
voltage regulator.
Maximum current
draw is 50mA.
GND: ground pins.
Reset Reset Resets the
microcontroller.
Analog Pins A0 – A5 Used to provide
analog input in the
range of 0-5V
Input/Output Pins Digital Pins 0 – 13 Can be used as input
or output pins.
Serial 0(Rx), 1(Tx) Used to receive and
transmit TTL serial
data.
External Interrupts 2, 3 To trigger an
interrupt.
11
PWM 3, 5, 6, 9, 11 Provides 8-bit PWM
output.
SPI 10 (SS), 11 (MOSI), Used for SPI
12 (MISO) and 13 communication.
(SCK)
Inbuilt LED 13 To turn on the inbuilt
LED.
TWI A4 (SDA), A5 (SCA) Used for TWI
communication.
AREF AREF To provide reference
voltage for input
voltage.
1.2.3 Software:
1.2.3.1 IDE:
12
The Arduino integrated development environment (IDE) is a cross-
platform application (for Microsoft Windows, macOS, and Linux) that is
written in the Java programming language. It originated from the IDE
for the languages Processing and Wiring. It includes a code editor with
features such as text cutting and pasting, searching and replacing text,
automatic indenting, brace matching, and syntax highlighting, and
provides simple one-click mechanisms to compile and upload programs
to an Arduino board. It also contains a message area, a text console, a
toolbar with buttons for common functions and a hierarchy of operation
menus. The source code for the IDE is released under the GNU General
Public License, version 2.
The Arduino IDE supports the languages C and C++ using special rules
of code structuring. The Arduino IDE supplies a software library from
the Wiring project, which provides many common input and output
procedures. User-written code only requires two basic functions, for
starting the sketch and the main program loop, that are compiled and
linked with a program stub main() into an executable cyclic executive
program with the GNU toolchain, also included with the IDE
distribution. The Arduino IDE employs the program argued to convert
the executable code into a text file in hexadecimal encoding that is
loaded into the Arduino board by a loader program in the board’s
firmware.
Integrated development environments are designed to maximize
programmer productivity by providing tight-knit components with
similar user interfaces. IDEs present a single program in which all
development is done. This program typically provides many features for
authoring, modifying, compiling, deploying and debugging software.
This contrasts with software development using unrelated tools, such as
VI, GDB, GCC, or make.
One aim of the IDE is to reduce the configuration necessary to piece
together multiple development utilities. Instead, it provides the same set
13
of capabilities as one cohesive unit. Reducing setup time can increase
developer productivity, especially in cases where learning to use the IDE
is faster than manually integrating and learning all of the individual
tools. Tighter integration of all development tasks has the potential to
improve overall productivity beyond just helping with setup tasks. For
example, code can be continuously parsed while it is being edited,
providing instant feedback when syntax errors are introduced, thus
allowing developers to debug code much faster and more easily with an
IDE.
Some IDEs are dedicated to a specific programming language, allowing
a feature set that most closely matches the programming paradigms of
the language. However, there are many multiple-language IDEs.
While most modern IDEs are graphical, text-based IDEs such as Turbo
Pascal were in popular use before the availability of windowing systems
like Microsoft Windows and the X Window System (X11). They
commonly use function keys or hotkeys to execute frequently used
commands or macros.
From version 1.8.12, Arduino IDE windows compiler supports only
Windows 7 or newer OS. On Windows Vista or older one gets
“Unrecognized Win32 application” error when trying to verify/upload
program. To run IDE on older machines, users can either use version
1.8.11, or copy “Arduino-builder” executable from version 11 to their
current install folder as its independent from IDE.
On March 1, 2021, the beta preview was released, renamed IDE 2.0. The
system still uses Arduino CLI (Command Line Interface), but
improvements include a more professional development environment,
auto completion support, and Git integration. The application frontend is
14
based on the Eclipse Theia Open Source IDE. The main features
available in the new release are:
o Modern, fully featured development environment
o Dual Mode, Classic Mode (identical to the Classic Arduino IDE)
and Pro Mode (File System view)
o New Board Manager
o New Library Manager
o Board List
o Basic Auto-Completion (Arm targets only)
o Git Integration
o Serial Monitor
o Dark Mode
1.2.3.3 SKETCH:
A sketch is a program written with the Arduino IDE. Sketches are saved
on the development computer as text files with the file extension .ino.
Arduino Software (IDE) pre-1.0 saved sketches with the extension .pde.
A minimal Arduino C/C++ program consists of only two functions:
o Setup (): This function is called once when a sketch starts after
power-up or reset. It is used to initialize variables, input and output
pin modes, and other libraries needed in the sketch. It is analogous
to the function main().
o Loop (): After setup () function exits (ends), the loop () function is
executed repeatedly in the main program. It controls the board
until the board is powered off or is reset. It is analogous to the
function while
15
1.2.3.4 Communication:
The Arduino/Genuino Uno has a number of facilities for communicating
with a computer, another Arduino/Genuino board, or other
microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX).
An ATmega16U2 on the board channels this serial communication over
USB and appears as a virtual com port to software on the computer. The
16U2 firmware uses the standard USB COM drivers, and no external
driver is needed. However, on Windows, a .inf file is required. Arduino
Software (IDE) includes a serial monitor which allows simple textual
data to be sent to and from the board. The RX and TX LEDs on the
board will flash when data is being transmitted via the USB-to-serial
chip and USB connection to the computer (but not for serial
communication on pins 0 and 1). A Software Serial library allows serial
communication on any of the Uno’s digital pins.
1.2.3.5 Automatic (software) reset:
16
will intercept the first few bytes of data sent to the board after a
connection is opened
CHAPTER 2
LITERATURE REVIEW
17
CHAPTER 3
COMPONENTS
18
some minor processing on it to emit a digital output pulse from the
analog sensor.
Our new PIRs have more adjustable settings and have a header installed
in the 3-pin ground/out/power pads
PIR sensors are more complicated than many of the other sensors
explained in these tutorials (like photocells, FSRs and tilt switches)
because there are multiple variables that affect the sensors input and
output. To begin explaining how a basic sensor works, we’ll use this
rather nice diagram.
The PIR sensor itself has two slots in it, each slot is made of a special
material that is sensitive to IR. The lens used here is not really doing
much and so we see that the two slots can ‘see’ out past some distance
(basically the sensitivity of the sensor). When the sensor is idle, both
slots detect the same amount of IR, the ambient amount radiated from
19
the room or walls or outdoors. When a warm body like a human or
animal passes by, it first intercepts one half of the PIR sensor, which
causes a positive differential change between the two halves. When the
warm body leaves the sensing area, the reverse happens, whereby the
sensor generates a negative differential change. These change pulses are
what is detected.
For many basic projects or products that need to detect when a person
has left or entered the area, or has approached, PIR sensors are great.
They are low power and low cost, pretty rugged, have a wide lens range,
and are easy to interface with. Note that PIRs won’t tell you how many
people are around or how close they are to the sensor, the lens is often
fixed to a certain sweep and distance (although it can be hacked
somewhere) and they are also sometimes set off by house pets.
20
Fig 3.1.2 PIR Waveform
3.1.1 Principle:
3.1.2 Advantages:
21
PIR motion sensors can detect moving objects even in dark with
great accuracy.
PIR sensors can detect the motion of objects without coming in
contact with them.
They are very easy to install and do not require much wiring.
They reduce a lot of human efforts by making things to work
automatically.
They consume very less energy and thus reduce electricity bills a
lot.
3.1.3 Disadvantages:
22
3.2 Ultrasonic sensor (HC-SR04):
24
(T = Time and C = the speed of sound)
3.2.1 Functioning:
So where can we use these sensors? Robot navigation comes to mind, as
well as factory automation. Water-level sensing is another good use, and
can be accomplished by positioning one sensor above a water surface.
Another aquatic application is to use these sensors to “see” the bottom of
a body of water, traveling through the water, but reflecting off the
bottom surface below.
25
Fig 3.2.1 Ultrasonic sensor
If this all sounds interesting, you can try it out yourself very easily using
an Arduino and an HC-SR04 sensor. Shown above is the compact and
inexpensive Arduino Nano, but any other development board should
also work. Gather the components (Arduino, HC-SR04, wires, and
breadboard) and go into the Arduino IDE and install the “NewPing”
sensor library.
Once installed, there will be a number of new example sketches you can
choose from. Open up the “NewPing3Sensors” sketch. Attach pins from
your Arduino to the HC-SR04, as defined in the program, adding ground
and 5V from the Arduino.
Send the program to your dev board, and then open up a serial monitor
at 115200 baud. You’ll see a distance reading when you put something
26
in front of it. Note that it reads “0” when it doesn’t properly read a
distance.
Send the program to your dev board, and then open up a serial monitor
at 115200 baud. You’ll see a distance reading when you put something
in front of it. Note that it reads “0” when it doesn’t properly read a
distance.
Try experimenting with different shapes and
materials to see what works and what doesn’t. I was pleased to find that
acoustic foam paneling does not return a signal, while flat smooth
surfaces like a phone screen or piece of paper are sensed quite well.
Ultrasonic transducers operate at frequencies in the range of 30–
500 kHz for air-coupled applications. As the ultrasonic frequency
increases, the rate of attenuation increases. Thus, low-frequency sensors
(30–80 kHz) are more effective for long range, while high-frequency
sensors are more effective for short range.
27
Fig 3.3.1 HC-05 module
After connecting the module you have to write the program in Arduino
IDE to receive and send data to the module.
The communication with this HC-05 module is done through UART
interface. The data is sent to the module or received from the module
though this interface. So we can connect the module to any
microcontroller or directly to PC which has RS232 port (UART
interface). Here the module is connected to +5V standard regulated
power supply and UART interface is established as shown in figure. All
you need to do is connect RXD of Arduino to TXD of module and TXD
of Arduino is connected to RXD of module through a resistor voltage
divider.
This voltage divider is provided for converting 5V logic signal sent by
Arduino to +3.3V logic signals which are suitable for the module. The
ground of Arduino and module must be connected for voltage reference
in case separate power sources are used. For successful wireless
communication you need to remember a few things:
28
In programming you need to set default baud rate of UART serial
communication to 9600. The value is default setting of module and
can be change in program.
The module is a slave and so you need a master to establish a
successful wireless interface. For that you need another [Arduino +
module (with master feature)] setup or you can use a smart phone
as a master and search for HC-05 slave.
The master searches for slave and connects to it after authenticated
with password. The HC-05 module has default password ‘1234’
which can be changed.
In program you can receive data master sends (After
authentication) and perform tasks based on it.
Also you can download libraries for module through the websites
and use them to make communication easy. All you need to do is
download these libraries and call them in programs. Once the
header file is included, you can use simple commands in the
program to tell the Arduino to send or receive data. The module
sends this data to master through wireless Bluetooth. If the module
receives any data from master, it will transmit it to Arduino
through UART serial communication.
You can also interface HC-05 to PC using RS232 cable. Once you
interface is done you can use serial terminal on PC or any similar
software to send or receive data to module. You need to type in AT
command in serial terminal to communicate with the module and
these commands can be downloaded.
After you change the baud rate, if it is not the default 9600, you need to
use the setting baud rate in future parameter setting or data
communication. It is recommended that you do not use the baud rate
greater than 115200. The interference of signals will make the system
unstable. You cannot use your computer if you set a baud rate higher
than 115200. You should program with SCM to make the baud rate
29
higher than 115200 so as to use this baud rate and resent AT command
to set a low rate.
3.3.1 Features:
The module is very easy to interface and to communicate.
HC-05 is best option when short distance wireless
communication is needed. The module is used for wireless
communications of less than 100 meters.
The module is one of the cheapest solutions for wireless
communication of all types present in the market.
The module consumes very less power to function and can be
used on battery operated mobile systems. • The module can
be interfaced with almost all controllers or processors as it
uses UART interface
3.3.2 Specifications:
30
3.4 Buck converters:
31
Fig 3.4.1 Buck converter circuit
32
CHAPTER 4
PROGRAMMING
#include <SoftwareSerial.h>
#include <HCSR04.h>
33
#define tx 3
#define rx 2
SoftwareSerial configBt(rx, tx); // RX, TX
UltraSonicDistanceSensor distanceSensor(11, 12);
Void setup()
{
Serial.begin(9600);
configBt.begin(9600);
pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
pinMode(8, INPUT);
pinMode(13, OUTPUT);
}
Void loop()
{ char c;
Bool flag;
Int Level = distanceSensor.measureDistanceCm();
//Serial.println(Level);
If (configBt.available()) // if the HC05 is sending something…
{
C = configBt.read();
Serial.print©; // print in serial monitor
}
34
If (c == ‘a’)
{
digitalWrite(13, 1);
//flag = true;
}
Else if (c == ‘b’)
{
digitalWrite(13, 0);
//flag = true;
}
If (digitalRead(8)==1&&Level < 10 && Level != -1)
{
Serial.print(“OK”);
configBt.print(“a”);
}
Else
{
configBt.print(“b”);
}
Delay(1000);
}
35
#include <SoftwareSerial.h>
#include <HCSR04.h>
#define tx 3
#define rx 2
SoftwareSerial configBt(rx, tx); // RX, TX
UltraSonicDistanceSensor distanceSensor(11, 12);
Void setup()
{
Serial.begin(9600);
configBt.begin(9600);
pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
// pinMode(8, INPUT);
pinMode(13, OUTPUT);
}
Void loop()
{ char c;
Bool flag;
Int Level = distanceSensor.measureDistanceCm();
//Serial.println(Level);
If (configBt.available()) // if the HC05 is sending something…
{
36
C = configBt.read();
Serial.print©; // print in serial monitor
}
If (c == ‘a’)
{
digitalWrite(13, 1);
//flag = true;
}
Else if (c == ‘b’)
{
digitalWrite(13, 0);
//flag = true;
}
If (Level < 10 && Level != -1)
{
Serial.print(“OK”);
configBt.print(“a”);
}
Else
{
configBt.print(“b”);
}
Delay(1000);
37
}
CHAPTER 5
WORKING PRINCIPLE
Microcontroller at the pedestrian side and vehicle side control the whole
operations. Arduino Uno is used as microcontroller unit. The Arduino
programming is done for 5 sec of time period it can be alternated by
alternating the program. The system consist of two circuit one for
pedestrian side and another vehicle side. The two circuit are place on
two dotted type breadboards and they should maintain a minimum
distance of 15 centimeters for an effective communication between the
Bluetooth modules. The basic diagram for two circuit is given below:
38
Fig 5.1 Circuit diagram:
POWER SUPPLY
BLUETOOTH
PIR SENSOR
LED WARNING
ARDUINO UNO
LIGHT
ULTRASONIC
SENSOR
39
5.2 Vehicle side:
POWER SUPPLY
PEDESTRIAN LED
WARNING LIGHT
ULTRASONIC
SENSOR ARDUINO UNO
BLUETOOTH
40
5.3 Stimulation Result:
The stimulation result for the above circuit diagram is given below as a
table for the simplicity:
41
CHAPTER 6
CONCLUSION
Through this work, we got more information about the Arduino and
microcontroller ATMEGA 328P and its function and specifications. By
using this methodology, we could develop a safety signal system for the
pedestrian to cross the road especially during the night period. Our main
motive was to reduce the count of accidents.
42
REFRENCES
[11] www.smartmotorist.com/average-car-length
44
45