Fin PDF
Fin PDF
1.5 RELIABILITY 6
1.6 TRACING 7
2.1 INTRODUCTION 8
2.4 WORKING 9
2.6 OBJECTIVES 10
2.7 ADVANTAGES 11
2.8 APPLICATIONS 11
COMMENTS 16
3.1.4 FUNCTION 16
RESULT 40
06 CONCLUSION 41
REFERENCES 42
LIST OF FIGURES
S.NO DESCRIPTION PAGE NO
2.1 BLOCK DIAGRAM OF AUTOMATIC COLLISION 9
AVOIDANCE SYSTEM
2.2 CIRCUIT DIAGRAM FOR COMPONENTS CONECTION 11
3.1 ARUDINO IDE 13
3.2 ARUDINO IDE INTERFACE 14
3.3 METHOD INITIALIZATION 15
3.4 ARUDINO LIBRARY 20
3.5 INSTALLING ARUDINO LIBRARY 21
4.1 ARUDINO NANO 24
4.2 RELAY MODULE 26
4.2.1 1 CHANNEL RELAY 30
4.2.2 4 CHANNEL RELAY 31
4.2.3 PIN DIAGRAM OF RELAY 31
4.3 ULTASONIC SENSOR 31
4.4 TOGGLE SWITCH(3PIN 2 POSITON SLIDE SWITCH
4.5 9VOLT BATTERY 34
4.6 CONNECTOR 36
5.1 CASE 1 40
5.2 CASE 2 40
CHAPTER 1
INTRODUCTION TO EMBEDDED SYSTEMS
Embedded Technology is now in its prime and the wealth of knowledge available is
mind blowing. However, most embedded systems engineers have a common complaint. There
are no comprehensive resources available over the internet which deal with the various design
and implementation issues of this technology. Intellectual property regulations of many
corporations are partly to blame for this and also the tendency to keep technical know-how
within a restricted group of researchers.
Every home has several examples of embedded computers. Any appliance that has a
digital clock, for instance, has a small embedded micro-controller that performs no other task
than to display the clock. Modern cars have embedded computers onboard that control such
things as ignition timing and anti-lock brakes using input from a number of different sensors.
Most embedded systems are time critical applications meaning that the embedded
system is working in an environment where timing is very important: the results of an operation
are only relevant if they take place in a specific time frame. An autopilot in an aircraft is a time
critical embedded system. If the autopilot detects that the plane for some reason is going into a
stall then it should take steps to correct this within milliseconds or there would be catastrophic
results.
1
1.1 APPLICATIONS OF EMBEDDED SYSTEM
Medical equipment uses embedded systems for vital signs monitoring, electronic
stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT,
and MRI) for non-invasive internal inspections. Embedded systems within medical equipment
are often powered by industrial computers.[9]
Embedded systems are used in transportation, fire safety, safety and security, medical
applications and life critical systems, as these systems can be isolated from hacking and thus,
be more reliable. For fire safety, the systems can be designed to have greater ability to handle
higher temperatures and continue to operate. In dealing with security, the embedded systems
can be self-sufficient and be able to deal with cut electrical and communication systems.
2
1.2 CHARACTERISTICS OF EMBEDDED SYSTEM
Embedded systems are designed to do some specific task, rather than be a general-purpose
computer for multiple tasks. Some also have real-time performance constraints that must be
met, for reasons such as safety and usability; others may have low or no performance
requirements, allowing the system hardware to be simplified to reduce costs.
Embedded systems are not always standalone devices. Many embedded systems consist of
small parts within a larger device that serves a more general purpose. For example, the Gibson
Robot Guitar features an embedded system for tuning the strings, but the overall purpose of the
Robot Guitar is, of course, to play music. Similarly, an embedded system in
an automobile provides a specific function as a subsystem of the car itself.
Embedded systems range from no user interface at all, in systems dedicated only to one
task, to complex graphical user interfaces that resemble modern computer desktop operating
systems. Simple embedded devices use buttons, LEDs, graphic or character LCDs (HD44780
LCD for example) with a simple menu system.
More sophisticated devices which use a graphical screen with touch sensing or screen-edge
buttons provide flexibility while minimizing space used: the meaning of the buttons can change
with the screen, and selection involves the natural behavior of pointing at what is
desired. Handheld systems often have a screen with a "joystick button" for a pointing device.
Some systems provide user interface remotely with the help of a serial (e.g. RS-
232, USB, I²C, etc.) or network (e.g. Ethernet) connection. This approach gives several
advantages: extends the capabilities of embedded system, avoids the cost of a display,
simplifies BSP and allows one to build a rich user interface on the PC. A good example of this
is the combination of an embedded web server running on an embedded device (such as an IP
camera) or a network router. The user interface is displayed in a web browser on a PC
connected to the device, therefore needing no software to be installed.
Embedded processors can be broken into two broad categories. Ordinary microprocessors
Embedded processors can be broken into two broad categories. Ordinary microprocessors (μP)
use separate integrated circuits for memory and peripherals. Microcontrollers (μC) have on-
chip peripherals, thus reducing power consumption, size and cost. In contrast to the personal
computer market, many different basic CPU architectures are used, since software is custom-
3
developed for an application and is not a commodity product installed by the end user.
Both Von Neumann as well as various degrees of Harvard architectures are used. RISC as well
as non-RISC processors are found. Word lengths vary from 4-bit to 64-bits and beyond,
although the most typical remain 8/16-bit. Most architectures come in a large number of
different variants and shapes, many of which are also manufactured by several different
companies.
Numerous microcontrollers have been developed for embedded systems use. General-
purpose microprocessors are also used in embedded systems, but generally require more
support circuitry than microcontrollers.
(μP) use separate integrated circuits for memory and peripherals. Microcontrollers (μC)
have on-chip peripherals, thus reducing power consumption, size and cost. In contrast to the
personal computer market, many different basic CPU architectures are used, since software is
custom-developed for an application and is not a commodity product installed by the end user.
Both Von Neumann as well as various degrees of Harvard architectures are used. RISC as well
as non-RISC processors are found. Word lengths vary from 4-bit to 64-bits and beyond,
although the most typical remain 8/16-bit. Most architectures come in a large number of
different variants and shapes, many of which are also manufactured by several different
companies.
Numerous microcontrollers have been developed for embedded systems use. General-
purpose microprocessors are also used in embedded systems, but generally require more
support circuitry than microcontrollers.
From simplest to most sophisticated they can be roughly grouped into the following areas:
4
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 multicore 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 (ICE) 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. The downsides
are expense and slow operation, in some cases up to 100 times slower than the final system.
For SoC designs, the typical approach is to verify and debug the design on an FPGA
prototype board. Tools such as Certus[11] are used to insert probes in the FPGA RTL that make
signals available for observation. This is used to debug hardware, firmware and software
interactions across multiple FPGA with capabilities similar to a logic analyzer.
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 HLL source-code, assembly code or mixture of
both.
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, and 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
1.5 RELIABILITY
Embedded systems often reside in machines that are expected to run continuously for years
without errors, and in some cases recover by themselves 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.
• 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.
• 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.
• 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[12] ensures a highly secure
& reliable system environment
• A hypervisor designed for embedded systems, 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
6
1.6 TRACING
Real-time operating systems (RTOS) often supports tracing of operating system events. A
graphical view is presented by a host PC tool, based on a recording of the system behavior.
The trace recording can be performed in software, by the RTOS, or by special tracing hardware.
RTOS tracing allows developers to understand timing and performance issues of the software
system and gives a good understanding of the high-level system behaviors. Commercial tools
like RTXC Quadros or IAR Systems exists.
7
CHAPTER 2
AUTOMATED RAILWAY COLLISION AVOIDANCE
SYSTEM USING SENSORS AND ARDUINO
2.1 INTRODUCTION
The Automatic Train Collision Avoidance System is a safety mechanism designed to prevent
train accidents by detecting potential collisions in advance and triggering appropriate
responses. With the rapid advancement in transportation technology, ensuring the safety of
railways has become crucial. This system employs an Arduino Nano microcontroller, sensors,
and actuators to autonomously detect objects or trains on the same track and take preventive
actions to avoid collisions. It is a cost-effective, reliable, and adaptable solution for enhancing
train safety.
8
2.3 SYSTEM DESIGN
1. Arduino Nano: The central microcontroller that processes input signals from sensors
and controls the relay.
2. Ultrasonic Sensor: Measures the distance between the train and any obstacle on the
track, helping in collision detection.
5. 1-Channel Relay: Controls the action of the train model based on sensor inputs.
6. Train Model: Simulates the train for which the collision avoidance system is
designed.
The ultrasonic sensor constantly monitors the track for any obstacles, and the Arduino Nano
processes the sensor’s data to activate the relay, which can stop or slow down the train if
necessary.
2.4 WORKING
The system is powered on using the 9V battery and the toggle switch.
The ultrasonic sensor continuously emits sound waves and detects reflected waves from
objects ahead of the train.
If an object is detected within a predefined distance, the sensor sends the distance data to
the Arduino Nano.
The Arduino Nano processes this data, and if the distance falls below a certain threshold, it
triggers the 1-channel relay to stop or slow down the train.
This ensures that the train halts in time, preventing a collision with the detected object or
another train on the track.
The system can also be reset using the toggle switch, allowing for manual control if
necessary.
9
2.5 CIRCUIT DIAGRAM
2.6 OBJECTIVES
Prevent Train Collisions: To stop or reduce the speed of a train when another object or
train is detected on the same track.
Improve Train Safety: By minimizing the chances of accidents, ensuring safer railway
operations.
10
2.7 ADVANTAGES
Enhanced Safety: Drastically reduces the chances of train collisions, ensuring passenger
and cargo safety.
Autonomous Operation: Once installed, the system requires minimal human intervention,
running autonomously.
Scalable concept: This basic setup can demonstrate the principle of collision avoidance,
which can be scaled up for lager system
2.8 APPLICATIONS
Railways: Can be installed in railway networks to avoid collisions on single-track or
congested routes.
Model Trains: Useful for educational purposes, especially for demonstrating the working
of collision avoidance systems in small-scale models.
Freight Trains: Can be applied to freight train operations to prevent damage to goods
during transit.
Metro and Urban Train Systems: Can be implemented in metro systems where frequent
stoppages are required, ensuring safer and more controlled travel.
1. Integration with GPS: Future iterations could include GPS for better tracking of train
positions, making the system even more robust.
2. Expansion to Larger Networks: The system could be adapted for use on larger rail
networks, with additional features such as communication between trains to share
information about their location.
11
3. Advanced Sensing Capabilities: The use of LIDAR or RADAR could be explored for
more precise object detection and longer-range operation.
4. Automation and AI Integration: Artificial intelligence could be used to predict
collision scenarios, further enhancing the decision-making process of the system.
This system is a foundation for safer railways, leveraging technology to improve transportation
safety efficiently and affordably.
12
CHAPTER 3
SOFTWARE REQUIREMENTS
Software used in this project for uploading code onto Arduino is Arduino IDE.
IDE stands for Integrated Development Environment. Pretty fancy sounding, and
should make you feel smart any time you use it. The IDE is a text editor-like program that
allows you to write Arduino code. When you open the Arduino program, you are opening the
IDE. It is intentionally streamlined to keep things as simple and straightforward as possible.
When you save a file in Arduino, the file is called a sketch – a sketch is where you save the
computer code you have written. The coding language that Arduino uses is very much like C++
(“see plus plus”), which is a common language in the world of computing. The code you learn
to write for Arduino will be very similar to the code you write in any other computer language
– all the basic concepts remain the same – it is just a matter of learning a new dialect should
you pursue other programming languages.
13
The code you write is “human readable”, that is, it will make sense to you (sometimes),
and will be organized for a human to follow. Part of the job of the IDE is to take the human
readable code and translate it into machine-readable code to be executed by the Arduino. This
process is called compiling. The process of compiling is seamless to the user. All you have to
do is press a button. If you have errors in your computer code, the compiler will display an
error message at the bottom of the IDE and highlight the line of code that seems to be the issue.
The error message is meant to help you identify what you might have done wrong – sometimes
the message is very explicit, like saying, “Hey – you forget a semicolon”, sometimes the error
message is vague. Why be concerned with a semicolon you ask? A semicolon is part of the
Arduino language syntax, the rules that govern how the code is written. It is like grammar in
writing. Say for example we didn’t use periods when we wrote – everyone would have a heck
of a time trying to figure out when sentences started and ended. Or if we didn’t employ the
comma, how would we convey a dramatic pause to the reader?
14
And let me tell you, if you ever had an English teacher with an overactive red pen, the
compiler is ten times worse. In fact – your programs WILL NOT compile without perfect
syntax. This might drive you crazy at first because it is very natural to forget syntax. As you
gain experience programming you will learn to be assiduous about coding grammar.
Int LedPin=9;
In this statement, I am assigning a value to an integer variable (we will cover this later),
notice the semicolon at the end. This tells the compiler that you have finished a chunk of code
and are moving on to the next piece. A semicolon is to Arduino code, as a period is to a
sentence. It signifies a complete statement.
15
3.1.2 THE DOUBLE BACKSLASH FOR SINGLE LINE COMMENTS //
Comments are what you use to annotate code. Good code is commented well.
Comments are meant to inform you and anyone else who might stumble across your code, what
the heck you were thinking when you wrote it. A good comment would be something like
this…
Now, in 3 months when I review this program, I know where to stick my LED. Comments will
be ignored by the compiler – so you can write whatever you like in them. If you have a lot you
need to explain, you can use a multi-line comment, shown below…
//This is an example
Comments are like the footnotes of code, except far more prevalent and not at the bottom of
the page.
Curly braces are used to enclose further instructions carried out by a function (we
discuss functions next). There is always an opening curly bracket and a closing curly bracket.
If you forget to close a curly bracket, the compiler will not like it and throw an error code.
3.1.4 FUNCTION ( )
Functions are pieces of code that are used so often that they are encapsulated in certain
keywords so that you can use them more easily. For example, a function could be the following
set of instructions…
16
This set of simple instructions could be encapsulated in a function that we call
WashDog. Every time we want to carry out all those instructions we just type WashDog and
voila – all the instructions are carried out. In Arduino, there are certain functions that are used
so often they have been built into the IDE. When you type them, the name of the function will
appear orange. The function pinMode(), for example, is a common function used to designate
the mode of an Arduino pin.
What’s the deal with the parentheses following the function pinMode? Many functions
require arguments to work. An argument is information the function uses when it runs. For our
WashDog function, the arguments might be dog name and soap type, or temperature and size
of a bucket.
pinMode(13, OUTPUT);
The argument 13 refers to pin 13, and OUTPUT is the mode in which you want the pin
to operate. When you enter these arguments the terminology is called passing. You pass the
necessary information to the functions. Not all functions require arguments, but opening and
closing parentheses will stay regardless though empty.
Notice that the word OUTPUT is blue. There are certain keywords in Arduino that are
used frequently and the color blue helps identify them. The IDE turns them blue automatically.
Now we won’t get into it here, but you can easily make your own functions in Arduino, and
you can even get the IDE to color them for you. We will, however, talk about the two functions
used in nearly EVERY Arduino program.
The function, setup(), as the name implies, is used to set up the Arduino board. The Arduino
executes all the code that is contained between the curly braces of setup() only once. Typical
things that happen in setup() are setting the modes of pins, starting You might be wondering
what void means before the function setup(). Void means that the function does not return
information. Some functions do return values – our DogWash function might return the number
of buckets it required to clean the dog. The function analogRead() returns an integer value
17
between 0-1023. If this seems a bit odd now, don’t worry as we will cover every common
Arduino function in depth as we continue the course.
You have to love the Arduino developers because the function names are so telling. As
the name implies, all the code between the curly braces in loop() is repeated over and over
again – in a loop. The loop() function is where the body of your program will reside. As with
setup(), the function loop() does not return any values, therefore the word void precedes it.
Does it seem odd to you that the code runs in one big loop? This apparent lack of
variation is an illusion. Most of your code will have specific conditions laying in wait which
will trigger new actions.
If you have a temperature sensor connected to your Arduino for example, then when
the temperature gets to a predefined threshold you might have a fan kick on. The looping code
is constantly checking the temperature waiting to trigger the fan. So even though the code loops
over and over, not every piece of the code will be executed every iteration of the loop.
18
3.2 INTRODUCTION ARDUINO LIBRARIES
Libraries are a collection of code that makes it easy for you to connect to a sensor,
display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to
character LCD displays. There are hundreds of additional libraries available on the Internet for
download. The built-in libraries and some of these additional libraries are listed in the
reference. To use the additional libraries, you will need to install them.
Arduino libraries are managed in three different places: inside the IDE installation
folder, inside the core folder and in the libraries folder inside your sketchbook. The way
libraries are chosen during compilation is designed to allow the update of libraries present in
the distribution. This means that placing a library in the “libraries” folder in your sketchbook
overrides the other libraries versions.
The same happens for the libraries present in additional cores installations. It is also
important to note that the version of the library you put in your sketchbook may be lower than
the one in the distribution or core folders, nevertheless it will be the one used during
compilation. When you select a specific core for your board, the libraries present in the core’s
folder are used instead of the same libraries present in the IDE distribution folder.
Last, but not least important is the way the Arduino Software (IDE) upgrades itself: all
the files in Programs/Arduino (or the folder where you installed the IDE) are deleted and a new
folder is created with fresh content. This is why we recommend that you only install libraries
to the sketchbook folder so they are not deleted during the Arduino IDE update process.
19
3.2.1 HOW TO INSTALL A LIBRARY
To install a new library into your Arduino IDE you can use the Library Manager
(available from IDE version 1.6.2). Open the IDE and click to the "Sketch" menu and
then Include Library > Manage Libraries.
Then the Library Manager will open and you will find a list of libraries that are already
installed or ready for installation. In this example we will install the Bridge library. Scroll the
list to find it, click on it, then select the version of the library you want to install. Sometimes
only one version of the library is available. If the version selection menu does not appear, don't
worry: it is normal.
20
FIG.3.5 INSTALLING ARUDINO LIBRARY
Finally click on install and wait for the IDE to install the new library. Downloading
may take time depending on your connection speed. Once it has finished, an Installed tag
should appear next to the Bridge library. You can close the library manager. You can now find
the new library available in the Sketch > Include Library menu. If you want to add your own
library to Library Manager, follow these instructions.
If you're using a serial board, power the board with an external power supply (6 to 25
volts DC, with the core of the connector positive). Connect the board to a serial port on your
computer. On the USB boards, the power source is selected by the jumper between the USB
and power plugs. To power the board from the USB port (good for controlling low power
devices like LEDs), place the jumper on the two pins closest to the USB plug. To power the
board from an external power supply (needed for motors and other high current devices), place
the jumper on the two pins closest to the power plug. Either way, connect the board to a USB
port on your computer. On Windows, the Add New Hardware wizard will open; tell it you want
to specify the location to search for drivers and point to the folder containing the USB drivers
you unzipped in the previous step.
21
3.4 HOW TO UPLOAD A PROGRAM
The content of circuits and Arduino sketches can vary greatly. Before you get started,
there is one simple process for uploading a sketch to an Arduino board that you can refer back
to.
The square end of the USB cable connects to your Arduino and the flat end connects to a USB
port on your computer.
You can also find all boards through this menu, such as the Arduino MEGA 2560 and Arduino
Leonardo.
You find a list of all the available serial ports by choosing Tools→Serial Port→ comX or
/dev/tty.usbmodemXXXXX. X marks a sequentially or randomly assigned number. In
Windows, if you have just connected your Arduino, the COM port will normally be the highest
number, such as com 3 or com 15.
Many devices can be listed on the COM port list, and if you plug in multiple Arduinos, each
one will be assigned a new number. On Mac OS X, the /dev/tty.usbmodem number will be
randomly assigned and can vary in length, such as /dev/tty.usbmodem1421 or
/dev/tty.usbmodem262471. Unless you have another Arduino connected, it should be the only
one visible.
This is the button that points to the right in the Arduino environment. You can also use the
keyboard shortcut Ctrl+U for Windows or Cmd+U for Mac OS X.
22
CHAPTER 4
HARDWARE REQUIREMENTS
Hardware Components of this project are
1. ARDUINO NANO
2. ONE CHANNEL RELAY
3. ULTRASONIC SENSOR
4. TOGGLE SWITCH
5. 9V BATTERY
Over the years Arduino has been the brain of thousands of projects, from everyday
objects to complex scientific instruments. A worldwide community of makers - students,
hobbyists, artists, programmers, and professionals - has gathered around this open-source
platform, their contributions have added up to an incredible amount of accessible
knowledge that can be of great help to novices and experts alike.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast
prototyping, aimed at students without a background in electronics and programming. As soon
as it reached a wider community, the Arduino board started changing to adapt to new needs
and challenges, differentiating its offer from simple 8-bit boards to products
for IoT applications, wearable, 3D printing, and embedded environments. All Arduino boards
are completely open-source, empowering users to build them independently and eventually
adapt them to their particular needs. The software, too, is open-source, and it is growing
through the contributions of users worldwide.
23
FIG.4.1 ARUDINO NANO
Thanks to its simple and accessible user experience, Arduino has been used in
thousands of different projects and applications. The Arduino software is easy-to-use for
beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux.
Teachers and students use it to build low cost scientific instruments, to prove chemistry and
physics principles, or to get started with programming and robotics. Designers and architects
build interactive prototypes, musicians and artists use it for installations and to experiment with
new musical instruments. Makers, of course, use it to build many of the projects exhibited at
the Maker Faire, for example. Arduino is a key tool to learn new things. Anyone - children,
hobbyists, artists, programmers - can start tinkering just following the step by step instructions
of a kit, or sharing ideas online with other members of the Arduino community.
24
• Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
• Simple, clear programming environment - The Arduino Software (IDE) is easy-to-
use for beginners, yet flexible enough for advanced users to take advantage of as well. For
teachers, it's conveniently based on the Processing programming environment, so students
learning to program in that environment will be familiar with how the Arduino IDE works.
• Open source and extensible software - The Arduino software is published as open
source tools, available for extension by experienced programmers. The language can be
expanded through C++ libraries, and people wanting to understand the technical details can
make the leap from Arduino to the AVR C programming language on which it's based.
Similarly, you can add AVR-C code directly into your Arduino programs if you want to.
• Open source and extensible hardware - The plans of the Arduino boards are published
under a Creative Commons license, so experienced circuit designers can make their own
version of the module, extending it and improving it. Even relatively inexperienced users can
build the breadboard version of the module in order to understand how it works and save
money.
The Arduino Uno is a microcontroller board based on the ATmega328. Arduino is an open-
source, prototyping platform and its simplicity makes it ideal for hobbyists to use as well as
professionals. The Arduino Uno has 14 digital input/output pins (of which 6 can be used as
PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack,
an ICSP header, and a reset button. It contains everything needed to support the
microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-
DC adapter or battery to get started.
• Microcontroller: ATmega328
• Operating Voltage: 5V
• Input Voltage (recommended): 7-12V
• Input Voltage (limits): 6-20V
• Digital I/O Pins: 14 (of which 6 provide PWM output)
25
• Analog Input Pins: 6
• DC Current per I/O Pin: 40 mA
• DC Current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB used by bootloader
• SRAM: 2 KB (ATmega328)
• EEPROM: 1 KB (ATmega328)
• Clock Speed: 16 MHz
A type of relay that can handle the high power required to directly control an electric motor
or other loads is called a contactor. Solid-state relayscontrol power circuits with no moving
parts, instead using a semiconductor device to perform switching. Relays with calibrated
26
operating characteristics and sometimes multiple operating coils are used to protect electrical
circuits from overload or faults; in modern electric power systems these functions are
performed by digital instruments still called "protective relays".
Magnetic latching relays require one pulse of coil power to move their contacts in one
direction, and another, redirected pulse to move them back. Repeated pulses from the same
input have no effect. Magnetic latching relays are useful in applications where interrupted
power should not be able to transition the contacts.
Magnetic latching relays can have either single or dual coils. On a single coil device, the
relay will operate in one direction when power is applied with one polarity, and will reset when
the polarity is reversed. On a dual coil device, when polarized voltage is applied to the reset
coil the contacts will transition. AC controlled magnetic latch relays have single coils that
employ steering diodes to differentiate between operate and reset commands.
A simple electromagnetic relay consists of a coil of wire wrapped around a soft iron
core (a solenoid), an iron yoke which provides a low reluctance path for magnetic flux, a
movable iron armature, and one or more sets of contacts (there are two contacts in the relay
pictured). The armature is hinged to the yoke and mechanically linked to one or more sets of
moving contacts. The armature is held in place by a spring so that when the relay is de-
energized there is an air gap in the magnetic circuit. In this condition, one of the two sets of
contacts in the relay pictured is closed, and the other set is open. Other relays may have more
or fewer sets of contacts depending on their function. The relay in the picture also has a wire
connecting the armature to the yoke. This ensures continuity of the circuit between the moving
contacts on the armature, and the circuit track on the printed circuit board (PCB) via the yoke,
which is soldered to the PCB.
When an electric current is passed through the coil it generates a magnetic field that
activates the armature, and the consequent movement of the movable contact(s) either makes
or breaks (depending upon construction) a connection with a fixed contact. If the set of contacts
was closed when the relay was de-energized, then the movement opens the contacts and breaks
the connection, and vice versa if the contacts were open. When the current to the coil is
switched off, the armature is returned by a force, approximately half as strong as the magnetic
force, to its relaxed position. Usually this force is provided by a spring, but gravity is also used
commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a
27
low-voltage application this reduces noise; in a high voltage or current application it
reduces arcing.
When the coil is energized with direct current, a diode is often placed across the coil to
dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise
generate a voltage spike dangerous to semiconductor circuit components. Such diodes were
not widely used before the application of transistors as relay drivers, but soon became
ubiquitous as early germanium transistors were easily destroyed by this surge. Some
automotive relays include a diode inside the relay case.
28
• Operating environment - minimum and maximum operating temperature and other
environmental considerations such as effects of humidity and salt
• Assembly – Some relays feature a sticker that keeps the enclosure sealed to allow PCB
post soldering cleaning, which is removed once assembly is complete.
• Mounting – sockets, plug board, rail mount, panel mount, through-panel mount, enclosure
for mounting on walls or equipment
• Switching time – where high speed is required
4.2.3 APPLICATIONS
Relays are used wherever it is necessary to control a high power or high voltage circuit
with a low power circuit, especially when galvanic isolation is desirable. The first application
of relays was in long telegraph lines, where the weak signal received at an intermediate station
could control a contact, regenerating the signal for further transmission. High-voltage or high-
current devices can be controlled with small, low voltage wiring and pilots switches. Operators
can be isolated from the high voltage circuit. Low power devices such as microprocessors can
drive relays to control electrical loads beyond their direct drive capability. In an automobile, a
starter relay allows the high current of the cranking motor to be controlled with small wiring
and contacts in the ignition key.
The use of relays for the logical control of complex switching systems like telephone
exchanges was studied by Claude Shannon, who formalized the application of Boolean
algebra to relay circuit design in A Symbolic Analysis of Relay and Switching Circuits. Relays
can perform the basic operations of Boolean combinatorial logic. For example, the boolean
AND function is realised by connecting normally open relay contacts in series, the OR function
by connecting normally open contacts in parallel. Inversion of a logical input can be done with
a normally closed contact. Relays were used for control of automated systems for machine
tools and production lines. The Ladder programming language is often used for designing relay
logic networks.
29
FIG.4.2.1 (1 CHANNEL RELAY)
30
FIG.4.2.3 PIN DIAGRAM OF RELAY
In a similar way to radar and sonar, ultrasonic transducers are used in systems which
evaluate targets by interpreting the reflected signals. For example, by measuring the time
between sending a signal and receiving an echo the distance of an object can be calculated.
Passive ultrasonic sensors are basically microphones that detect ultrasonic noise that is present
under certain conditions.
31
4.3.1 APPLICATION AND PERFORMANCE
Ultrasound can be used for measuring wind speed and direction (anemometer), tank or
channel fluid level, and speed through air or water. For measuring speed or direction, a device
uses multiple detectors and calculates the speed from the relative distances to particulates in
the air or water. To measure tank or channel liquid level, and also sea level (tide gauge), the
sensor measures the distance (ranging) to the surface of the fluid. Further applications
include: humidifiers, sonar, medical ultrasonography, burglar alarms, non-destructive
testing and wireless charging.
Systems typically use a transducer which generates sound waves in the ultrasonic range, above
18 kHz, by turning electrical energy into sound, then upon receiving the echo turn the sound
waves into electrical energy which can be measured and displayed.
The technology is limited by the shapes of surfaces and the density or consistency of the
material. Foam, in particular, can distort surface level readings.[1][2]
This technology, as well, can detect approaching objects and track their positions.
4.4TOGGLE SWITCH
A toggle switch is a type of electrical switch that is commonly used to control the flow of
electricity in electronic devices or electrical circuits. It typically consists of a lever or a
protruding handle that can be flipped up or down to change the state of the switch. When the
lever is in one position, the switch is in the "on" state, allowing the current to flow through the
circuit. When the lever is flipped to the opposite position, the switch is in the "off" state,
interrupting the flow of electricity.
Toggle switches are widely used in various applications, ranging from household devices and
appliances to industrial equipment and electronic instruments. They provide a simple and
reliable means of controlling power supply, enabling users to easily turn devices on or off.
One common example of a toggle switch is the light switch in our homes. By flipping the toggle
lever up or down, we can control the illumination of a room. Similarly, toggle switches can be
found in many electronic devices, such as radios, amplifiers, and computers, allowing users to
control their operation.
32
Toggle switches are valued for their simplicity, durability, and ease of use. Their mechanical
design makes them robust and resistant to wear and tear. Additionally, their distinct on/off
positions make it easy to determine the state of the switch at a glance.
In summary, toggle switches are widely used electrical switches that provide a straightforward
and reliable way to control the flow of electricity in a circuit or device. They are commonly
found in both residential and industrial settings and are appreciated for their simplicity and
durability.
The nine-volt battery, or 9-volt battery, is a common size of battery that was introduced
for the early transistor radios. It has a rectangular prism shape with rounded edges and a
polarized snap connector at the top. This type is commonly used in walkie-
talkies, clocks and smoke detectors.
The nine-volt battery format is commonly available in primary carbon-zinc and alkaline
chemistry, in primary lithium iron disulfide, and in rechargeable form in nickel-cadmium,
nickel-metal hydride and lithium-ion. Mercury-oxide batteries of this format, once common,
have not been manufactured in many years due to their mercury content. Designations for this
33
format include NEDA 1604 and IEC 6F22 (for zinc-carbon) or MN1604 6LR61 (for alkaline).
The size, regardless of chemistry, is commonly designated PP3 - a designation originally
reserved solely for carbon-zinc or in some countries, E or E-block.
Most nine-volt alkaline batteries are constructed of six individual 1.5 V LR61 cells
enclosed in a wrapper. These cells are slightly smaller than LR8D425 AAAA cells and can be
used in their place for some devices, even though they are 3.5 mm shorter. Carbon-zinc types
are made with six flat cells in a stack, enclosed in a moisture-resistant wrapper to prevent
drying. Primary lithium types are made with three cells in series.
In 2007, 9-volt batteries accounted for 4% of alkaline primary battery sales in the US. In
Switzerland in 2008, 9-volt batteries totalled 2% of primary battery sales and 2% of secondary
battery sales
34
4.5.1 TECHNICAL SPECIFICATIONS
The PP3 size battery has height 48.5 mm, width 26.5 mm, depth 17.5 mm (or 1.9 in ×
1.0 in × 0.68 in). Both terminals are at one end and their centers are 1⁄2 inch (12.7 mm) apart.
Inside an alkaline or carbon-zinc 9-volt battery there are six cylindrical or flat cells connected
in series. Some brands use welded tabs internally to attach to the cells, others press foil strips
against the ends of the cells.
Mercury batteries were formerly made in this size. They had higher capacity than the
then-standard carbon-zinc types, a nominal voltage of 8.4 volts, and very stable voltage. Once
used in photographic and measuring instruments or long-life applications, they are no longer
manufactured as mercury is an environmental pollutant.
4.6 CONNECTORS
The battery has both terminals in a snap connector on one end. The smaller circular
(male) terminal is positive, and the larger hexagonal or octagonal (female) terminal is the
negative contact. The connectors on the battery are the same as on the connector itself; the
smaller one connects to the larger one and vice versa. The same snap-style connector is used
on other battery types in the Power Pack (PP) series. Battery polarization is normally obvious
since mechanical connection is usually only possible in one configuration. A problem with this
style of connector is that it is very easy to connect two batteries together in a short circuit,
which quickly discharges both batteries, generating heat and possibly a fire. Because of this
hazard, 9-volt batteries should be kept in the original packaging until they are going to be
used. An advantage is that several nine-volt batteries can be connected to each other in series
to provide higher voltages.
35
FIG.4.6 CONNECTOR
36
CHAPTER 5
PROGRAM CODE
const int trigPin = 9; // Pin connected to the TRIG pin of the ultrasonic sensor
const int echoPin = 10; // Pin connected to the ECHO pin of the ultrasonic sensor
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
37
// Initialize serial communication for debugging purposes
Serial.begin(9600);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
38
// If the distance is less than a threshold (e.g., 20 cm), stop the train by activating the
relay
} else {
39
RESULT
DESCRIPTION:
40
CHAPTER 6
CONCLUSION
41
REFERENCES
1. "Railway Collision Avoidance System Using Wireless Sensor Networks" (IEEE
Transactions on Intelligent Transportation Systems, 2019).
3. "Collision Avoidance System for Railways Using IoT and Data Analytics" (IEEE Internet
of Things Journal, 2019).
4. "Railway Safety System Using GNSS and Sensor Fusion" (IEEE Transactions on
Instrumentation and Measurement, 2018).
5. "Intelligent Railway Collision Avoidance System Using Deep Learning" (IEEE Transactions
on Neural Networks and Learning Systems, 2020).
42