2014
Application of Distance Sensor
in Parking Car
Phạm Duy Khanh
Đinh Tiến Đạt
Lê Thanh Tùng
CTT Cơ Điện Tử K55
Distance Sensor in Parking Car
Table of Contents
A. Abstract .................................................................................................................... 2
B. Introduction and Overview ...................................................................................... 3
C. Approach .................................................................................................................. 4
I.
Structure of our system......................................................................................... 4
II. Hardware .............................................................................................................. 4
1. Distance sensor ................................................................................................. 4
2. Microcontroller ............................................................................................... 10
3. Display device ................................................................................................. 11
4. Actuator and Status devices... ......................................................................... 12
III.
Software .......................................................................................................... 13
1. Programer and complier software. ..................................................................... 13
2. Simulation platform. ....................................................................................... 15
Figure 8: Some types of lcd panel ................................................................................ 11
Figure 9: LCD text 16x2 ............................................................................................... 12
Figure 10: DC Motor .................................................................................................... 13
Figure 11: AVR Studio 6 .............................................................................................. 14
Figure 12: User Interface of AVR Studio 6.................................................................. 14
Figure 13: Proteus 7.8 ................................................................................................... 15
Figure 14: User Interface of Proteus 7.8 ...................................................................... 15
Figure 15: Altium Designer 14 ..................................................................................... 15
Figure 16: PCB Design of Product ............................................................................... 16
Figure 17: IC LM7805 .................................................................................................. 16
Figure 18: Schematic of Power Block .......................................................................... 17
Figure 19: Block Diagram of Main Block .................................................................... 17
Figure 20: Schematic of Main Block............................................................................ 18
Figure 21: Real Product ................................................................................................ 19
Figure 22: IC LM298 .................................................................................................... 20
Figure 23: Schematic of L298 Module ......................................................................... 21
Figure 24: Real of L298 Module .................................................................................. 21
Figure 25: Flow Chart of Main Program ...................................................................... 22
Figure 26: Timing Diagram of HC SR04 ..................................................................... 23
Figure 27: Flow Chart of Get Width Pulse on HC SR04 ............................................. 24
Figure 28: Flow Chart of LCD in 4bit mode ................................................................ 26
Figure 29: PWM Waveform ......................................................................................... 30
Figure 30: A Simlifed H Bridge ................................................................................... 30
Figure 31: Timing Diagram of fast PWM on Timer 2 in Atmega8 ............................. 31
Page | 2
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Page | 3
HaNoi University of Science and Technology
Distance Sensor in Parking Car
C. Approach of Product
I. Structure of System
In our system, we have monitor to display infomation of status and distances recieved
from distances sensor. If the car is in dangerours regions, the red light is turned on and
the buzzer is notified and speed of motor also reduced to zero to the car not cross to
object.
Figure 1: Structure of System
II. Hardware
1. Distance sensor
a. Introduce types of distance sensor.
Measuring the level, position, distance and displacement of physical objects is
essential for many applications: process feedback control, performance evaluation,
transport, traffic control, robotics, security systems, to name just a few.
In our problem, we need a sensor that can mearsure extractly distances from source
(car) to unknown body (unknown about shape, material, movement,etc).
Hence, we will consider 3 types of distance sensors: optical sensor, microwave sensor
and ultrasonic sensor.
Optical Distance Sensor:
A light wave is transmitted by the sensor, reflected by the measuring object and
received by the detector. The simplest way to calculate distances with optical sensors
is based on the determination of the elapsed time interval between emission and
reception of a pulse (signal burst) or series of pulses.
The pulses containing a definite number of periodic waves propagate with sound
1
http://www.pololu.com/product/1137
Page | 5
HaNoi University of Science and Technology
Distance Sensor in Parking Car
velocity towards a measured object. The pulses are then reflected from the measured
object and picked up by the receiver (Figure 7.29) with a lag time equal to the
elapsed time between the emission and reception of pulses. The received pulses of
ultrasonic waves are transformed to the electrical signal by means of the
piezoelectric effect. the scanning regime of operation is feasible (e.g. in ultrasonic
tomography).
Doppler effect
The Doppler effect, (discovered by C. Doppler in 1843) is the change in
frequency undergone by radiation (be it mechanical or electromagnetic) when it is
reflected by an object that is moving with respect to the radiation transmitter. If the
reflector moves with velocity v the shift of frequency is approximately given by
relation
where fe is the emitted frequency, fr is the received frequency, and α is the relative
angle between reflector velocity and propagation direction.
Figure 4: Operation of Ultrasonic Sensor
triangular waveform of the frequency modulating signal.
2
http://www.robotshop.com/en/hc-sr04-ultrasonic-range-finder.html
Page | 7
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Figure 6: Operation of Microwave Sensor
Travel time measurement is the original procedure used in radar systems for a
distance measurement.
Typical parameters:
Measurement range: up to km range.
Resolution: 1m
Examples:
Figure 7: HB-100 Microwave Sensor
US $29.30
3
3
www.aliexpress.com/HB100
But it has the same ranging accuracy and longer ranging distance.
More details:
Power supply :5V DC
Quiescent current : 2mA
Page | 9
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Effectual angle: 15 degree
Ranging distance : 2cm - 500 cm
Resolution : 0.3 cm
There are 4 pins out of the module : VCC , Trig, Echo, GND . So it's a very easy
interface for controller to use it ranging. The all process is : pull the Trig pin to high
level for more than 10us impulse , the module start ranging ; finish ranging , If you
find an object in front , Echo pin will be high level , and based on the different
distance, it will take the different duration of high level. So we can calculated the
distance easily :
Distance = ((Duration of high level)(Sonic :340m/s))/2
Finally,look at the back of the module. All of the chip in the module have been
burnish, maybe the author want to prevent the designed from plagiarism. But
ultrasonic ranging module is nearly the same principle,so it's not hard to speculated
that the role of the chip - I'm sure at least one 74series chip on it). It is not a difficult
task to crack it, but it's at so low a price, even cheaper than your copy.
2. Microcontroller
a. Overview of microcontroller.
A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a
single integrated circuit containing a processor core, memory, and
programmable input/output peripherals. Program memory in the form of NOR
3. Display device
A liquid-crystal display (LCD) is a flat panel display, electronic visual display, or video
display that uses the light modulating properties of liquid crystals. Liquid crystals do not emit
light directly.
LCDs are available to display arbitrary images (as in a general-purpose computer display) or
fixed images which can be displayed or hidden, such as preset words, digits, and 7-segment
displays as in a digital clock. They use the same basic technology, except that arbitrary
images are made up of a large number of small pixels, while other displays have larger
elements.
LCDs are used in a wide range of applications including computer monitors, televisions,
instrument panels, aircraft cockpit displays, and signage. They are common in consumer
devices such as video players, gaming devices, clocks, watches, calculators, and telephones,
Figure 8: Some types of lcd panel
Why choose LCD 16x2?
1.Easy to control.
2.Enough space to display the information that user need to know about
module : distance , warning level .
3.Friendly to users .
Page | 11
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Introduce features and characteristic of LCD 16x2.
Figure 9: LCD text 16x2
III.
Software
1. Programer and complier software.
We use AVR Studio v6.2 to write code and complier programs.
Page | 13
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Figure 11: AVR Studio 6
Atmel® Studio 6 is the integrated development platform (IDP) for developing and
debugging Atmel ARM® Cortex®-M and Atmel AVR® microcontroller (MCU)
based applications. The Atmel Studio 6 IDP gives you a seamless and easy-to-use
environment to write, build and debug your applications written in C/C++ or assembly
code.
Atmel Studio 6 is free of charge and is integrated with the Atmel Software Framework
(ASF)—a large library of free source code with 1,600 ARM and AVR project
examples. ASF strengthens the IDP by providing, in the same environment, access to
ready-to-use code that minimizes much of the low-level design required for projects.
Use the IDP for our wide variety of AVR and ARM Cortex-M processor-based
MCUs, including our broadened portfolio of Atmel SAM3 ARM Cortex-M3 and M4
Flash devices.
Figure 12: User Interface of AVR Studio 6
Figure 16: PCB Design of Product
D. Design System
I.
Hardware
1. Power Supply Block (LM7805)
LM7805 is a voltage regulator integrated circuit. It is a member of 78xx series of fixed
linear voltage regulator ICs. The voltage source in a circuit may have fluctuations and
would not give the fixed voltage output. The voltage regulator IC maintains the output
voltage at a constant value. The xx in 78xx indicates the fixed output voltage it is
designed to provide. 7805 provides +5V regulated power supply. Capacitors of suitable
values can be connected at input and output pins depending upon the respective voltage
levels.
Pin Diagram:
Figure 17: IC LM7805
Page | 16
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Pin
No
1
2
3
Distance Sensor in Parking Car
Figure 20: Schematic of Main Block
Page | 18
HaNoi University of Science and Technology
Distance Sensor in Parking Car
c. Real Board
Figure 21: Real Product
Page | 19
HaNoi University of Science and Technology
Distance Sensor in Parking Car
3. Actuator Block
a. Introduce IC Driver LM298
In our product, we want to drive a DC motor by Pulse Width Modulation. There are
many way to solve problem. In our product, we use IC Dirver LM298 to driver our
motor
A very popular and reasonably priced all-in-one H-bridge motor driver is the L298. It
can control two motors, not just one. It can handle 2 amps per motor, though to get the
maximum current be sure to add a heat sink. The L298 has a large cooling flange with
a hole in it, making it easy to attach a homebrew metal heat sink to it.
If there’s a downside to the L298 it’s that it comes in a special “Multiwatt 15”
If no object is detected, the Echo pin will stay high for 38ms and then go low.
b. Calculate length of time the Echo Pin high
After 40kHz sound wave has trig, the Echo Pin is high. If Sensor is received the
reflected sound wave, the Echo Pin will low. We will calculate lenght of time the
Echo in high by using timer 32bit of Atmega8.
Page | 23
HaNoi University of Science and Technology
Distance Sensor in Parking Car
Flow Chart:
Figure 27: Flow Chart of Get Width Pulse on HC SR04
Code:
Page | 24
HaNoi University of Science and Technology