Professional Documents
Culture Documents
Road accidents are increasing, day by day - the causes being carelessness
and rash driving. Therefore an efficient system is needed to indicate and display
the drunken-drive and over speed and is further essential to take necessary controls
reports the distance as an analog voltage. Using this sensor, the distance between
two vehicles is known and hence when the vehicles are closer to each other, the
speed of the vehicle is reduced, to avoid collision. To control the motor speed,
pulse width modulation is used in which the duty cycle of a square wave output
from the microcontroller is varied. The drunken-drive can be identified by the use
human breath. If the concentration exceeds limit, the vehicle will not start. Both
the levels will be indicated in the LCD and necessary controls will be taken when
ABSTRACT
TABLE OF CONTENT
LIST OF TABLES
LSIT OF FIGURES
LIST OF SYMBOLS
LIST OF APPENDICES
1 INTRODUCTION
1.1 Background 1
1.2 Objective of Project 2
1.3 Scope of Project 2
1.4 Outline of Thesis 2
1.5 Summary of Works 3
1. INTRODUCTION:
The possibility of every human being must have had a small accident
or suffered a very severe accident so that lives will likely float. This is
because due to lack of security in a car next to the negligence of the driver’s
own. As time runs, the more technology develops very rapidly as well as
security technology in order to minimize car accidents that could save
someone’s life.
We all know that driving the vehicle over the speed limit of the
particular zone, is one of the main causes of vehicle accidents. This rash
driving leads to uncontrollable nature of the vehicle, and hence results in
accidents. Apart from the rash driving, consciousness of the driver is also
considered more important. A drunken driver has imbalanced mentality
which may also result in accidents while driving. Therefore an efficient
system is needed to indicate the over-speed and drunken-drive and to take
necessary controls to avoid accidents.
1.1 OBJECTIVE:
The main aim of this project which we have undertaken is to prevent
over speeding and drunken-drive so as to prevent vehicular collisions. This
idea is mainly applicable in the roads which follow lane system.
1.2 SCOPE OF PROJECT:
The scope of this project includes C language to program
microcontroller ATmega8, build hardware for the system, and interface the
hardware to the microcontroller by using parallel port communication.
1.3 EXISTING TECHNOLOGIES:
The quest for accident free future had given us a major number of
safety technologies, some of which are listed as below. Some of these are
still in action, whereas some are yet to be implemented. Few of these
technologies have been removed from use by certain countries due to
severe disadvantages caused by them. These technologies either prove to be
efficient preventive scheme or protective scheme, but rarely both.
1.3.1 REAR TRAFFIC CROSSING:
The sensor needs 5V to operate, give regulated +5V DC supply. The sensor
will take around 180mA supply. The sensor will heat a little bit since it has internal
heater that heats the sensing element.
Measure the output voltage through multi-meter between A.OUT and Ground
pins or Use a microcontroller to measure the voltage output. Best way to check the
sensor is take a bottle of after shave liquid and open the cap. Take the sensor near
the bottle output. You will see increase in the readings.
2.1.1.4 SENSITIVITY :
Basically, it has 6pins, the cover and the body. Even though it has 6 pins, you
can use only 4 of them. Two of them are for the heating system, which are called H
and the other 2 are for connecting power and ground, which are A and B.
PIN DETAILS:
1 GND Power Supply Ground
2 A.OUT Analog Voltage Out
3 +5V Supply voltage DC +5V regulated
INTERFACING:
Fig 2.8 Sample circuit diagram for interfacing sensor with microcontroller
To connect the sensor, you have to connect one of the H pin to +5V Supply
and the other one to Ground.
2.1.1.8 SPECIFICATIONS:
A. STANDARD WORKING CONDITION:
Table 2.1 Standard conditions
O Oxygen 21%(std
condition)Oxygen
concentration
can affect sensitivity
C. STRUCTURE:
Table 2.3 Structural configuration
PARTS MATERIALS
Gas sensing Sno2
Electrode Au
Electrode line Pt
Heater coil Ni-Cr coil alloy
Tubular ceramic Al2O3
2.1.2.1 FEATURES :
V = 1 / (R + k)
Where V is voltage and R is range, the equation produces a very straight line.
The division operation acts as a linearizing function that turns the ungainly curve
into a linear plot. This observation is the key to finding a simple approximation
function for a Sharp IR range finder. The first step in getting a good voltage-to-
range function is to find a constant k that linearizes the data.
The next step is to find a straight line approximation that relates the voltage to
the linearizing function. This involves finding suitable m and b constants for the
familiar line equation:
y=m*x+b
In this case, y is equal to the linearized range. Substituting the linearizing
function from above for y and substituting V for x yields:
1 / (R + k) = m * V + b
Rearranging the equation terms gives range as a function of voltage:
R = (1 / (m * V + b)) - k
This is a useful result for languages that support floating point math, but it can
be rearranged further to get:
R = (m' / (V + b')) - k
Where m' = 1/m and b' = b/m.
Finding the value of constants takes a bit of work. The first step is to get
some calibration data. This can be obtained experimentally or "eyeballed" from
the voltage-to-range curve. Create a table of voltage vs. range for a set of range
values. Then create a table of voltage in controller unit vs. linearized range. Some
experimentation may be required to find a k constant that produces a linear plot.
Do a linear regression on that data to find m and b to find their corresponding
values.
Fig 2.16 Analog output voltage Vs Distance to reflected object
PIN DETAILS:
INTERFACING:
To connect the sensor, connect Pin 2 to GND and Pin 3 to +5V Vcc
supply.
2.1.2.5 SPECIFICATIONS:
For an 8-bit data bus, the display requires a +5V supply plus 11 I/O
lines. For a 4-bit data bus it only requires the supply lines plus seven extra
lines. When the LCD display is not enabled, data lines are tri-state and they
do not interfere with the operation of the microcontroller.
Data can be placed at any location on the LCD. For 16×2 LCD, the
address locations are:
First line 80 81 82 83 84 85 86 through 8F
2) READ/WRITE (R/W):
This line determines the direction of data between the LCD and
microcontroller. When it is low, data is written to the LCD. When it is
high, data is read from the LCD.
3) REGISTER SELECT (RS):
With the help of this line, the LCD interprets the type of data on
data lines. When it is low, an instruction is being written to the LCD.
When it is high, a character is being written to the LCD.
2.1.3.2 LOGIC STATUS ON CONTROL LINE:
• E – 0 Access to LCD disabled
– 1 Access to LCD enabled
• R/W – 0 Writing data to LCD
– 1 Reading data from LCD
• RS – 0 Instruction
– 1 Character
2.1.3.3 WRITING AND READING THE DATA FROM LCD:
Writing data to LCD is done in several ways:
1. Set R/W bit to low.
2. Set RS bit to logic 0 or 1 (instruction or character).
3. Set data to data lines (if it is writing).
4. Set E line to high.
5. Set E line to low.
Reading data from data lines (if it is reading):
1. Set R/W bit to high.
2. Set RS bit to logic 0 or 1 (instruction or character).
3. Set data to data lines (if it is writing).
4. Set E line to high.
5. Set E line to low.
2.1.3.4 PIN DESCRIPTION:
Most LCDs with 1 controller has 14 pins and LCDs with 2
controllers has 16 pins (2 pins are extra in both for back-light LED
connections).
1. An armature core
2. An air gap
3. Poles
4. A yoke
5. An armature winding
6. A field winding
8. Commutator
10.A shaft
Fig 2.23 Brushless DC motor schematic diagram
DYNAMIC EQUILIBRIUM:
eph = 2TphBglrѠm
Where Bg = flux density in the airgap, r = radius of the airgap,
l = length of the air gap, Ѡm = angular velocity in mech. Rad/sec,
Tph = Number of turns per phase.
Torque Equation:
Te = 4BgrlTphI N-m
Where I = current flowing through the motor.
As the load torque is increased, the speed drops, and the drop is
proportional to the phase resistance and the torque. There are two
boundaries in the torque-speed characteristics- intermittent and continuous
operation. The continuous limit is usually determined by heat transfer and
temperature rise. The intermittent limit may be determined by the maximum
ratings of semiconductor devices in the controller or by the temperature
rise.
2.1.4.7 ADVANTAGES:
The name H-bridge is derived from the actual shape of the switching
circuit which controls the motion of the motor. It is also known as “full
bridge”.
Fig 2.29 Structure of an H-bridge
Pin 1 enables and disables our motor whether it is give HIGH or LOW
Pin 2 is a logic pin for our motor (input is either HIGH or LOW)
Pin 3 is for one of the motor terminals
Pin 4-5 are for ground
Pin 6 is for the other motor terminal
Pin 7 is a logic pin for our motor (input is either HIGH or LOW)
Pin 8 is the power supply for our motor, this should be given the rated
voltage of your motor
Pin 9-11 are unconnected as you are only using one motor in this lab
Pin 12-13 are for ground
Pin 14-15 are unconnected
Pin 16 is connected to 5V
A B DESCRIPTION
0 0 Motor stops or brakes.
0 1 Motor runs anti-clockwise.
1 0 Motor runs clockwise.
1 1 Motor stops or brakes.
For the above truth table, the Enable has to be set (1). Motor power
is mentioned to be 12 Volt. As you can see in the circuit, three pins are
needed for interfacing a DC motor- A, B, Enable. When wanting the o/p to
be enabled completely, connect Enable to VCC and only 2 pins are needed
from the controller to make the motor work. As per the truth table, it’s fairly
simple to program the microcontroller.
Pulse width modulation is all about the switching speed and pulse
width (duty cycle). The duty cycle is defined as percentage of digital ‘high’
to digital ‘low’ plus digital ‘high’ pulse width during a PWM period, i.e.,
the duty cycle is the ratio of signal Ton/T, where T is the period of signal.
Fig 2.34 PWM technique
In the above diagram, there are two signals. First duty cycle is about
t1/T=1/3 and other duty cycle would be about t2/T=2/3. And notice the
period of signals are the same.
If we apply these signals to switching transistor we would get
control over effective voltage across motor:
Veffective = (tON/T)*Vcc;
Where tON- signal on time over one period T.
2.1.4.15 PRODUCTION OF PWM SIGNALS:
Here is a simplified view of timer when they are used for PWM
technique:
The clock:
This is either the speed of any external crystal you have used or
the internal clock speed of your microcontroller. Obviously there is only
one clock speed per microcontroller.
The pre-scalar:
The purpose of the pre-scalar is to divide
the clock frequency by a given value so as to slow down the counting
process in the timer. This slow-down factor is always a power of 2 and is
typically either1, 8, 32, 64, 128, 256 or 1024.
Here is the formula to work out how often the counter is
incremented: every pre-scalar / clock seconds.
The other benefit of the pre-scalar is to help us to
minimize the code changes, which we need to, make if we programmed the
fuse-bits to change the clock speed of the controller from 1MHz to 8MHz.
The comparator:
The comparator value that is used to change the duty
cycle of the PWM is just a register variable.
PWM Out:
This is the pin on the microcontroller that is changed
between high and low and will be fixed for a specific controller/package.
For example: on the ATMega8 the 2 channels on Timer1 are output on
OC1A and OC1B (which are pins 15 and 16 on a 28 pin DIP package - also
known as PB1, PB2), and the 1 channel from Timer2 is output on OC2
(which is pin 17 on a 28 pin DIP package - also known as PB3).
Thus these PWM signals are applied to the enable pin of the
L293D motor driver. The duty cycle of square wave output from
microcontroller is varied to provide a varying DC output. Suppose to run a
motor by half of its rated speed, we have to send 50% duty cycle square
wave at the enable pin effectively, and hence we will get 50% on time, but
due to high frequency and inertia, motor will seem to run continuously.
Fig 2.36 Sending PWM signals to L293D
AVCC –
AVCC is the supply voltage pin for the A/D Converter, Port C
(3 to 0), and ADC (7 to 6). It should be externally connected to V CC, even if
the ADC is not used. If the ADC is used, it should be connected to V CC
through a low-pass filter. Note that Port C (5 to 4) use digital supply voltage,
VCC.
AREF – AREF is the analog reference pin for the A/D Converter.
ADC7 to 6 (TQFP and QFN/MLF Package Only) –
In the TQFP and QFN/MLF package, ADC7 to 6 serve as
analog inputs to the A/D converter. These pins are powered from the analog
supply and serve as 10-bit ADC channels.
ARCHITECTURE:
7805 voltage
Power supply regulator
Distance
sensor Buzzer
LCD display
4. PROGRAMMING:
4.1 FLOWCHART:
START
IF READ
VALUE≥80 No DISTANCE
Yes
A
CALL DELAY
STOP
A
Yes
IF PRINT “VEHICLE IS
DISTANCE TOO CLOSE”
≤20
No
CALCULATE THE DISTANCE PWM OUTPUT
Yes
IF STOP
DISTANCE
≥60 PRINT
“HAVE A SAFE RIDE”
No
D
IF DISTANCE
≤60
STOP
4.2 C PROGRAMMING:
#include <LiquidCrystal.h>
int map1(int x, int in_min, int in_max, int out_min, int out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
int distancemeasure()
{
i=analogRead(dispin);
j=i*0.0048828125;
di=65*pow(j,-1.10);
if(di>56)
return 1;//on function
else if(di<25)
return 0;//off function
else if(di<56 || di>25)
{
y=map1(di,0,56,20,255); //plot vaule
return y;
}
}
void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2; // calculate the delay value
between transitions
//// 1 second's worth of microseconds, divided by the frequency,
then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length/ 1000; // calculate the number
of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the
number of seconds to
//// get the total number of cycles to produce
for (long i=0; i < numCycles; i++){ // for the calculated length of time...
digitalWrite(targetPin,HIGH); // write the buzzer pin high to push
out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin,LOW); // write the buzzer pin low to pull
back the diaphram
delayMicroseconds(delayValue); // wait againf or the calculated delay
value
}
}
void beep(int a)
{
for(;a>0;a--)
{
buzz(buz,2500,500);
delay(1000);
}
}
void alcolevel()
{
alval = analogRead(alpin);
Serial.print("alcohol level");
lcd.print("Alcohol level :");
lcd.setCursor(0,1);
int b=alval/80;
lcd.print("[");
for(;b>0;b--)
lcd.print("#");
lcd.setCursor(12,1);
lcd.print("]");
}
void setup()
{
lcd.begin(16, 2);
Serial.begin (9600);
pinMode (alpin,INPUT);
pinMode (buz,OUTPUT);
pinMode(led,OUTPUT);
Serial.println("Welcome");
lcd.print("Welcome");
delay(10*d);
lcd.clear();
Serial.println("Blow air");
lcd.print("Blow air");
beep(2);
delay(10*d);
lcd.clear();
alcolevel();
delay (2*d);
void loop()
{
x=distancemeasure();
Serial.println(x);
if(x==1)
{ lcd.clear();
lcd.print("Have a safe ride");
digitalWrite(mot1,HIGH);
}
else if(x==0)
{
lcd.clear();
lcd.print("Vechile too close");
lcd.setCursor(1,0);
lcd.print("Engine OFF");
digitalWrite(mot1,LOW);
beep(7);
}
else
{ lcd.clear();
lcd.print("Vechile Ahead");
lcd.setCursor(1,0);
lcd.print("Distance:");
lcd.print(di);
analogWrite(mot1,x);
beep(3);
}
delay(2500);
}