Вы находитесь на странице: 1из 67

ABSTRACT

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

required, so as to avoid accidents.

An Sonar distance sensor is used to take continuous distance reading and

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

of an alcoholic sensor which is suitable for detecting alcoholic concentration in

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

exceeding limits, as programmed in the microcontroller. A motor driver is used for

interfacing microcontroller with motor and a voltage regulator is made use to

supply power to the board.


TABLE OF CONTENT

CHAPTER TITLE PAGE

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:

Fig 1.1 Rear traffic crossing


When we back away from parking lot with a reverse course, it will be
very difficult to see the vehicles that are behind the new car. Radar system,
is activated every time the car is in inverted position, to warn the driver if
there is a car approaching in the rear with the raised icons and irregular
sound. The disadvantages of using radar system are that these detectors
require license from federal communication commission to operate and are
hard to maintain.
1.3.2 INFLATABLE SEAT BELTS:
When the sensors detect the impact of accident, the air sacs in the belt
which is filled with cold gas is compressed, it will expand and protect
passengers from impact due to collisions.
This was introduced by Ford Explorer in the year 2010. These belts
can be efficient only when they are used along with airbags and padded
interior.

1.3.3 AIR BAG SAFETY SYSTEM:


Fig 1.2 Working diagram of airbag safety system
Air bags were designed primarily to provide protection in frontal
crashes. The life-saving benefits of the air bags derive almost entirely from
purely frontal crashes; their benefit in partially frontal crashes, if any, is
quite limited; and the fatality reduction in all types of crashes is slightly
more than one-third of the reduction in purely frontal crashes. Inadvertent
airbag deployment while the vehicle is being serviced can result in severe
injury, and an improperly installed or defective airbag unit may not operate
or perform as intended. Airbags can injure or kill vehicle occupants. Injuries
such as abrasion of the skin, hearing damage from the extremely loud 165-
175 dB deployment explosion, head injuries, eye damage, and broken nose,
fingers, hands or arms can occur as the airbag deploys.
1.3.4 ENHANCED HEADS-UP DISPLAY:
This technology combines the use of a combination of navigation,
night vision, and lasers to illuminate the road if the road could not be seen
clearly (fog). Infrared camera is used in a vehicle to identify where the end
of the road, and the laser will "display images" on the windshield of the
driver. This system can also identify animals or pedestrians that are not
visible to the naked eye. It can even highlight the speed limit signs. This is
just a mere indication. Drivers have to be conscious about the indications
throughout their drive.
1.3.5 WRONG WAY DRIVER:
This technology was developed by BMW. This technology serves to
commemorate the driver who went into the wrong lane, through car
navigation systems.
This technology is to send a warning sound or image if it is on
the wrong track. If the driver stays in the wrong lane, the navigation system
will display a warning and a map indicating the wrong lane. This system is
also a mere warning and when the driver is unresponsive, it will result in an
accident.
1.3.6 DROWSINESS DETECTOR:
Drowsiness may occur if the driver is traveling far. Mercedes
Benz but has developed a technology reminders on the series E-Class cars
in the year 2010. This technology is able to monitor 70 different parameters
to detect fatigue. If drowsiness is detected, a coffee cup icon and the words
"time to rest" appears on the dashboard panel accompanied by the sound of
car alarms to commemorate the driver so as not to fall asleep while driving.
Reduction of accidents due to this system is recorded to be one third of the
total rate.
1.3.7 VIBRATING CAR SEAT:

Fig 1.3 Vibrating car seat


A new vibrating car seat could prevent accidents by using the sense of
touch to alert drivers to cars in the car’s blind spot, and other hard-to-see
spots around the rear of the vehicle. Driver has to be responsive and alert to
the warnings, so as to avoid the accidents.
1.4INTRODUCTION TO EMBEDDED SYSTEM:
An embedded system is a dedicated computer based system for an
application product; it addresses the issues of the response time constraints
of various tasks of the system. It is one of the systems that have computer
hardware with software embedded in it as one of its most important
components.
1.4.1 WHAT IS AN EMBEDDED SYSTEM?
Definition:
1. It is a digital system.
2. It uses a microprocessor (usually).
3. It runs software for some or all of its function.
4. It is frequently used as a controller.
1.4.2 WHAT AN EMBEDDED SYSTEM IS NOT?
1. It is not a computer system that is used primarily for processing.
2. It is generally not a PC-centered software system.
3. It is not a traditional business or scientific application.
1.4.3 WHY ‘EMBEDDED’?
1. The processor is ‘inside’ some other system.
2. A microprocessor/microcontroller is ‘embedded’ into a TV, car, or
any appliance.
3. Considered as ‘a part of’ the thing rather than the thing.
1.4.4 CHARACTERISTICS:
1. Embedded systems are designed to do some specific tasks, rather
than be general purpose computer for multiple tasks.
2. Embedded systems are not always standalone devices. For example,
an embedded system in an automobile provides specific function as a
subsystem for the car itself.
3. The program instructions written for embedded systems are referred
to as firmware, and are stored in read-only memory or flash chip
memory chips.
4. Special characteristics include hardware and software (in one
system), sensors (for inputs), synchronization, timing (often real
time), concurrency (several processes working at the same time).
1.4.5 DIFFERENCES BETWEEN EMBEDDED SYSTEMS AND
TRADITIONAL SOFTWARES:
1. Responding to sensors is good in embedded systems.
2. Embedded systems can operate real-time applications.
3. Routine can stop at completion or in response to an external event.
4. Embedded system does not deal only with sequential code.
5. Many parts of the system might be running concurrently.
6. Safety-critical component of many systems.
1.4.6 WHY MICROCONTROLLERS IN EMBEDDED SYSTEMS?
Just as a microprocessor is the most essential part of a computing
system, a microcontroller is the most essential component of a control or
communication circuit. A microcontroller is a single-chip VLSI unit
(also called as ‘microcomputer’) that, though having limited
computational capabilities, possesses enhanced input-output capabilities
and a number of on-chip functional units. Microcontrollers in general,
can be considered as the extended versions of the microprocessors.
Microcontrollers are particularly suited for use in embedded systems for
real-time control applications with on-chip program memory and
devices.
2. THEORY AND EXPERIMENTAL SETUP:
This chapter deals with all the components that we use in our project
and their corresponding interfacing details.
2.1 COMPONENTS USED:
1. Alcohol sensor
2. Distance sensor
3. Liquid Crystal Display
4. DC Motor control using an H-bridge
5. Microcontroller
6. Power supply
2.1.1 ALCOHOL SENSOR – MQ3:
This is a gas sensor named MQ-3, which is suitable for detecting
ethanol concentration in the air. It is one of the straightforward gas sensors
and hence, works almost the same way as other gas sensors, just like
common breathalyzer.
Fig 2.1 MQ3 gas sensor
2.1.1.1 FEATURES:
 High sensitivity to alcohol and small sensitivity to Benzene.
 Fast response and High sensitivity.
 Stable and long life.
 Simple drive circuit.
 Provides analog resistive output.
2.1.1.2 SPECIFICATIONS :
 Target Gas - Alcohol
 Detection Range - 0.05mg/L—10mg/L PPM (part per millions)
 Output Voltage Range - 0 to 5 V (DC)
 Working Voltage - 5 V (DC)
 Current Consumption - ≤180 mA
 Warm-up Time - 10 Minutes
 Calibrated Gas - 0.4 mg/L Alcohol
 Response Time - ≤10s Seconds
 Resume Time - ≤30s Seconds
 Standard Working Condition Temperature :- 10 to 65 deg C
Humidity :- ≤95%RH
 Storage Condition Temperature : - 20-70 deg C
Humidity :- ≤ 70%RH
2.1.1.3 USAGE AND TESTING CONDITIONS:

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 :

Typical Sensitivity Characteristics of sensor for several gases:


 Temp: 20 deg C
 Humidity: 65%
 Oxygen concentration: 21%
 RL = 10K Ohm
 Ro = Sensor resistance at 0.4mg/L of
 Alcohol in clean air
 Rs = Sensor resistance at various concentrations of gases.
2.1.1.5 CONSTRUCTION:

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.

Fig 2.2 Pin diagram


Looking at the inside of the sensor, we can find the little tube. Basically, this
tube is a heating system that is made of aluminum oxide and tin dioxide and in it
there are heater coils, which practically produce the heat.

Fig 2.3 Cross-sectional view of gas sensor


The core system is cube. In cross-sectional view, it has an Alumina tube
covered by SnO2, which is tin dioxide. And between them there is an Aurum
electrode, the black one. The alumina tube and the coils are the heating system-
the yellow, brown parts and the coils.

Fig 2.4 Heating system of the MQ3 sensor


2.1.1.6 WORKING:
If the coil is heated up, SnO2 ceramics will become the semi - conductor, so
there are more movable electrons, which means that it is ready to make more
current flow. Then, when the alcohol molecules in the air meet the electrode that is
between alumina and tin dioxide, ethanol burns into acetic acid then more current
is produced. So more the alcohol molecules, more the current we will get. Because
of this current change, we get the different values from the sensor.
STEP 1

Fig 2.5 Heating of coil


STEP 2

Fig 2.6 SnO2 becomes semi-conductor


STEP 3

Fig 2.7 Acetic acid formation


2.1.1.7 INTERFACING OF ALCOHOL SENSOR:

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.

Fig 2.9 Schematic representation of connection-1


Pin A is connected between the power and the pin H and the pin B goes to
the microcontroller. Pin B (any of them) you connect to Ground. And the A pin
(also any of them) you connect to the 100KΩ potentiometer. In the same pin where
you are connecting the pin A, you need to connect a wire to the Analog/Digital
Converter, which is where you are going to read the Alcohol information.
Fig 2.10 Schematic representation of connection-2

2.1.1.8 SPECIFICATIONS:
A. STANDARD WORKING CONDITION:
Table 2.1 Standard conditions

SYMBOL PARAMETER TECHNICAL REMARKS


NAME CONDITION
Vc Circuit voltage 5V±0.1 AC OR DC
V Heating voltage 5V±0.1 AC OR DC
R Load resistance 200 kilo ohms DC
R Heater 33O±5% Room
resistance temperature
P Heating Less than Room
consumption 750mw temperature
B. ENVIRONMENTAL CONDITION:
Table 2.2 Environmental conditions

SYMBOL PARAMETER TECHNICAL


NAME CONDITION
Tao Using temperature -10 to 50

Tas Storage -20 to 70


temperature

R Related humidity Less than 95% Rh

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

Anti explosion network Stain less steel gauze


Clamp ring Copper plating Ni
Tube pin Copper plating Ni
Resin base Bakelite

2.1.2 DISTANCE SENSOR:


=>SHARP SENSOR - GP2Y0A02YK SERIES:

It is an infra-red detector. These detectors boast a small package, very little


current consumption, and a variety of output option. It is a wide angle sensor.
Fig 2.11 Sharp IR distance sensor

2.1.2.1 FEATURES :

Fig 2.12 Block diagram


• Analog output
• Detection Accuracy @ 80 cm: ±10 cm
• Range: 20 to 150 cm
• Typical response time: 39 ms
• Typical start up delay: 44 ms
• Average Current Consumption: 33 mA
2.1.2.2 THEORY OF OPERATION :

Fig 2.13 Minimum and maximum ranges

• A pulse of IR light is emitted by the emitter.


• This light travels out in the field of view and either hits an object or just
keeps on going.
• In the case of no object, the light is never reflected and the reading shows no
object.
• If the light reflects off an object, it returns to the detector and creates a
triangle between the point of reflection, the emitter, and the detector.

Fig 2.14 Operation of IR trans-receiver sensor


It is CCD-chip in the sharp IR sensor that tells where the light hits the
sensor, and by this, it calculates the distance by triangulating. This is then
processed in the DSP chip in the sharp sensor, and it returns a voltage depending
up on what it discovered. The sensor takes 48ms to calculate this value. Also the
sensor won’t be able to read under 20cm, because the angle becomes so steep, that
the returning light won’t even reach the CCD sensor.
Fig 2.15 Triangle formation
The angle of the triangles varies based on the distance to the object. The
angle is x degrees whereas the object is y distance away. The receiver portion of
these new detectors is actually a precision lens that transmits the reflected light
onto various portions of the enclosed linear CCD array based on the angle of the
triangle described above. The CCD array can then determine what angle the
reflected light came back at and therefore, it can calculate the distance to the
object. This new method of ranging is almost immune to interference from ambient
light and offers amazing indifference to the color of object being detected.
Detecting a black wall in full sunlight is now possible.

2.1.2.3 DISTANCE CALCULATION:

Here we use single approximation function to covert output voltage of the


sensor into range values (inches or centimeters). There are some simple
calculations that can linearize the response of the sharp sensor.

THE LINEARIZING FUNCTION:

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

2.1.2.4 INTERFACING OF DISTANCE SENSOR:

PIN DETAILS:

Fig 2.17 Pin out Diagram


 Vo -Voltage Output
 GND -Ground

 Vcc -Supply Voltage

INTERFACING:

To connect the sensor, connect Pin 2 to GND and Pin 3 to +5V Vcc
supply.

Also you need to connect a wire from Pin 1, Vo to Analog/Digital


Converter, which is where you are going to read the Distance information.

2.1.2.5 SPECIFICATIONS:

Fig 2.18 Timing Diagram

Table 2.4 Electrical specifications of sharp IR sensor


PARAMETERS SYMBOLS RATING

Operating supply voltage Vcc 4.5V to 5.5V

Operating supply current Icc 33 to 50 mA

Output terminal voltage Vo -0.3V to 5.3V

Detection range ΔL 20cm to


150cm

Typical response time 39ms

Typical start up delay time 44ms

Output type Analog

2.1.3 LIQUID CRYSTAL DISPLAY:

A liquid crystal display (LCD) is a thin, flat display device made up


of any number of color or monochrome pixels arrayed in front of a light
source or reflector. Each pixel consists of a column of liquid crystal
molecules suspended between two transparent electrodes, and two
polarizing filters, the axes of polarity of which are perpendicular to each
other. Without the liquid crystals between them, light passing through
one would be blocked by the other. The liquid crystal twists the
polarization of light entering one filter to allow it to pass through the other.

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

Second line C0 C1 C2 C3 C4 C5 C6 through CF


Fig 2.19 Address locations for a 2x16 line LCD
2.1.3.1 SIGNALS TO THE LCD:
The LCD also requires 3 control lines from the microcontroller:
1) ENABLE (E):
This line allows access to the display through R/W and RS lines.
When this line is low, the LCD is disabled and ignores signals from R/W
and RS. When (E) line is high, the LCD checks the state of the two control
lines and responds accordingly.

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

Fig 2.20 Pin diagram of 2x16 line LCD


Fig 2.21 Pin description of 2x16 line LCD

2.1.4 DC MOTOR CONTROL USING AN H-BRIDGE:


2.1.4.1 INTRODUCTION TO DC MOTOR:

The electric motor is a simple device in principle. It converts electrical


energy into mechanical energy. DC motors are widely used because of their
small size and high energy output. They are excellent for powering drive
wheels and other mechanical assemblies. In our project, we are using a 12
volt DC brushless motor.
Fig 2.22 12V DC brushless motor

2.1.4.2 GENERAL CONSTRUCTION OF DC MOTOR:

A typical DC motor usually consists of the following:

1. An armature core
2. An air gap

3. Poles

4. A yoke

5. An armature winding

6. A field winding

7. Brushes, brush supports

8. Commutator

9. Frame, end bells, bearings

10.A shaft
Fig 2.23 Brushless DC motor schematic diagram

The important function of the commutator and brushes arrangement in


a conventional DC machine is to set up an armature mmf whose axis is
always in quadrature with the main field irrespective of the speed of the
rotation. When the functions of commutator and brushes are implemented by
solid state switches, maintenance free motor can be realized. These motors
are known as brushless D.C motors.

Fig 2.24 Disassembled view of brushless DC motor

The permanent magnet brushless DC motor is the third stage


evolution of conventional DC motor. The main difference in construction of
this motor from conventional DC motor is that rotor accommodates the
permanent magnet and the stator is made up of silicon steel stamping with
slots in its interior surface. These slots are accommodated in open
distributed armature winding. Here the permanent magnet rotates and the
armature remains static. In order to do this, the brush system/commutator
assembly is replaced by an electronic controller.

Fig 2.25 Electronic commutator

2.1.4.3 PRINCIPLE OF OPERATION OF BRUSHLESS DC MOTOR:

The brushless permanent magnet DC motor is a synchronous electric


motor which is powered by DC supply and it has an electronically controlled
commutation system, instead of a mechanical commutation system based on
brushes. In these motors, the current and torque, voltage and rpm are linearly
related.

The principle of operation of the brushless DC motor can be


analyzed by considering the starting and dynamic equilibrium conditions,
which helps to understand the electromechanical power transfer in this
motor.
 STARTING:

When the DC supply is given to the motor, the armature


winding draws a current and this turns on the device. This current sets up an
mmf, perpendicular to the main mmf set up by the permanent magnet.
According to Fleming’s left hand rule, a force is experienced by the armature
conductors. As it is in stator, a reactive force develops a torque in the rotor.
When this torque is more than the load torque and frictional torque, the
motor starts rotating. It is a self starting motor.

Fig 2.26 Principle of PMBL DC motor-equivalent


circuit

 DYNAMIC EQUILIBRIUM:

As the motor picks up speed, there exists a relative velocity


between the stationary armature conductors & the rotating rotor. According
to Faraday’s law of electromagnetic induction, an emf is dynamically
induced in the armature conductors. As per Lenz’s law, this emf opposes the
armature current. As the supply voltage is maintained constant, current
drawn is reduced, reducing the developed torque.
When the developed torque is exactly equal to the opposing
load torque, the rotor attains a steady state speed, hence attaining a steady
state condition.

 ELECTRO MECHANICAL POWER TRANSFER:

When the load torque is increased, the speed tends to fall.


Therefore it reduces back emf in the armature. Then the current drawn from
the mains increases, and hence more torque develops. The motor attains the
new equilibrium condition, when the developed torque is equal to the new
load torque.

Now the power drawn from the supply (V x I) equals the


mechanical power developed (Pm = 2πNT/60 = ѠT) and the power loss in
the machine and in the switching circuitry. Vice-versa takes place when the
load torque is reduced.

Thus the electrical to mechanical power transfer takes place.

2.1.4.4 EMF AND TORQUE EQUATIONS:


 Emf Equation:

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.

2.1.4.5 TORQUE-SPEED CHARACTERISTICS:

Fig 2.27 Torque-speed characteristics

The ideal torque-speed characteristics of BLPM DC motor can be


obtained, if the commutation is perfect, the phase current waveforms are
ideal and if the converter is supplied from an ideal direct voltage source V.

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.6 RATINGS AND SPECIFICATIONS:

 Operating Voltage – 12 volt DC


 Operating current – 100 mA
 Output power – 30 watts

2.1.4.7 ADVANTAGES:

i. Due to absence of brushes, it requires no maintenance.

ii. High reliability and higher efficiency.

iii. Low inertia and friction, hence faster acceleration.

iv. Cooling is much better, as armature winding is on stator.

v. Low radio frequency interference and noise.

2.1.4.8 MOTOR DRIVER L293D:

Fig 2.28 L293D motor drive

To interface DC motor with the microcontroller, usually the most


preferred way is the use of H-bridge. The most preferably used H-bridge is
the L293D motor drive. This H-bridge is used to drive the DC motor.

2.1.4.9 WORKING THEORY OF H-BRIDGE:

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

An H-bridge is build with 4 switches (solid state or mechanical).


When the switches S1 and S4 are closed and S2 and S3 are open, a positive
voltage will be applied across the motor. By opening S1 and S4 switches
and closing S2 and S3 switches, this voltage is reversed, allowing reverse
operation of the motor. Hence, the switches S1 and S2 should never be
closed at the same time, as this would cause a short circuit on the input
voltage source. The same applies to the switches S3 and S4. This condition
is known as shoot-through.
The H-bridge arrangement is generally used to reverse the polarity
of the motor, but can also be used to 'brake' the motor, where the motor
comes to a sudden stop, as the motor's terminals are shorted, or to let the
motor 'free run' to a stop, as the motor is effectively disconnected from the
circuit. The following table summarizes the operation:
Table 2.5 Motor operation
S1 S2 S3 S4 RESULT
1 0 0 1 Motor moves right
0 1 1 0 Motor moves left
0 0 0 0 Motor free runs
0 1 0 1 Motor brakes
1 0 1 0 Motor brakes

2.1.4.10 PIN DIAGRAM OF MOTOR DRIVER:


Fig 2.30 Pin connections of L239D

 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

All the four I/Os can be used to connect up to four DC motors.


L293D has output current of 600mA and peak output current of 1.2A per
channel. Moreover for protection of circuit from back emf, output diodes
are included within the IC. The output supply has a wide range from 4.5V
to 36V, which has made L293D a best choice for D.C motor driver.

Fig 2.31 Block Diagram of L293D

2.1.4.11 INTERFACING A DC MOTOR USING L293D:

A simple schematic for interfacing a DC motor using L293D is


shown below:
Fig 2.32 Schematic diagram for interfacing DC motor with
L293D
Table 2.6 Truth Table

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.

2.1.4.12 INTERFACE L293D WITH AVR:

Connections of the motor to ATmega8 are shown as follows:


Fig 2.33 Interface L293D with AVR

2.1.4.13 MOTOR SPEED CONTROL:

In general there are two ways to control DC motor speed: by varying


supply voltage, and pulse width modulation technique. First system is not
convenient especially in digital systems. It requires analog circuitry and so
on. Second system is very convenient for digital systems, because all
controls is made using digital signals.

2.1.4.14 MOTOR SPEED CONTROL USING PWM:

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:

In this way, speed control of the DC motor is possible. The


PWM signals are produced by the microcontroller itself. An advantage of
using the microcontroller to generate the PWM signal for us is that once it
has been set up correctly the PWM signal will continue to be generated for
us automatically in the background. We don't need to write any complicated
interrupt routine or other timing code. The beauty is that by simply
changing the comparator value we can alter the duty cycle of the PWM
until such time as we decide to modify it again.
The AVR microcontrollers use the various timers for producing
PWM. The ATMega8 has 3 PWM channels. All of the PWM facilities are
provided by the internal Timers of the AVR. Each timer may, or may not,
support PWM. Assuming that PWM is supported: then the other differences
are:-
 The modes of operation available
 The maximum number of bits of accuracy that are supported
 Pre-scalar values

Here is a simplified view of timer when they are used for PWM
technique:

Fig 2.35 Simplified timer diagram

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

What actually happens by applying a PWM pulse is that the


motor is switched ON and OFF at a given frequency. In this way, the motor
reacts to the time average of the power supply.

Fig 2.37 Motor speed control using PWM


2.1.5 MICROCONTROLLER:

The microcontroller we use here is one among the AVR series-


ATmega8. The ATmega8is an electronic integrated circuit microcontroller
produced by the Atmel Corporation. It has the basic Atmel AVR instruction
set.

Fig 2.38 Block diagram of ATmega8


2.1.5.1 PIN DESCRIPTION AND ARCHITECTURE:
PIN CONNECTIONS:

Fig 2.39 Pin diagram

VCC - Digital supply voltage.


GND - Ground.
Port B (PB7 to PB0) XTAL1/XTAL2/TOSC1/TOSC2 –
Port B is an 8-bit bi-directional I/O port with internal pull-up
resistors (selected for each bit). The Port B output buffers have symmetrical
drive characteristics with both high sink and source capability. As inputs, Port
B pins that are externally pulled low will source current if the pull-up resistors
are activated. The Port B pins are tri-stated when a reset condition becomes
active, even if the clock is not running. Depending on the clock selection fuse
settings, PB6 can be used as input to the inverting Oscillator amplifier and
input to the internal clock operating circuit. Depending on the clock selection
fuse settings, PB7 can be used as output from the inverting Oscillator
amplifier. If the Internal Calibrated RC Oscillator is used as chip clock source,
PB7 to 6 is used as TOSC2 to 1 input for the Asynchronous Timer/Counter2 if
the AS2 bit in ASSR is set.
Port C (PC5 to PC0) –
Port C is a 7-bit bi-directional I/O port with internal pull-up
resistors (selected for each bit). The Port C output buffers have symmetrical
drive characteristics with both high sink and source capability. As inputs, Port
C pins that are externally pulled low will source current if the pull-up resistors
are activated. The Port C pins are tri-stated when a reset condition becomes
active, even if the clock is not running.
PC6/RESET –
If the RSTDISBL Fuse is programmed, PC6 is used as an I/O
pin. Note that the electrical characteristics of PC6 differ from those of the
other pins of Port C. If the RSTDISBL Fuse is un-programmed, PC6 is used
as a Reset input. A low level on this pin for longer than the minimum pulse
length will generate a Reset, even if the clock is not running. Shorter pulses
are not guaranteed to generate a Reset.
Port D (PD7 to PD0) –
Port D is an 8-bit bi-directional I/O port with internal pull-up
resistors (selected for each bit). The Port D output buffers have symmetrical
drive characteristics with both high sink and source capability. As inputs, Port
D pins that are externally pulled low will source current if the pull-up resistors
are activated. The Port D pins are tri-stated when a reset condition becomes
active, even if the clock is not running.
RESET –
Reset input. A low level on this pin for longer than the
minimum pulse length will generate a reset, even if the clock is not running.
Shorter pulses are not guaranteed to generate a reset.

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:

Fig 2.40 Architecture of ATmega8


In order to maximize performance and parallelism, the AVR
uses Harvard architecture – with separate memories and buses for program
and data. Instructions in the Program memory are executed with a single level
pipelining. While one instruction is being executed, the next instruction is pre-
fetched from the Program memory. This concept enables instructions to be
executed in every clock cycle. The Program memory is In-System
Reprogrammable Flash memory.
The fast-access Register File contains 32 x 8-bit general
purpose working registers with a single clock cycle access time. This allows
single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU
operation, two operands are output from the Register File, the operation is
executed, and the result is stored back in the Register File – in one clock
cycle.
Six of the 32 registers can be used as three 16-bit indirect
addresses register pointers for Data Space addressing – enabling efficient
address calculations. One of the address pointers can also be used as an
address pointer for look up tables in Flash Program memory.
The ALU supports arithmetic and logic operations between
registers or between a constant and a register. Single register operations can
also be executed in the ALU. After an arithmetic operation, the Status Register
is updated to reflect information about the result of the operation.
The Program flow is provided by conditional and unconditional
jump and call instructions, able to directly address the whole address space.
Most AVR instructions have a single 16-bit word format. Every Program
memory address contains a 16- or 32-bit instruction.
Program Flash memory space is divided in two sections, the
Boot program section and the Application program section. Both sections
have dedicated Lock Bits for write and read/write protection. The SPM
instruction that writes into the Application Flash memory section must reside
in the Boot program section.
During interrupts and subroutine calls, the return address
Program Counter (PC) is stored on the Stack. The Stack is effectively
allocated in the general data SRAM, and consequently the Stack size is only
limited by the total SRAM size and the usage of the SRAM. All user programs
must initialize the SP in the reset routine (before subroutines or interrupts are
executed). The Stack Pointer SP is read/write accessible in the I/O space. The
data SRAM can easily be accessed through the five different addressing
modes supported in the AVR architecture.
The memory spaces in the AVR architecture are all linear and
regular memory maps.
A flexible interrupt module has its control registers in the I/O
space with an additional global interrupt enable bit in the Status Register. All
interrupts have a separate Interrupt Vector in the Interrupt Vector table. The
interrupts have priority in accordance with their Interrupt Vector position. The
lower the Interrupt Vector address, the higher the priority.
The I/O memory space contains 64 addresses for CPU
peripheral functions as Control Registers, SPI, and other I/O functions. The
I/O Memory can be accessed directly, or as the Data Space locations
following those of the Register File, 0x20 - 0x5F.

2.1.5.2 ANALOG TO DIGITAL COVERTER IN ATMEGA8:


The ATmega8 features a 10-bit successive approximation ADC.
The ADC is connected to an 8- channel Analog Multiplexer which allows
eight single-ended voltage inputs constructed from the pins of Port C. The
single-ended voltage inputs refer to 0V (GND).
FIG 2.41 A/D block schematic operation

The ADC contains a Sample and Hold circuit which ensures


that the input voltage to the ADC is held at a constant level during conversion.
The ADC has a separate analog supply voltage pin, AVCC. AVCC must not
differ more than ± 0.3V from VCC.
Internal reference voltages of nominally 2.56V or AVCC are
provided On-chip. The voltage reference may be externally decoupled at the
AREF pin by a capacitor for better noise performance. The ADC converts an
analog input voltage to a 10-bit digital value through successive
approximation. The minimum value represents GND and the maximum value
represents the voltage on the AREF pin minus 1 LSB. Optionally, AVCC or an
internal 2.56V reference voltage may be connected to the AREF pin by
writing to the REFSn bits in the ADMUX Register. The internal voltage
reference may thus be decoupled by an external capacitor at the AREF pin to
improve noise immunity.
The analog input channel is selected by writing to the MUX bits
in ADMUX. Any of the ADC input pins, as well as GND and a fixed band gap
voltage reference, can be selected as single ended inputs to the ADC. The
ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltage
reference and input channel selections will not go into effect until ADEN is
set. The ADC does not consume power when ADEN is cleared, so it is
recommended to switch off the ADC before entering power saving sleep
modes.
The ADC generates a 10-bit result which is presented in the
ADC Data Registers, ADCH and ADCL. By default, the result is presented
right adjusted, but can optionally be presented left adjusted by setting the
ADLAR bit in ADMUX. If the result is left adjusted and no more than 8-bit
precision is required, it is sufficient to read ADCH. Otherwise, ADCL must be
read first, then ADCH, to ensure that the content of the Data Registers belongs
to the same conversion. Once ADCL is read, ADC access to Data Registers is
blocked. This means that if ADCL has been read, and a conversion completes
before ADCH is read, neither register is updated and the result from the
conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL
Registers is re-enabled.
The ADC has its own interrupt which can be triggered when a
conversion completes. When ADC access to the Data Registers is prohibited
between reading of ADCH and ADCL, the interrupt will trigger even if the
result is lost.
2.1.5.3 FEATURES OF ATMEGA8:
 High-performance, Low-power AVR® 8-bit Microcontroller
 Advanced RISC Architecture
– 130 Powerful Instructions – Most Single-clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-chip 2-cycle Multiplier
 High Endurance Non-volatile Memory segments
– 8K Bytes of In-System Self-programmable Flash program memory
– 512 Bytes EEPROM
– 1K Byte Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits
 In-System Programming by On-chip Boot Program
 True Read-While-Write Operation
– Programming Lock for Software Security
 Peripheral Features
– Two 8-bit Timer/Counters with Separate Pre-scalar, one Compare
Mode
– One 16-bit Timer/Counter with Separate Pre-scalar, Compare Mode,
and Capture
 Mode
– Real Time Counter with Separate Oscillator
– Three PWM Channels
– 8-channel ADC in TQFP and QFN/MLF package
 Eight Channels 10-bit Accuracy
– 6-channel ADC in PDIP package
 Six Channels 10-bit Accuracy
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
 Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-
down, and
 Standby
 I/O and Packages
– 23 Programmable I/O Lines
– 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
 Operating Voltages
– 2.7 - 5.5V (ATmega8L)
– 4.5 - 5.5V (ATmega8)
 Speed Grades
– 0 - 8 MHz (ATmega8L)
– 0 - 16 MHz (ATmega8)
 Power Consumption at 4 Mhz, 3V, 25°C
– Active: 3.6 mA
– Idle Mode: 1.0 mA
– Power-down Mode: 0.5 μA

2.1.6 POWER SUPPLY:


In this power supply circuit we have to create a +5V DC which
is given to the micro controller. The below components are used to create the
power supply:

230V Step down Bridge Filter Voltage


AC transformer rectifier Regulator
supply Fig
2.42 Block diagram of power supply
230V AC supply is given to the step down transformer. It may
be a 230V to 9V/12V step down transformer. The output of the step down
transformer is given to bridge rectifier. The bridge rectifier is formed with
1N4007 diodes. The bridge rectifier converts the AC Voltage into DC Voltage.
But the output DC Voltage contains some AC component (ripples). So we
have to use a capacitor-2200uF/25V as a filter for removing ripples. That
output DC Voltage is given to the positive voltage regulator 7805. The output
will be the regulated +5V DC.
Instead of having such a long process we use adapter instead
and its output DC voltage is given to the voltage regulator 7805.

2.1.6.1 VOLTAGE REGULATOR 7805:

It is a three terminal positive voltage regulator. It is used to


provide regulated power supply to the board. It looks like a transistor but it is
actually an integrated circuit with 3 legs. It can take a higher, crappy DC
voltage and turn it into a nice, smooth 5 volts DC. It has to be fed with at least
8 volts and not more than 30 volts. It can handle around .5 to .75 amps, but it
gets hot, and hence a heat sink can be used. It is efficient to use in power
circuits that needs or runs off at 5 volts.

Fig 2.43 KIA7805AP/API Voltage regulator

Each type employs internal current limiting, thermal shut down


and safe operating area protection, making it essentially indestructible. If
adequate heat sinking is provided, they can deliver over 1A output current.
Although designed primarily as fixed voltage regulators, these devices can be
used with external components to obtain adjustable voltages and currents.

2.1.6.2 FEATURES OF VOLTAGE REGULATOR 7805:


 Suitable for C-MOS, TTL and other digital IC’s power supply.
 Internal thermal overload protection.
 Internal short circuit current limiting.
 Output current in excess of 1A.
 Output Transistor Safe Operating Area Protection.
 Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24.
2.1.6.3 PIN DIAGRAM AND CONNECTION TO BREAD BOARD:

Fig 2.44 Pin diagram

Fig 2.45 Schematic connection to breadboard

Sometimes the input line may be noisy. To help smoothen out


the noise and to get better 5 volt output, capacitors is usually added to the
circuit.
3. METHODOLOGY:
3.1 INTRODUCTION:

7805 voltage
Power supply regulator

Alcohol Motor Motor


sensor driver
AT mega8
Microcontroller

Distance
sensor Buzzer

LCD display

Fig 3.1 Block diagram of the project

In this project, microcontroller is used as controller to control


the DC motor speed to the desirable level when it exceeds limits, and also
controls the movement of the vehicle when the alcohol concentration in
breathe is high. For the DC motor control, H-bridge motor drive (L293D) is
used.

Two sensors are used in this project viz., - Alcohol sensor


(MQ3 gas sensor) and Distance sensor (Sharp IR distance sensor).

Most digital logic circuits and controllers require +5V DC


power supply. To make +5V DC power supply, we use LM7805 voltage
regulator IC.

3.2 IMPLEMENTATION OF THE PROJECT:

Fig 3.2 Picture of the project

3.2.1 ALCOHOL SENSOR IMPLEMENTATION:

Alcohol sensor is suitable for detecting ethanol concentration in


the air, just like a breathalyzer. In this sensor, the sensing element is tin
dioxide (SnO2), which has low conductivity in clean air. In the presence of
ethanol in the air, the sensor’s conductivity increases depending upon the gas
concentration in the air. In the process, ethanol contained in the person’s
breath is oxidized. The ethanol becomes acetic acid in the oxidation/reduction
reaction, and hence more current is produced corresponding to the alcohol
concentration.

The SnO2 conducting material is enclosed along with a heating


unit. The MQ-3 has 6 input/output pins. Four pins transmit signals while the
remaining two provide current for the heating element. The heater is necessary
as it maintains proper temperature conditions for the sensing material to
behave as intended. Thus, a solenoid circuit is formed within the electric
circuit of the sensor. In this circuit, the emf varies leading to creation of
potential difference depending upon the alcohol concentration. This potential
difference is the actual reading. It is then compared with the programmed
standard reading given to the controller.
• If actual reading > standard = 300ml, DC motor does not start and LCD
indicates not safe to drive, via microcontroller program.

• If actual reading < standard = 300ml, DC motor is capable of starting, LCD


indicates can drive safely, via microcontroller program.

3.2.2 DISTANCE SENSOR IMPLEMENTATION:

For measuring the distance between two vehicles, we make use


of the Sharp IR distance sensor. This sensor has a trans-receiver system. A
pulse of IR is emitted by the transmitter. This light travels out in the direction
of the field of view. In case of no object, the light is never reflected. In case of
the presence of an object, the light hits the object and gets reflected back.
Hence a triangle is formed between the transmitter, point of reflection, and
receiver.

By using simple approximation function, the analog output


voltage of the sensor is converted into range (inches or centimeters). This
calculated range is compared with the standard range given to the controller.
When the calculated range is less than the standard range, the microcontroller
is programmed so as to control the speed of the DC motor, which drives the
vehicle.

This is done by using the PWM technique. The actual speed


will be measured and is given to the microcontroller. In it, it is programmed to
calculate the error between the actual range and the standard range. The error
is given as DC supply voltage to the microcontroller. This voltage determines
the duty cycle of the PWM signals in the microcontroller. These signals are
enabled to the motor drive (L293D), which in turn controls the speed of the
DC motor. When the calculated range is less than the standard limit, the motor
drive decelerates the DC motor.

• When calculated distance range > standard range, DC motor continues to


run at the constant speed.
• When calculated distance range < standard range, the speed of the DC
motor decelerates, LCD indicates the presence of object, via
microcontroller program.
3.3.3 SOFTWARE IMPLEMENTATION:
The microcontroller is programmed in such a way that, it limits
the speed of the DC motor, when the distance measured between two vehicles
are smaller than the standard value programmed to it. Also it is programmed
to inhibit the starting of the DC motor, when the alcohol concentration in the
person’s breath is higher than the standard range programmed to it. It is also
programmed to display the distance measured, the presence of an object, and
presence of alcohol in the LCD display unit. The programming of
microcontroller is done using the C language.

3.3 COMPLETE CIRCUIT DIAGRAM OF THE PROJECT:


Fig 3.3 Complete circuit connection diagram

4. PROGRAMMING:
4.1 FLOWCHART:

START

INITIALIZING THE LCD MODULE


READ ANALOG OUTPUT FROM ALCOHOL
INITIALIZING
PRINTPRINT”
PRINT
“THE BLOW
INITIALIZING
C THEAIR”
THE INPUT
OUTPUT
“WELCOME”
CALL
ALCOHOL
DELAY
SENSOR VALUE”
C
B

IF READ
VALUE≥80 No DISTANCE

Yes
A

PRINT “YOU ARE DRUNK”

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 PWM OUTPUT HIGH

D
IF DISTANCE
≤60

SEND PWM ANALOG SIGNAL

PRINT “THE VEHICLE DISTANCE”

STOP

4.2 C PROGRAMMING:

#include <LiquidCrystal.h>

#define RS 3 // the lcd's Registry Select PIN


#define E 4 // the lcd's Enable Pin
#define D4 5 // D4 Pin
#define D5 6 // D5 Pin
#define D6 7 // D6 Pin
#define D7 8 // D7 Pin
LiquidCrystal lcd(RS,E,D4,D5,D6,D7);
int led=13; //
int buz=12;//buzzer
unsigned char alpin = 0;//alchol sensor
int dispin=1;//distance sensor
int mot1=9;//motor
unsigned int alval = 0;
float j,i,di;
int x,y;
int sensorValue; // Value for sensor output
int d=250;

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);
}

5. CONCLUSION AND REAL-TIME IMPLEMENTATION:


5.1 CONCLUSION:
In recent years, focus has been shifted from prevention to
protection and we are making a continuous progress. Although many
preventive systems, such as radar technology and vibrating car alerts have
been implemented before, they are not efficient as they are hard to maintain.
Our project is easy to implement in real-time vehicles and is cost efficient.
5.2 REAL-TIME IMPLEMEMNTATION:
In real-time vehicles, this preventive technology has to be
implemented during the manufacturing of the vehicle itself. This technology
serves efficiently for lane system. It is a preventive technology and it can be
further advanced to alert the driver about the vehicles in the blind spot and can
guide the driver even during the fog. This advancement is possible due to the
use of IR distance sensor.
Also a breathalyzer can be used here, which is composed of
many MQ3 alcohol sensors. Unless and until the driver takes the alcohol
consumption test, the vehicle could not be ignited. He will be able to drive
only if he passes the alcohol consumption test. i.e., if the actual ethanol
reading in the driver’s breath is greater than 0.8 BAC (blood alcohol content),
it would be indicated in the LCD that he is drunk and the vehicle could not be
started. This could be further advanced, with the advancement in the AI
technology, so as to operate with an auto-drive.
The distance sensor used here is an IR sensor, which is more
advantageous over the other basic sensors. It is almost immune to interference
and noise and offers amazing indifference to the color of object being
detected. Using this it is also possible to differentiate whether the object is a
vehicle or a person. This sensor can be manufactured to the sides and rear side
also. Thus when the vehicle is prone to an accident with another vehicle at any
of the sides, the LCD will indicate the distance measure and the controller is
programmed to control the speed of the vehicle. It could also be programmed,
such that, when the driver goes beyond the over-speed limit of a particular
zone, the vehicle’s speed will be automatically inhibited. The speed limit of
that particular zone can be detected using the IR sensor.
Thus the objective of the project is successfully fulfilled.

Вам также может понравиться