Smart City Traffic Control for Ambulance with Accident dtection

56
Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System Abstract Traffic congestion and tidal flow management were recognized as major problems in modern urban areas, which have caused much thwarting for the ambulance. Moreover road accidents in the city have been incessant and to bar the loss of life due to the accidents is even more crucial. To implement this we introduce a scheme called AARS (Automatic ambulance rescue system). The main theme behind this scheme is to provide a smooth flow for the ambulance to reach the hospitals in time and thus minifying the expiration. The idea behind this scheme is to implement a ITS which would control mechanically the traffic lights in the path of the ambulance. The ambulance is controlled by the central unit which furnishes the most scant route to the ambulance and also controls the traffic light according to the ambulance location and thus reaching the hospital safely. The server also determines the location of the accident spot through the sensor systems in the vehicle which encountered the accident and thus the server walks through the ambulance to the spot. This scheme is fully automated, thus it finds the accident spot, controls the traffic lights, helping to reach the hospital in time. In this project we build a city traffic model and demonstrate how ambulance can be guided smoothly across densed city traffic. We also create a central sensor

description

A project powered by Arduino that implements the concept of city traffic monitoring and controlling for priority vehicles like ambulance. The report provides minute details about every section of the hardware.

Transcript of Smart City Traffic Control for Ambulance with Accident dtection

Page 1: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Abstract

Traffic congestion and tidal flow management were recognized as major problems in

modern urban areas, which have caused much thwarting for the ambulance.

Moreover road accidents in the city have been incessant and to bar the loss of life due

to the accidents is even more crucial. To implement this we introduce a scheme

called AARS (Automatic ambulance rescue system). The main theme behind this

scheme is to provide a smooth flow for the ambulance to reach the hospitals in time

and thus minifying the expiration. The idea behind this scheme is to implement a

ITS which would control mechanically the traffic lights in the path of the ambulance.

The ambulance is controlled by the central unit which furnishes the most scant route

to the ambulance and also controls the traffic light according to the ambulance location

and thus reaching the hospital safely. The server also determines the location of the

accident spot through the sensor systems in the vehicle which encountered the accident

and thus the server walks through the ambulance to the spot. This scheme is fully

automated, thus it finds the accident spot, controls the traffic lights, helping to reach the

hospital in time.

In this project we build a city traffic model and demonstrate how ambulance can be guided

smoothly across densed city traffic. We also create a central sensor monitoring system for

accidents.

Chapter 1

Page 2: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Project Concept

The project has following main Units:

1) Microcontroller

2) Power Supply

3) Traffic Light Set

4) Ambulance Vehicle

5) Sample Vehicle to test Accident case

6) Sensors: a) IR, b) LDR

First We build a traffic junction with 4 pairs of traffic light sets with one green and one red

LED lights. These are controlled with a Transistor switch mechanism where transistor(NPN-

BC548) base is driven by Arduino's digital pin. Under normal situation, traffic light turns

green in every area in a rotation based system.

Page 3: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Page 4: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

We create ambulance model with an IR remote preprogrammed and installed on the top of the

vehicle. There are 10 distinct switches and 10^10 possibilities are there. Hence technically it

is sufficient to accomodate in real time in all city ambulances.

We installed IR receiver before and after the Traffic junction. The soon Ambulance comes in

proximity, traffic light in the section becomes green and remains green till it leaves the

junction and goes away from proximity of the receiver on the other side.

Accident Monitoring System

Our second module is accident monitoring system where we installed 4 LDR sensors across

four road junction. We create following special vehicle model.

Page 5: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Page 6: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

The vehicle has a Green LED on one side of the vehicle and a push switch at the front.

Whenever collision/accident occurs, it triggers the switch glowing the vehicle light.

Once the accident light is triggered, it triggers LDR even. Every area has a LDR sensor.

Hence MC can easily identify the area where accident has occurred.

Page 7: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Page 8: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 3

Microcontroller Unit

We use Arduino Dueminolova with ATMEG328 Microcontroller in our project. For entire

model to drive smoothly, the ground of power supply is made common with arduino

ground. Note that digital pins of Arduino produces about 4.2 v which is sufficient to drive

LEDs. However it does not produce enough current. Hence without external current, the

project runs a risk at draining microcontroller. Therefore alternative supply is used with it.

Page 9: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Arduino is a popular open-source single-board microcontroller, descendant of the open-

source Wiring platform, designed to make the process of using electronics in

multidisciplinary projects more accessible. The hardware consists of a simple open hardware

design for the Arduino board with an Atmel AVR processor and on-board input/output

support. The software consists of a standard programming language compiler and the boot

loader that runs on the board.

Arduino hardware is programmed using a Wiring-based language (syntax and libraries),

similar to C++ with some simplifications and modifications, and a Processing-based

integrated development environment.

Current versions can be purchased pre-assembled; hardware design information is available

for those who would like to assemble an Arduino by hand. Additionally, variations of the

Italian-made Arduino—with varying levels of compatibility—have been released by third

parties; some of them are programmed using the Arduino software.

The Arduino project received an honorary mention in the Digital Communities category at

the 2006 Prix Ars Electronica.[

Hardware

An Arduino board consists of an 8-bit Atmel AVR microcontroller with complementary

components to facilitate programming and incorporation into other circuits. An important

aspect of the Arduino is the standard way that connectors are exposed, allowing the CPU

board to be connected to a variety of interchangeable add-on modules (known as shields).

Official Arduinos have used the megaAVR series of chips, specifically the ATmega8,

ATmega168, ATmega328, ATmega1280, and ATmega2560. A handful of other processors

have been used by Arduino compatibles. Most boards include a 5 volt linear regulator and a

16 MHz crystal oscillator (or ceramic resonator in some variants), although some designs

such as the LilyPad run at 8 MHz and dispense with the onboard voltage regulator due to

specific form-factor restrictions. An Arduino's microcontroller is also pre-programmed with a

boot loader that simplifies uploading of programs to the on-chip flash memory, compared

with other devices that typically need an external programmer.

Page 10: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

At a conceptual level, when using the Arduino software stack, all boards are programmed

over an RS-232 serial connection, but the way this is implemented varies by hardware

version. Serial Arduino boards contain a simple inverter circuit to convert between RS-232-

level and TTL-level signals. Current Arduino boards are programmed via USB, implemented

using USB-to-serial adapter chips such as the FTDI FT232. Some variants, such as the

Arduino Mini and the unofficial Boarduino, use a detachable USB-to-serial adapter board or

cable, Bluetooth or other methods. (When used with traditional microcontroller tools instead

of the Arduino IDE, standard AVR ISP programming is used.)

The Arduino board exposes most of the microcontroller's I/O pins for use by other circuits.

The Diecimila, now superseded by the Duemilanove, for example, provides 14 digital I/O

pins, six of which can produce pulse-width modulated signals, and six analog inputs. These

pins are on the top of the board, via female 0.1 inch headers. Several plug-in application

"shields" are also commercially available.

The Arduino Nano, and Arduino-compatible Bare Bones Board and Boarduino boards

provide male header pins on the underside of the board to be plugged into solderless

breadboards.

Arduino Board Models

Arduin

oProcessor

Volt

age

Fla

sh

kB

EEPR

OM

kB

SR

AM

kB

Digi

tal

I/O

pins

...w

ith

PW

M

Ana

log

inp

ut

pins

USB

Interfa

ce

type

Dimen

sions

inches

Dimen

sions

mm

Diecimi

laATmega168 5 V 16 0.5 1 14 6 6 FTDI

2.7 in

×

2.1 in

68.6 m

m ×

53.3 m

m

Page 11: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Due[11]ATMEL

SAM3U

25

60[12] 50 54 16 16

Duemil

anove

ATmega168/328

P5 V

16/

320.5/1 1/2 14 6 6 FTDI

2.7 in

×

2.1 in

68.6 m

m ×

53.3 m

m

Uno ATmega328P 5 V 32 1 2 14 6 6ATmeg

a8U2

2.7 in

×

2.1 in

68.6 m

m ×

53.3 m

m

Leonard

oAtmega32u4 5 V 32 1 2 14 6 12

Atmega

32u4

2.7 in

×

2.1 in

68.6 m

m ×

53.3 m

m

Mega ATmega1280 5 V12

84 8 54 14 16 FTDI

4 in ×

2.1 in

101.6 

mm ×

53.3 m

m

Mega25

60ATmega2560 5 V

25

64 8 54 14 16

ATmeg

a8U2

4 in ×

2.1 in

101.6 

mm ×

53.3 m

m

Fio ATmega328P 3.3 

V

32 1 2 14 6 8 None 1.6 in

×

40.6 m

m ×

Page 12: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

1.1 in27.9 m

m

NanoATmega168 or 

ATmega3285 V

16/

320.5/1 1/2 14 6 8 FTDI

1.70 in

×

0.73 in

43 mm

×

18 mm

LilyPadATmega168V or

ATmega328V

2.7-

5.5 

V

16 0.5 1 14 6 6 None 2 in ⌀50 mm

The board with marked color is used for this project.

Arduino Software

The Arduino IDE is a cross-platform application written in Java, and is derived from the IDE

for the Processing programming language and the Wiring project. It is designed to introduce

programming to artists and other newcomers unfamiliar with software development. It

includes a code editor with features such as syntax highlighting, brace matching, and

automatic indentation, and is also capable of compiling and uploading programs to the board

with a single click. There is typically no need to edit makefiles or run programs on a

Page 13: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

command-line interface. Although building on command-line is possible if required with

some third-party tools such as Ino.

The Arduino IDE comes with a C/C++ library called "Wiring" (from the project of the same

name), which makes many common input/output operations much easier. Arduino programs

are written in C/C++, although users only need define two functions to make a runnable

program:

setup() – a function run once at the start of a program that can initialize settings

loop() – a function called repeatedly until the board powers off

A typical first program for a microcontroller simply blinks a LED on and off. In the Arduino

environment, the user might write a program like this:[14]

#define LED_PIN 13

void setup () {

pinMode (LED_PIN, OUTPUT); // enable pin 13 for digital output

}

void loop () {

digitalWrite (LED_PIN, HIGH); // turn on the LED

delay (1000); // wait one second (1000 milliseconds)

digitalWrite (LED_PIN, LOW); // turn off the LED

delay (1000); // wait one second

}

For the above code to work correctly, the positive side of the LED must be connected to pin

13 and the negative side of the LED must be connected to ground. The above code would not

be seen by a standard C++ compiler as a valid program, so when the user clicks the "Upload

Page 14: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

to I/O board" button in the IDE, a copy of the code is written to a temporary file with an extra

include header at the top and a very simple main() function at the bottom, to make it a valid

C++ program.

The Arduino IDE uses the GNU toolchain and AVR Libc to compile programs, and uses

avrdude to upload programs to the board.

For educational purposes there is third party graphical development environment called

Minibloq available under a different open source license.

Arduino Duemilanove

Page 15: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Overview

The Arduino Duemilanove ("2009") is a microcontroller board based on

the ATmega168 or ATmega328. It 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.

"Duemilanove" means 2009 in Italian and is named after the year of its release. The

Duemilanove is the latest in a series of USB Arduino boards; for a comparison with previous

versions.

Summary

Microcontroller ATmega168

Operating Voltage 5V

Input Voltage

(recommended)7-12V

Input Voltage (limits) 6-20V

Page 16: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Digital I/O Pins 14 (of which 6 provide PWM output)

Analog Input Pins 6

DC Current per I/O Pin 40 mA

DC Current for 3.3V Pin 50 mA

Flash Memory16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB used

by bootloader

SRAM 1 KB (ATmega168) or 2 KB (ATmega328)

EEPROM 512 bytes (ATmega168) or 1 KB (ATmega328)

Clock Speed 16 MHz

Power

The Arduino Duemilanove can be powered via the USB connection or with an external power

supply. The power source is selected automatically.

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.

The adapter can be connected by plugging a 2.1mm center-positive plug into the board's

power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the

POWER connector.

The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,

however, the 5V pin may supply less than five volts and the board may be unstable. If using

more than 12V, the voltage regulator may overheat and damage the board. The recommended

range is 7 to 12 volts.

The power pins are as follows:

VIN. The input voltage to the Arduino board when it's using an external power source (as

opposed to 5 volts from the USB connection or other regulated power source). You can

supply voltage through this pin, or, if supplying voltage via the power jack, access it through

this pin.

Page 17: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

5V. The regulated power supply used to power the microcontroller and other components on

the board. This can come either from VIN via an on-board regulator, or be supplied by USB

or another regulated 5V supply.

3V3. A 3.3 volt supply generated by the on-board FTDI chip. Maximum current draw is 50

mA.

GND. Ground pins.

Memory

The ATmega168 has 16 KB of flash memory for storing code (of which 2 KB is used for the

bootloader); the ATmega328has 32 KB, (also with 2 KB used for the bootloader).

The ATmega168 has 1 KB of SRAM and 512 bytes of EEPROM (which can be read and

written with the EEPROM library); the ATmega328 has 2 KB of SRAM and 1 KB of

EEPROM.

Input and Output

Each of the 14 digital pins on the Duemilanove can be used as an input or output,

using pinMode(), digitalWrite(), anddigitalRead() functions. They operate at 5 volts. Each pin

can provide or receive a maximum of 40 mA and has an internal pull-up resistor

(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These

pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.

External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low

value, a rising or falling edge, or a change in value. See the attachInterrupt() function for

details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication

using the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value,

the LED is on, when the pin is LOW, it's off.

The Duemilanove has 6 analog inputs, each of which provide 10 bits of resolution (i.e. 1024

different values). By default they measure from ground to 5 volts, though is it possible to

Page 18: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

change the upper end of their range using the AREF pin and the analogReference() function.

Additionally, some pins have specialized functionality:

I2C: analog input pins A4 (SDA) and A5 (SCL). Support I2C (TWI) communication using

the Wire library.

There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogReference().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button

to shields which block the one on the board.

See also the mapping between Arduino pins and ATmega168 ports.

Communication

The Arduino Duemilanove has a number of facilities for communicating with a computer,

another Arduino, or other microcontrollers. The ATmega168 and ATmega328 provide UART

TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX). An

FTDI FT232RL on the board channels this serial communication over USB and the FTDI

drivers (included with the Arduino software) provide a virtual com port to software on the

computer. The Arduino software includes a serial monitor which allows simple textual data to

be sent to and from the Arduino board. The RX and TX LEDs on the board will flash when

data is being transmitted via the FTDI chip and USB connection to the computer (but not for

serial communication on pins 0 and 1).

A SoftwareSerial library allows for serial communication on any of the Duemilanove's digital

pins.

The ATmega168 and ATmega328 also support I2C (TWI) and SPI communication. The

Arduino software includes a Wire library to simplify use of the I2C bus; see

the documentation for details. For SPI communication, use the SPI library.

Programming

The Arduino Duemilanove can be programmed with the Arduino software (download). Select

"Arduino Diecimila or Duemilanove w/ ATmega168" or "Arduino Duemilanove

Page 19: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

w/ ATmega328" from the Tools > Board menu (according to the microcontroller on your

board).

The ATmega168 or ATmega328 on the Arduino Duemilanove comes preburned with

a bootloader that allows you to upload new code to it without the use of an external hardware

programmer. It communicates using the original STK500protocol (reference, C header files).

You can also bypass the bootloader and program the microcontroller through the ICSP (In-

Circuit Serial Programming) header; see these instructions for details.

Automatic (Software) Reset

Rather then requiring a physical press of the reset button before an upload, the Arduino

Duemilanove is designed in a way that allows it to be reset by software running on a

connected computer. One of the hardware flow control lines (DTR) of the FT232RL is

connected to the reset line of the ATmega168 or ATmega328 via a 100 nanofarad capacitor.

When this line is asserted (taken low), the reset line drops long enough to reset the chip. The

Arduino software uses this capability to allow you to upload code by simply pressing the

upload button in the Arduino environment. This means that the bootloader can have a shorter

timeout, as the lowering of DTR can be well-coordinated with the start of the upload.

This setup has other implications. When the Duemilanove is connected to either a computer

running Mac OS X or Linux, it resets each time a connection is made to it from software (via

USB). For the following half-second or so, the bootloader is running on the Duemilanove.

While it is programmed to ignore malformed data (i.e. anything besides an upload of new

code), it will intercept the first few bytes of data sent to the board after a connection is

opened. If a sketch running on the board receives one-time configuration or other data when

it first starts, make sure that the software with which it communicates waits a second after

opening the connection and before sending this data.

The Duemilanove contains a trace that can be cut to disable the auto-reset. The pads on either

side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may

also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset

line; see this forum thread for details.

USB Overcurrent Protection

Page 20: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

The Arduino Duemilanove has a resettable polyfuse that protects your computer's USB ports

from shorts and overcurrent. Although most computers provide their own internal protection,

the fuse provides an extra layer of protection. If more than 500 mA is applied to the USB

port, the fuse will automatically break the connection until the short or overload is removed.

Physical Characterist ics

The maximum length and width of the Duemilanove PCB are 2.7 and 2.1 inches respectively,

with the USB connector and power jack extending beyond the former dimension. Three

screw holes allow the board to be attached to a surface or case. Note that the distance

between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil spacing of

the other pins.

Pin Configuration

Chapter 4

Power Supply Unit

Page 21: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

1. Step down transformer

2. Voltage regulator

3. Capacitors

4. Diodes

Let’s get into detail of rating of the devices :

Voltage regulator :

As we require a 5V we need LM7805 Voltage Regulator IC.

7805 IC Rating :

Input voltage range 7V- 35V

Current rating Ic = 1A

Output voltage range   VMax=5.2V ,VMin=4.8V 

Page 22: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

LM7805 – Pin Diagram

Transformer :

Selecting a suitable transformer is of great importance. The current rating and the secondary

voltage of the transformer is a crucial factor.

The current rating of the transformer depends upon the current required for the load to be

driven.

The input voltage to the 7805 IC should be at least 2V greater than the required 2V

output, therefore it requires an input voltage at least close to 7V.

So I chose a 6-0-6 transformer with current rating 500mA (Since 6*√2 = 8.4V).

NOTE : Any transformer which supplies secondary peak voltage up to 35V can be used but as

the voltage increases size of the transformer and power dissipation across regulator increases.

Rectifying circuit :

The best is using a full wave rectifier

Its advantage is DC saturation is less as in both cycle diodes conduct.

Higher Transformer Utilization Factor (TUF).

1N4007 diodes are used as its is capable of withstanding a higher reverse voltage of

1000v whereas 1N4001 is 50V

Page 23: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Center Tap Full Wave Rectifier

Capacitors :

Knowledge of Ripple factor is essential while designing the values of capacitors

It is given by

Y=1/(4√3fRC)  (as the capacitor filter is used)

1. f= frequency of AC ( 50 Hz)

2. R=resistance calculated

R= V/Ic   

V= secondary voltage of transformer

     V=6√2=8. 4

     R=8.45/500mA=16.9Ω standard 18Ω chosen

3. C= filtering capacitance

We have to determine this capacitance for filtering

Y=Vac-rms/Vdc

Vac-rms = Vr/2√3

Vdc= VMax-(Vr/2)

Vr= VMax- VMin

Page 24: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

  Vr = 5.2-4.8 =0. 4V

   Vac-rms = .3464V

   Vdc = 5V

    Y=0 .06928

Hence the capacitor value is found out by substituting the ripple factor in Y=1/(4√3fRC)

Thus, C= 2314 µF and  standard 2200µF is chosen

Datasheet of 7805 prescribes to use a 0.01μF capacitor at the output side to

avoid transient changes in the voltages due to changes in load and a 0.33μF at the input side

of regulator to avoid ripples if the filtering is far away from regulator.

Circuit Diagram

5V Power Supply Circuit using 7805 Voltage Regulator

Page 25: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 5

Traffic Light Set

A traffic light set contains One Green LED and One Red LED Connected with Transsistors.

Anode of LED's are connected to +5v and grounds are connected to collector of their

respective transistors. Transistors emitter is grounded. Transistor is given base current

through a 100 ohm resistor from Digital PINs of Arduino

Following is the circuit diagram:

Page 26: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

LED is connected with a resistor to limit the current.

Page 27: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 6

Arduino with LDR Light Sensor

Page 28: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

The LDR is given power supply through a 1K resistor from board power out +5v VCC and

Ground pin. LDR’s positive output is taken as input for reading the Light variation. The

program continuesly reads the value of pin 5 of the analog ports. Where there are no objects

in between, voltage across pin 5 is low, and when an object is placed, it is very high. Based

on this information product is counted.

CODE

void setup()

{

Serial.begin(19200);

}

Page 29: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

void loop()

{

int a=analogRead(5);// assume LDR's output is connected to pin 5

Serial.println(a);

if(a<600)

{

Serial.println("Medium Light");

}

if(a<200)

{

Serial.println("High Light");

}

if(a>950)

{

Serial.println("Low Light");

}

}

Chapter 7

Arduino with IR Protocol

Page 30: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

IR Communication Basics

IR radiation is simply light that we cannot see, which makes it great for

communication. IR sources are all around us. The sun, light bulbs, or any anything

with heat is very bright in the IR spectrum. When you use your TV remote, an IR

LED is used to transmit information to your TV. So, how does the IR receiver in

your TV pick out signals from your remote among all of the ambient IR? The answer

is that the IR signal is modulated. Modulating a signal is like assigning a pattern to

your data, so that the receiver knows to listen.

A common modulation scheme for IR communication is something called 38kHz

modulation. There are very few natural sources that have the regularity of a 38kHz

signal, so an IR transmitter sending data at that frequency would stand out among

the ambient IR. 38kHz modulated IR data is the most common, but other

frequencies can be used.

When you hit a key on your remote, the transmitting IR LED will blink very quickly

for a fraction of a second, transmitting encoded data to your appliance.

Each pulse is turned on and off at a frequency of 38kHz

If you were to hook an oscilloscope up to your TV remote’s IR LED, you would see a

signal similar to the one above. This modulated signal is exactly what the receiving

system sees. However, the point of the receiving device is to demodulate the signal

and output a binary waveform that can be read by a microcontroller. When you read

the OUT pin of the TSOP382 with the wave from above, you will see something like

this:

Page 31: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

By controlling the spacing between the transmitted modulated signals, the

waveform can be read by an input pin on a microcontroller and decoded as a serial

bit stream.

Below is conceptual view of how an IR transmitter receiver pair works.

Thanks to SBProjects.com for the gif and excellent IR resource!

An Arduino or other microcontroller can be connected to either end of the system to

transmit data (left side) or receive data (right side).

Hardware Setup

For the hardware in this tutorial, you will need these parts:

Arduino Uno

IR LED

TSOP382 IR Receiver

Mini Push Button Switch

330Ω Resistors

IR Keychain Remote  or any IR remote that uses 38kHz modulation

You will be setting up two separate circuits both using an Arduino. The first

example circuit uses a TSOP382 IR photo sensor to receive and demodulate the IR

signal from a common remote control. The second example circuit uses an IR LED

Page 32: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

and current limiting resistor to transmit IR codes to a common appliance, for

example a home stereo or TV.

Here is the complete setup for connecting to an Arduino:

Hardware setup for both of the examples.

Be sure to connect your LED correctly! The long leg is positive and connects to the

resistor, then to the Arduino’s output pin. The short leg is negative and is connected

to ground (GND).

Also, you cannot see IR LED light with your eyes, since IR radiation is outside of the

visible spectrum. However, most cellphone cameras can detect short wave IR and

can see the LED faintly glowing.

When the LED is modulating at 38kHz, the LED should appear constantly lit, but

dim.

Page 33: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Also, pay attention to the polarity of the TSOP382. Refer to the TSOP382

datasheet for the pinout of the sensor.

The current limiting resistor attached to the LED can have values down to 100Ω

(40mA) for full power and longest range. If you use a larger value resistor, the LED

won’t light as bright and your range will suffer. With a 330Ω resistor, you should be

able to operate the IR LED across a dimly lit room.

Receiving IR Example

 

In this example, all you need is the TSOP382 IR receiver connected to an Arduino

and a common remote control. The IR LED and button can stay connected, but you

will not use it until the next example.

IR remote controls are as ubiquitous as their appliance counterparts. What if you

could put all of those old remote controls to use in your next project? This example

will show you how to read IR remote codes from any IR remote using the TSOP382

IR photo sensor and an Arduino. Once you can receive codes from individual button

presses, your remote control and Arduino become a general purpose, short range,

communication interface!

The first thing you need to do is install the IR Arduino library. Instructions on how

to install an Arduino library can be found here.

IR Arduino Library

After downloading the IR library, go to your Arduino project directory -> libraries -

> IRremote -> examples -> IRrecvDemo -> and open the IRrecvDemo.ino. Upload

the sketch to your Arduino.

The sketch will automatically decode the type of remote you are using and identify

which button on your remote is pressed. Open the serial port in the Arduino IDE at

9600 bps and hit different buttons on your remote.

Page 34: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Terminal window displaying random button presses on my remote. Different

buttons show different codes.

When specific buttons are pressed, you can use the incoming values to do

something else in your code, for example turn on and off a motor or LED.

The results from each button press can be found by calling the value() method:

Copy Code

results.value

You can print the values to the terminal window:

Copy Code

Serial.println(results.value, HEX); //prints the hex value a a button press

Or you might need read the values to run a conditional statement:

Copy Code

if(irrecv.decode(&results)) //this checks to see if a code has been received{ if(results.value == 0xC284) //if the button press equals the hex value 0xC284 { //do something useful here } irrecv.resume(); //receive the next value}

Page 35: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Transmitting IR Example

This example uses both the LED and TSOP382.

In this example, your Arduino and an IR LED imitate an IR remote to control an

appliance (TV, stereo, etc.). In order to control your appliance with the LED, you

need to know what type of IR protocol your appliance uses. The easiest way to find

this out is to have the remote that comes with the appliance.

The following image explain the setup used in the project

Page 36: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 8

Circuit Diagram

Page 37: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 9

Coding

#include <Timer.h>

Page 38: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

#include <IRremote.h>

int RECV_PIN = 9;//2

int RECV_PIN1 = 3;//1

int T=0;

int ambulance=-1;

IRrecv irrecv1(RECV_PIN1);

decode_results results;

int road_Segment=1;

int shouldDecode=0;

Timer t;

int GREEN_1=12;

int RED_1=11;

int GREEN_2=8;

int RED_2=10;

int GREEN_3=7;

int RED_3=6;

int GREEN_4=5;

int RED_4=4;

int ALL_GREEN[4];

int ALL_RED[4];

int TRAFF_IND=0;

void setup() {

// initialize the digital pin as an output.

// Pin 13 has an LED connected on most Arduino boards:

for(int i=0;i<=13;i++)

pinMode(i, OUTPUT);

ALL_GREEN[0]=GREEN_1;

Page 39: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

ALL_GREEN[1]=GREEN_2;

ALL_GREEN[2]=GREEN_3;

ALL_GREEN[3]=GREEN_4;

ALL_RED[0]=RED_1;

ALL_RED[1]=RED_2;

ALL_RED[2]=RED_3;

ALL_RED[3]=RED_4;

t.every(5000,SwitchLights,(void *)0 );

t.every(500,CheckLeave,(void *)0 );

Serial.begin(9600);

pinMode(3,INPUT);

pinMode(9,INPUT); // Start the receiver

SwitchLights((void*)0);

irrecv1.enableIRIn(); // Start the receiver

}

void CheckLeave(void * temp)

{

T++;

shouldDecode=5;

int TH=500;

int a=analogRead(5);

int b=analogRead(4);

int c=analogRead(3);

int d=analogRead(2);

Page 40: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

if(a<TH)

{

Serial.println("ACCIDENT in 1");

}

if(b<TH)

{

Serial.println("ACCIDENT in 2");

}

if(c<TH)

{

Serial.println("ACCIDENT in 3");

}

if(d<TH)

{

Serial.println("ACCIDENT in 4");

}

}

void SwitchLights(void * temp)

{

shouldDecode=5;

if(ambulance==1)

{

return;

}

for(int i=0;i<4;i++)

{

if(i==TRAFF_IND)

{

digitalWrite(ALL_GREEN[i],HIGH);

Page 41: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

}

else

{

digitalWrite(ALL_GREEN[i],LOW);

}

}

for(int i=0;i<4;i++)

{

if(i==TRAFF_IND)

{

digitalWrite(ALL_RED[i],LOW);

}

else

{

digitalWrite(ALL_RED[i],HIGH);

}

}

TRAFF_IND++;

if(TRAFF_IND>3)

{

TRAFF_IND=0;

}

}

void loop()

{

t.update();

if (irrecv1.decode(&results)&& shouldDecode<=-5)

{

Page 42: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

if(ambulance<0)

{

Serial.println("AMB IN JNC");

shouldDecode=0;

Serial.println(results.value,HEX);

// Receive the next value

TRAFF_IND=3;

SwitchLights((void*)0);

ambulance=1;

}

delay(100);

irrecv1.resume();

T=0;

}

if(T>=8)

{

if(ambulance==1)

{

Serial.println("Ambulance Left");

ambulance=-1;

SwitchLights((void*)0);

}

T=0;

}

shouldDecode--;

delay(10);

}

Page 43: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 10

Results

Page 44: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

Chapter 11

Conclusion

Smart Traffic system is need of the hour to meet busy city traffic demands. Lot of research is

being carried out in the direction of density based traffic monitoring. Where as not much

work is being done towards priority based traffic management where different priority is

being given to different sets of vehicles.

Page 45: Smart City Traffic Control for Ambulance with Accident dtection

Intelligent Ambulance Traffic Assistance and Centralized Accident Alert System

In this project we demonstrate that a scalable real time traffic solution can be successfully

generated for ambulances. The system is also shown to be real time as it is tested with real

moving vehicles.

We also show sensor based accident alert system. This helps city authorities to monitor the

accidents and send ambulance urgently in that place. This unit is handfull in highway

accident monitoring and prevention system.