SlideShare une entreprise Scribd logo
1  sur  45
Page | 1
SMART Fuel Theft Detector
Page | 2
An-Najah National University
Electrical Engineering Department
Graduation Project 2
SMART Fuel Theft Detector
Supervisor:
Dr. Samer Mayyalih
Prepared by:
Amjad Rabayaa
Adham Sawafta
December 2013
Page | 3
‫اإلهــــــداء‬
‫هللا‬ ‫بسم‬‫الرحيم‬ ‫الرحمن‬
‫الحمد‬‫يعلمون‬ ‫ال‬ ‫والذين‬ ‫يعلمون‬ ‫الذين‬ ‫يستوي‬ ‫هل‬‫ل‬‫ق‬ .. " ‫التنزيل‬‫محكم‬ ‫في‬ ‫ائل‬‫الق‬ ‫العالمين‬‫رب‬‫هلل‬.. "‫والصالة‬‫األنام‬‫خير‬‫على‬ ‫والسالم‬
‫على‬ ‫العالم‬ُ‫ل‬ْ‫ض‬َ‫وف‬ .. ‫ة‬َّ‫ن‬‫الج‬‫إلى‬ً‫ا‬‫طريق‬ ‫به‬ ‫له‬ ‫هللا‬ ‫سهل‬ ،ً‫ا‬‫علم‬ ‫فيه‬ ‫يلتمس‬ً‫ا‬‫طريق‬ ‫سلك‬ ‫من‬ .."‫ائل‬‫الق‬‫هللا‬ ‫عبد‬ ‫بن‬ ‫محمد‬‫القمر‬‫كفضل‬ ‫العابد‬
‫و‬ ...‫الكواكب‬‫سائر‬ ‫على‬َّ‫أن‬‫منهاجا‬ ‫بذالك‬ ‫سطر‬ُّ‫ي‬‫ل‬ "‫األنبياء‬‫ورثة‬ ‫العلماء‬ً‫ا‬ّ‫رباني‬.‫والتعلم‬ ‫العلم‬‫حب‬‫على‬ً‫ا‬‫ائم‬‫ق‬
‫بعد‬‫التوكل‬‫الوقت‬‫كل‬ ‫منا‬ ‫استنفذ‬‫لطالما‬ ‫الذي‬ ‫المتواضع‬‫اإلنجاز‬ ‫هذا‬ ‫نهدي‬ ,‫هللا‬ ‫يشكر‬ ‫ال‬ ‫الناس‬ ‫اليشكر‬ ‫من‬ ‫باب‬ ‫ومن‬ ,‫هللا‬‫على‬
‫الكري‬‫هللا‬ ‫وجه‬ ‫نحو‬ ‫بذلك‬ ‫ماضين‬ ,‫والمثابرة‬ ‫الجد‬ ‫من‬ ‫طوال‬ ‫سنوات‬ ‫به‬ ‫تتوج‬ ‫إكليال‬ ‫بذلك‬ ‫ليكون‬ ‫والجهد‬‫م‬‫الجد‬‫على‬‫ائمة‬‫ق‬ ‫حياة‬‫نحو‬ ,
.‫والتضحية‬ ‫واإلجتهاد‬
‫إليك‬..‫إلهي‬‫وخالقي‬
‫الذي‬‫بطاعت‬ ‫إال‬ ‫النهار‬ ‫يطيب‬ ‫وال‬ ‫بشكره‬ ‫إال‬ ‫الليل‬‫يطيب‬ ‫ال‬‫ه‬‫إال‬ ‫ة‬ّ‫الجن‬‫تطيب‬ ‫وال‬ ‫بعفوه‬ ‫إال‬ ‫األخرة‬ ‫تطيب‬ ‫وال‬ ‫بذكره‬ ‫إال‬ ‫اللحظات‬ ‫تطيب‬ ‫وال‬
‫برؤيته‬
‫إلى‬..‫دي‬ّ‫سي‬‫وحبيبي‬
‫يامن‬‫اعته‬‫بشف‬ ‫نطمع‬ ‫من‬ ‫يا‬ ‫امه‬‫لمق‬ ‫العروق‬ ‫بين‬ ‫الدم‬‫ويقف‬ ‫لذكره‬ ‫العيون‬ ‫وسط‬ ‫من‬ ‫الدمع‬‫يسيل‬
‫محمد‬‫وسلم‬ ‫عليه‬ ‫هللا‬ ‫صلى‬
‫إلى‬..‫تعالى‬ ‫هللا‬ ‫بعد‬ ‫الوجود‬‫في‬ ‫من‬ ‫كل‬
‫سندي‬ّ‫ا‬‫من‬ ,‫هللا‬ ‫بعد‬ ‫ومالذي‬ ‫وقوتي‬‫ثروني‬‫واألمل‬ ‫اؤل‬‫والتف‬ ‫الصبر‬ ‫ومعنى‬ ‫الحياة‬ ‫معنى‬ ‫وعلموني‬ ‫أنفسهم‬‫على‬
‫والدي‬‫إنتظار‬ ‫بدون‬ ‫العطاء‬‫علمني‬ ‫من‬ .. ‫العزيز‬
‫أمي‬‫اء‬‫الشف‬‫وبلسم‬ ‫الحب‬‫رمز‬ .. ‫الحنون‬
‫إخواني‬‫..الذ‬ ‫وأخواتي‬‫المعين‬‫نعم‬ ‫فكانوا‬ ‫والمؤازرة‬ ‫المساندة‬‫اشكال‬‫بكل‬ ‫امدوني‬ ‫ين‬
‫أهلي‬... ‫بجانبي‬ ‫وقف‬ ‫من‬ ‫وكل‬ ‫بلدي‬ ‫وأهل‬ ‫وعشيرتي‬
‫إلى‬..‫خطوت‬‫نخطوا‬ ‫ونحن‬ ‫ووداعهم‬ ‫شكرهم‬ ‫علينا‬ ‫وجب‬ ‫الذين‬‫نا‬‫يبخل‬ ‫لم‬ ‫الذين‬ ,‫الحياة‬‫غمار‬ ‫في‬ ‫األولى‬‫وا‬‫ووقتهم‬ ‫بعلمهم‬ ‫علينا‬
‫الذين‬‫أينا‬‫ر‬‫األوفياء‬‫وسماحة‬ ‫العلماء‬‫وتواضع‬ ‫األباء‬‫محبة‬ ‫فيهم‬
Page | 4
‫الدكتور‬‫الكهربائية‬ ‫الهندسة‬‫قسم‬ ‫رئيس‬ ‫خماش‬‫ماهر‬
‫الدكتور‬‫بريك‬ ‫عماد‬
‫الدكتور‬‫خير‬‫كل‬ ‫ا‬ّ‫عن‬ ‫هللا‬ ‫اه‬‫ز‬‫ج‬ .. ‫المشروع‬ ‫هذا‬ ‫على‬ ‫افه‬‫ر‬‫بإش‬ ‫تفضل‬ ‫الذي‬‫ميالة‬ ‫سامر‬
‫و‬‫الوطنية‬‫النجاح‬‫جامعة‬‫في‬ ‫الكهربائية‬ ‫الهندسة‬‫أسرة‬‫كل‬
‫إلى‬‫م‬ ‫الذين‬‫والقهر‬ ‫والظلم‬ ‫الغدر‬‫زنازين‬ ‫في‬ .. ‫هناك‬ ‫الوا‬‫ز‬‫ا‬
‫يامن‬‫الشهداء‬‫ألرض‬ ‫فداءا‬ ‫أعماركم‬‫دفع‬ ‫اليتم‬ ‫يامن‬ ‫بصبركم‬ ‫للنصر‬ ‫وحون‬ّ‫ل‬‫وت‬ ‫بصمودكم‬ ‫الحرية‬ ‫تكتبون‬
‫نعم‬‫سالم‬ ‫الف‬ ‫ا‬ّ‫من‬ ‫لكم‬ .. ‫األسرى‬ ‫..أيها‬
‫أما‬‫الوطن‬ ‫امتداد‬‫على‬ ‫النصر‬‫هة‬ّ‫فو‬ ‫ورسمتم‬ ‫اء‬‫البق‬‫حب‬‫فينا‬ ‫زرعتم‬ ‫من‬ ‫يا‬ ..‫أنتم‬
‫نسألكم‬‫منكم‬ ‫لنستلهم‬ ‫األيادي‬ ‫تمدوا‬ ‫أن‬‫ما‬‫جهادكم‬‫ومضات‬ ‫على‬ ‫يحيينا‬
‫سالم‬‫ريعا‬ ‫في‬ ‫األحياء‬‫أيها‬‫ن‬‫الشهادة‬
Page | 5
Contents
ACKNOWLEDGMENT...............................................................................Error! Bookmark not defined.
Table of Figures..................................................................................................................................6
CH 1 SURVEY...................................................................................................................................7
1.1 THE SURVEY ........................................................................................................................7
1.2 RESULTS AND ANALYISIS ......................................................................................................9
CH 2 Introduction..........................................................................................................................11
2.1 PROBLEMTO SOLVE...........................................................................................................11
2.2 ABSTRACT.........................................................................................................................12
2.3 METHODOLOGY.................................................................................................................13
2.4 ENVIRONMENT OF WORK ..................................................................................................14
CH 3 SOLUTION.............................................................................................................................15
3.1 FUEL MEASURMENT...........................................................................................................15
3.1.1 THE FIRST PROPER SENSOR (HC-SR04) .........................................................................15
3.1.2 THE SECONDPROPER SENSOR(LSM303DLH)…………………………………………………………………16
3.1.3 MICROCONTROLLER.................................................................................................187
3.1.3 FILTERING & PROCESSING......................................................................................... 219
3.2 TRANSMISSION OFDATA……………………………………………………………………………………………………….22
3.2.1 GPRS MODULE……………………………………………………………………………………………………………….22
3.2.2 INTERFACING BETWEEN THE GPRS AND THE CONTROLLER ...........................................25
3.2.3 TRANSMISSION USING GPRS MODULE.........................................................................25
3.3 The Whole system .............................................................................................................25
CH 4 CONCLUSION ANDOBSERVATIONS…………………………………………………………………………………………….25
4.1 Experiment on the Sensor..................................................................................................27
4.2 CONCLUSION.....................................................................................................................29
Bibliography.....................................................................................................................................31
APPENDEX A.1: The Code of the PIC16f877a.......................................................................................32
Page | 6
Table of Figures
Figures1.2-1 The surveyresults………………………………………………………………………………………………………………7
Figure 3.1-1 Ultrasonic principle ........................................................................................................13
Figure 3.1-2 The HC-SR04 ultrasonic sensor........................................................................................14
Figure 3.1-3 The Principle of Work Ultrasonic Sensor...........................................................................17
Figure 3.1-4 Timing Diagram of the Ultrasonic Sensor.........................................................................17
Figure 3.1-5 The LSM303DLE slope sensor..........................................................................................20
Figure3.1-6 PIC16f877a…………………………...................................................................................................17
Figure 3.1-7 Flow Chartfor the Microcontroller .............................................................................. 2422
Figure 3.2-1 GPRS module.................................................................................................................25
Figure 4.1-1: 12cm distance from a rigid body ....................................................................................27
Figure 4.1-2: 16cm distance from a rigid body ....................................................................................27
Figure 4.1-3: 20cm distance from a rigid body ....................................................................................27
Figure 4.1-4: 24cm distance from a rigid body ....................................................................................27
Figure 4.1-5: Test of the Sensor on Fluids............................................................................................28
Page | 7
CH 1 SURVEY
1.1 THE SURVEY
Afterwe choose ourprojectidea we did a short survey about the projectto ensure thatthe system
isimportantfor the ownersof transport companies, aswell as find out if they have usedotherdevices
to solve the problem and how the success of these devices. In addition to that we want to identifythe
extent of the Palestinian marketneed forthe project and the possibility of marketingit effectively.
Our surveyis shownbelowinArabicaswe distributedit:
‫الى‬ ‫إرسالها‬ ‫و‬ ‫دقيق‬ ‫بشكل‬ ‫التنك‬ ‫داخل‬ ‫الوقود‬ ‫كمية‬ ‫حساب‬ ‫على‬ ‫يعمل‬ ‫جهاز‬ ‫بناء‬ ‫على‬ ‫المشروع‬ ‫فكرة‬ ‫تقوم‬
‫تج‬ ‫مناسبة‬ ‫بطريقة‬ ‫الجهاز‬ ‫وصمم‬ ‫دوري‬ ‫بشكل‬ ‫الشركة‬ ‫مقر‬‫عله‬‫ثم‬ ‫ومن‬ ‫الوقود‬ ‫إستهالك‬ ‫مقدار‬‫تتبع‬ ‫على‬ ‫قادرا‬
‫عن‬ ‫السرقة‬ ‫إكتشاف‬‫السرقة‬ ‫عن‬ ‫تبلغ‬ ‫فورية‬ ‫رسالة‬ ‫بإرسال‬ ‫يقوم‬ ‫حيث‬ ‫حدوثها‬ ‫د‬‫وكمية‬.‫المسروقة‬ ‫الوقود‬
‫ت‬ ‫على‬ ‫العمل‬ ‫فريق‬ ‫تساعد‬ ‫بطريقة‬ ‫وضع‬ ‫التالي‬ ‫اإلستبيان‬‫وقع‬‫وساعات‬ ‫يوميا‬ ‫المسروقة‬ ‫الوقود‬ ‫كميات‬
‫الوسائل‬ ‫جميع‬ ‫اإلعتبار‬ ‫بعين‬ ‫األخذ‬ ‫مع‬ ‫السرقة‬ ‫حالة‬ ‫مع‬ ‫التعامل‬ ‫طريقة‬ ‫من‬‫البيانات‬ ‫هذه‬ ‫تسهل‬ ‫حيث‬ ‫السرقة‬
.‫الوقود‬ ‫سرقة‬ ‫في‬ ‫المتبعة‬
‫ما‬‫دوري‬ ‫بشكل‬ ‫المستهلكة‬ ‫الوقود‬ ‫لكميات‬ ‫الدقيقة‬ ‫المعرفة‬ ‫أهمية‬ ‫هي‬
‫مهم‬‫جدا‬
‫مهم‬
‫محايد‬
‫غير‬‫مهم‬
‫الشعور‬‫ب‬‫الوقود‬ ‫سرقة‬
‫متأكد‬‫السرقة‬ ‫وجود‬ ‫من‬
‫شاك‬‫السرقة‬ ‫بوجود‬
‫ال‬‫لي‬ ‫علم‬
‫متأكد‬‫سرقة‬ ‫وجود‬ ‫عدم‬ ‫من‬
‫في‬‫الوقود‬ ‫سرقة‬ ‫تكون‬ ‫الغالب‬
‫أثناء‬‫المركبة‬ ‫عمل‬
‫خارج‬‫المركبة‬ ‫عمل‬ ‫ساعات‬
‫في‬‫السابقتين‬ ‫الحالتين‬ ‫كلتا‬
‫في‬‫قبل‬ ‫من‬ ‫الوقود‬ ‫سرقة‬ ‫تكون‬ ‫الغالب‬
‫سائق‬‫الشاحنة‬
‫ناس‬ُ‫أ‬‫(أثناء‬ ‫العمل‬ ‫خارج‬ ‫اخرون‬)‫العمل‬ ‫عن‬ ‫المركبة‬ ‫توقف‬
‫ال‬‫أعلم‬
Page | 8
‫بكم‬‫شهريا‬ ‫المسروقة‬ ‫الوقود‬ ‫كمية‬ ‫تقدر‬.................................................................................................
‫هل‬‫الوقود‬ ‫سرقة‬ ‫من‬ ‫يمنع‬ ‫أو‬ ‫عن‬ ‫يكشف‬ ‫جهاز‬ ‫شراء‬ ‫حاولت‬
‫نعم‬
‫ال‬
‫إذا‬‫نعم‬ ‫اإلجابة‬ ‫كانت‬
‫ما‬‫عمل‬ ‫طبيعة‬ ‫هي‬
........................................................‫الجهاز؟‬.....................................
............................................................................................................................................
‫ما‬‫سعر‬ ‫هو‬
............................................................‫الجهاز؟‬.........................................
‫هل‬‫؟‬ ‫المشكلة‬ ‫حل‬ ‫على‬ ‫وقادرا‬ ‫اال‬ّ‫ع‬‫ف‬ ‫الجهاز‬ ‫كان‬
‫نعم‬
‫ال‬
‫إذا‬‫؟‬ ‫برأيك‬ ‫السبب‬ ‫هو‬ ‫فما‬ ‫ال‬ ‫اإلجابة‬ ‫كانت‬
.............................................................................................
............................................................................................................................................
‫هل‬‫؟‬ ‫المشكلة‬ ‫حل‬ ‫لك‬ ‫يكفل‬ ‫جهاز‬ ‫لشراء‬ ‫مستعد‬‫أنت‬
‫نعم‬
‫متردد‬
‫ال‬‫أرغب‬
Page | 9
1.2 RESULTS AND ANALYISIS
Evenour sample wasnotlarge enoughdue to the limitedcompaniesandfoundationswhichare
nearto us, we can say the following:
 The majorityof companiesstatedthatit isveryimportantforthemto identifyexactlytheir
expenses onthe fuel consumption.
 A significantnumberof the sample suffersfromuncertaintyinthe amountof itsfuel
consumption.
 Some of the companiesare sure thatthere issome kindof fuel theftfromtheirvehicles.
 Some of the companieshave alreadybought asystemtofindtrackthe fuel consumptionin
theirvehicles.
 Some of the companiesmentionedthatthe fuel theftisperformedbypersonsnotfromthe
drivers.
To understandthe surveyoutputsee the figuresbellow.
Figures1.2-1 the survey results
Page | 10
As we expected,thisphenomenaispresentandneedtoa reliable andcost-effective solutionwhich
can calculate the fuel consumptionanddetectthe fuel theftif happened.
Page | 11
CH 2 Introduction
2.1 PROBLEM TO SOLVE
Due to the high fuel price, fuel theft became worrying phenomenon and it is very
important for companies and foundations to monitor its fuel consumption rate in order to put
its best budget.
According to the Palestinian distributing fuel stations the cost of one litter of diesel in
excess of 5.7 NIS (as of 12:00 a.m. April 29, 2013), so any storage of fuel can be a target for
theft as well as transportation vans. In our project we provide a smart electrical system to help
our client to deal with this problem and we aim to protect our clients from the fuel theft
especially the transportation vans and vehicles.
Our duty to stop the fuel theft so, before we start the smart fuel level detector idea, we set
some advice for the fuel consumers which can help to a void the fuel theft.
 Consider installing a locking gas cap. Remember that many of the “fuel doors” that open
remotely or with a key are flimsy and easily compromised.
 Avoid parking in dark, isolated areas (especially for extended periods).
 At home, park in a locked garage where possible. If you don’t have a garage, park as
close as possible to the house and avoid parking on the street.
 If you must park on a street or in a parking lot, attempt to locate your vehicle so the fuel
door is visible to you or other residents in your area.
 If you have bulk fuel on your property, ensure you lock the tank and or dispenser to
prevent access.
Our fuel level detector continuously monitors your tank fuel with the ultrasonic fuel
detector, the easiest solution to prevent fuel theft and fraud.
Fuel theft: the moment our system tracks an unusual rate of decrease in the fuel-level (i.e.
in usual conditions, the vehicle consumes a certain amount of fuel; while in the theft case, the
rate of decrease of the fuel will be faster than the usual case) the fuel-tracker will send an
alarm via a GPRS module (may be a SMS) and can be automatically configured to ring an
audible alarm when the fuel theft occurs. The tracker is sensitive enough to detect when
someone tries to 'skim' excess fuel from a vehicles tank.
Page | 12
2.2 ABSTRACT
The level of the fuel, especially in cars and vehicles, is very important since it gives
indication about the remaining amount of fuel in the tank of the vehicle. However, particularly,
for the companies which have number of vehicles it is essential to monitor the fuel level at all
times in order to identify its budget and expenses also to capture the fuel theft.
The level measurement of fuel in the vehicle’s tank is a special case of general level
measuring applications because:
 The flammability of the fuel, so it is very dangerous to put any electrical devices or
wires inside the fuel tank.
 The very accurately closed tank, so it isn’t preferred to make holes other than the
main opening.
 The dynamic motion of the fuel, which means that the measuring process must take
into consideration the road condition such that if the road is flat or has some slope
(either positive or negative).
In our project, we aim to design a smart fuel level measuring system which:
 Measures the amount of fuel in the tank accurately and in real time.
 Has the ability to measure the amount of fuel even if the vehicle is moving on a flat
or has some slope roads.
 Can store the measurements in order to do some extra process such as consumption
rate per day or month … etc.
 Can be configured with a microcontroller to send the measurements via GPRS.
 Capture the fuel theft even if the vehicle is turned off!
Finally, our scope of work will be:
 Specify which kind of sensors will be suitable for our requirements.
 Make some data processing such as Filtering.
 Store the measurements.
 Capable to make data communication (GPRS).
 Display the measurements as graphical representation.
 Alarm in case of fuel theft.
Page | 13
2.3 METHODOLOGY
The methodology will be followed at this project is to:
 Identify the elements of the project and the functionality of each one.
 Identify the circumstances which presents in the environment surrounding the
project.
 Find the best arrangement of the elements of the system in order to achieve the
best performance.
 Find the best and safe way to take the measurements of the fuel.
 Write the best code of the microcontroller to filter and process the sensor’s
measurement.
 Connect the microcontroller to the GPRS module in order to send the measurements
to the site of the company.
Page | 14
2.4 ENVIRONMENT OF WORK
For the work environment there are many criteria that must be taken into consideration. If
we want to put the sensor on the surface of the tank we will be forced to make a suitable slot
to fix the sensor, for this reason it must be very careful because small arc will lead to huge
explosion. In addition of that, the large needed to speed and accurate transmission methods.
So in our project we have taken a lot of things in consideration, for example:
 Chemical properties of the diesel.
 Small dimensions of the sensor.
 The temperature effect on the sensor reading.
 A suitable sensor which works at low voltage.
 Good transmission methods like GPRS and GSM.
All these things and more will make from our system as safe as possible.
Page | 15
CH 3 SOLUTION
3.1 FUEL MEASURMENT
3.1.1 THE FIRST PROPERSENSOR (HC-SR04)
In a large number of ultrasonic distance measurements, the operating principle is
the estimation of time of flight (ToF) Tf. The sensor generates ultrasonic pulses and
these pulses will be reflected to the receiver when it reaches the fuel surface as shown
in figure 3.1-1. So that the distance can be estimated directly by the formula:
V: represents the propagation velocity of the ultrasonic wave in the medium (air).
Figure 3.1-1 Ultrasonic principle
According to the previous equation we see that the distance depends directly on
the propagation velocity of the ultrasonic wave and this quantity depends on the
relative humidity and the temperature, and also on some chemical and physical
parameters of the fluid. More over the time of flight will control the measured
distance.
In the ultrasonic system two kinds of sensing are possible (1) :
 The continuous wave method
 The pulse echo method
In our project there are many things must be considered when we select the
sensor kind, so we saw the advantages and the disadvantages for both kind.
Let us start with the first type which is the continuous wave method. In this
method two separate transmitting and receiving elements are used, so that the level is
Page | 16
evaluated through the estimation of a phase shift. In this case good performance can
be obtained, but a more complex hardware system is necessary.
The pulse echo method, on the other hand, requires only one transducer that
operates alternately in transmitting and receiving method. Also pulse echo method
offers a simple and low cost solution, even it yields poorer results due to uncertainty
in the time delay measurement .These results, in fact, can be improved by using a
cheap software signal processing.
However, our HC-SR04 ultrasonic sensor is included under the continuous wave
method but with some modification which is instead of the output in the form of
phase shift it is here a PWM (pulse width modulation) such that the time of flight is
represented by the width of the echo signal from the ultrasonic.
The HC-SR04 (2) ultrasonic sensor as shown in figure 2.3-1 is small and
meets our requirements so as not to take large space on the tank.
As shown, it has four legs:
 VCC: 5 volt
 GND: zero volt (ground).
 Trig: a 10us 5 volt pulse to start the sensor.
 Echo: the output signal of the sensor.
Figure 3.1-2 The HC-SR04 ultrasonic sensor
Ultrasonic ranging module HC - SR04 provides (2cm - 400cm) non-contact
measurement function, the ranging accuracy can reach to 3mm. The module includes
ultrasonic transmitter, receiver and control circuit.
The basic principle of work, figure 3.1-2 clarifies this principle:
1- Using IO trigger for at least 10us high level signal.
2- The Module automatically sends eight 40 kHz and detect whether there is a
pulse signal back.
3- IF the signal back, through high level , time of high output IO duration is the time
from sending ultrasonic to returning.
4- Test distance = (high level time X velocity of sound (340 m/sec) / 2
Page | 17
Figure 3.1-3 The Principle of Work Ultrasonic Sensor
Timing diagram
Figure 3.1-4 Timing Diagram of the Ultrasonic Sensor
The Timing diagram is shown in figure 2.3-2. We only need to supply a short 10uS
pulse to the trigger input to start the ranging, and then the module will send out an 8
cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object
that is pulse width and the range in proportion .We can calculate the range through
the time interval between sending trigger signal and receiving echo signal.
The formula to calculate the distance is:
uSec / 58 = centimeters
or uSec / 148 =inch
or the range = high level time * velocity (340 m/sec) / 2
It is recommended to use over 60ms measurement cycle, in order to prevent trigger
signal to the echo signal.
Page | 18
3.1.2 THE SECOND PROPERSENSOR(LSM303DLH)
Figure 3.1-5 The LSM303DLH slope sensor
Description:
The LSM303DLH is a system-in-package featuring a 3D digital linear acceleration sensor and a
3D digital magnetic sensor. The various sensing elements are manufactured using specialized
micromachining processes, while the IC interfaces are realized using a CMOS technology that
allows the design of a dedicated circuit which is trimmed to better match the sensing element
characteristics. The LSM303DLH includes an I2C serial bus interface that supports standard
mode (100 kHz) and fast mode (400 kHz).The system can be configured to generate an interrupt
signal by inertial wakeup/free-fall events, as well as by the position of the device itself.
Thresholds and timing of interrupt generators are programmable on the fly by the end user.
Magnetic and accelerometer parts can be enabled or put in power-down mode separately. The
LSM303DLH is available in a plastic land grid array (LGA) package, and is guaranteed to operate
over an extended temperature range from -30 to +85 °C. See the table below. (3)
Sensor Features
 Analog supply voltage: 2.5V to 3.3V.
 Digital supply voltage IOs:1.8V.
 Power-down mode.
 3 magnetic field channels and 3 acceleration channels.
 16 bit data out.
 I2C serial interface.
 2 independent programmable interrupt generators for free-fall and motion
detection.
 Embedded self-test.
Applications
 Compensated compassing.
 Map rotation.
 Position detection.
Page | 19
 Motion-activated function.
 Free-fall detection.
 Display orientation.
 Vibration monitoring and compensation.
In our project, we used this sensor to determine the slope of the road so as to find the actual
fuel level even in the tilted roads this is due to the fact that most of our roads are tilted!
So we have derived an equation which relates the slope of the tank with the distance from the
Ultrasonic sensor to determine the fuel level as accurate as possible. However, the LSM303DLH
sensor communicates through the I2C protocol which is differ from the Ultrasonic which is
connected to the microcontroller directly, so we provide here some description of this protocol.
As for the coding of this sensor, it is attached in the appendix.
I2C serialinterface
I²C (Inter-Integrated Circuit, referred to as I-squared-C, I-two-C, or IIC) is a multimaster serial
single ended computer bus invented by Philips used for attaching low-speed peripherals to a
motherboard, embedded system, cell phone or other electronic device. At the low end of the
spectrum of communication options for "inside the box" communication is I2C .The name I2C is
shorthand for a standard Inter-IC (integrated circuit) bus.
I2C provides good support for communication with various slow, on-board peripheral devices
that are accessed intermittently, while being extremely modest in its hardware resource needs.
It is a simple, low-bandwidth, short-distance protocol. Most available I2C devices operate at
speeds up to 400Kbps, with some venturing up into the low megahertz range. I2C is easy to use
to link multiple devices together since it has a built-in addressing scheme. (4)
3.1.3 MICROCONTROLLER
All kinds of sensors need some device to process its readings and
measurements, so it’s common to find in such systems microcontrollers. The
common microcontrollers are PIC and ARDUINO. In our project we will use
the PIC microcontroller PIC16f877a which is shown in figure 3.1-5.
Page | 20
Figure 3.1-6 PIC16f877a
These microcontrollers can be connected to more than one sensor and
devices such as small DC motors, LCD, computers and GPRS modules. Also
theses microcontrollers can be programmed using high level languages in
order to operate as the designer wants.
The PIC16f877a microcontroller is manufactured by MICROCHIP©
company. The oscillator which will be used is a crystal of 4 MHz frequency,
which allows us to take number of readings from the sensors per minute in
order to get the best and accurate reading in different conditions. The most
important feature of the PIC16f877a for this project is the capture property
which can trigger or start a timer when the rising edge of the echo signal
(from the ultrasonic) reach the microcontroller, then the value of that timer
can be directly treated as the time of flight Tf . However more details will be
mentioned in Appendix A.1.
However, the code of the microcontroller will convert measured distance
by the ultrasonic into a volume reading depending on the shape and
dimensions of the tank.
It is important to mention that each kind of vehicles has its own tank
shape and dimensions, so our system will be adaptive such that for each
vehicle the dimensions of the tank must be taken into consideration in the
programing process of the microcontroller which will be fitted on it.
Page | 21
3.1.4 FILTERING & PROCESSING
After we did the survey we saw that there is a great importance to stop the fuel theft as
well as give accurate readings for the fuel level and in real time. As we said before, the
main function of our system to tracks an unusual rate of decrease in the fuel-level and we
said too the tracker is sensitive enough to detect when someone tries to 'skim' excess fuel
from a vehicles tank. After we stared the project we saw that there are two main
limitations to give an accurate reading in real time. Actually the two limitations are the
same but in different position and each one required special method to solve. The two
limitation leads to dynamic motion of the fuel. And because of the fuel inside the tank will
be dynamic, so it is important to take number of readings from the ultrasonic and then
make the filtering to it. We will perform the filtering process through the microcontroller
such that we will do averaging to these readings and take its average. Then we will
compare this reading of the fuel level with another reading after a specific time (this time
is determined from the vehicle itself according to its usual consumption rate of fuel) then
if the difference is greater than the usual consumption rate of fuel then a warning signal
will be sent to the GPRS module which in turn will send it to the appropriate address to
alarm for fuel theft. By the way, figure 2.1-4 shows a flow chart for our programed
microcontroller.
In this part we would like to explain the two limitations and what are the methods
which we used to solve these two limitations.
 The first problem occurs when the vehicle is moving on a flat road but this
road has large Protrusions. See the figures bellow
Page | 22
To solve this problem it is important to take number of readings from the ultrasonic sensor
and then make the filtering to it. We will perform the filtering process through the
microcontroller such that we will do averaging to these readings and take its average.
To solve this problem we did a simple averaging for the values because the normal
decreasing of the fuel level is small and so no needed to make a complicated filtering. See
the below equation
Simple filtration equation
 The second limitation occurs when the vehicle is moving on a road has some
slope (positive or negative) slope. See the figure bellow.
Actually we sit some alternatives to solve this problem for example
 The first method is to considerate the consumption rate only by reading the fuel level at
specific time and then we will compare this reading of the fuel level with another reading
after a specific time to calculate the consumption rate according the below equation. If the
consumption rate is greater than the usual consumption rate of the vehicle, the
microcontroller will send an alarm signal to the database on the company. In this way we
can detect the fuel theft which the main function of our project. But the same time we lose
an important thing which is know the fuel level in real time and so we will face some error
in the fuel consumption.
 The second method depends on both the fuel level and the consumption rate at the same
time, and here we ignore the first reading (the reading which make a large variation). In
this method we set a three probability.
1) Large change in both fuel level and consumption rate.
In this case we ensure that there is a fuel theft or some problem in the fuel tank, so the
microcontroller will send an alarm signal to the database on the company.
2) Large change in the fuel level and usual change in the consumption rate.
In this case we ensure that the vehicle is moving on a road has some slope (positive or
negative slope. And here the microcontroller will send an approximate fuel level
which equals the previous fuel level (from the microcontroller memory) minus the
consumption rate. In this method we give approximation readings, which is good
Page | 23
comparing with the other alternatives on the market. But at the same time we faced a
big problem in our country “Palestine” because a high percentage of the roads have a
large slope, and so this method become un valuable in some cases.
3) Small change on the fuel level and large change on the consumption rate.
In this case no probabilities and we ensure that there is a fuel theft from the fuel tank
and so, the microcontroller will send an alarm signal to the database on the company.
 The last method is depending on the same principle of the second method, but here with
more accurate approximation.
In this method we make an experiment to compare between the measured level and the
slope of the fuel level to calculate the accurate “actual” level depending on the bellow
equation.
Where:
D: the actual distance between the ultrasonic sensor and the fuel level
D`: the measured distance between the ultrasonic sensor and the fuel level
:the road slope (the measured angle by LSM303DLH sensor)
However, we can configure and program the microcontroller to periodically send its
reading to the GPRS module in order to allow the company to monitor and save the
consumption of the fuel by its vehicle.
Page | 24
Figure 3.1-7 Flow Chart for the Microcontroller
3.2 TRANSMISSION OF DATA
3.2.1 GPRS MODULE
It is a device used to send data through the wireless communication networks; it
needs a SIM card related to the cellular network which provides this service.
Fortunately, the local cellular network provides this service with cheap cost. All what we
need is to provide each module with a SIM card and connect it to the microcontroller to
enable the GPRS module to send the measurements. By the way, the size of GPRS
modules is small as shown in figure 3.2-1 which is very suitable for our project.
Doesthe falling
edge arrived
from the echo
Measure the echo time from
the interrupt (rising edge)
Increment counter
YESNO
Return from interrupt
Delay (1 mSec) to
allow the echo to
interrupt
Divide the echo time by 58
to get the distance in cm
Convert from binary to
decimal
Send the reading
to the GPRS
START
Enable Capture mode of the
microcontroller
Trigger The Sensor (Pulse
for 10uS)
Measure the echo time from
the interrupt (rising edge)
Page | 25
Figure 3.2-1 GPRS module
3.2.2 INTERFACING BETWEENTHE GPRS AND THE CONTROLLER
PIC-GSM is excellent board for adding remote monitoring and control in remote
places by GSM cellular network or Ethernet or internet network. (5)
The GSM antenna is built in the board so no need for external expensive GSM
antennas. PIC-GSM have two inputs which could be connected to alarm sensors or just
buttons for user actions (like call pre-loaded phone numbers), on-board temperature
sensor up to 30 meter distance from the module. So we can connect the microcontroller
easily to it in order to achieve the communication between them.
3.2.3 TRANSMISSIONUSING GPRS MODULE
The readings of the sensor will be sent through the GPRS module to a web server in
order to store, process and display the fuel rate consumption for each vehicle to allow
the company to benefit as best as possible to identify its budget.
3.3 The Whole system
As an overall sight on our system, based on the circumstances mentioned in section 1.4, we
have designed our system such that:
 The ultrasonic HC-SR04 will be fitted on the surface of the tank with small hole
(45X20 mm2) with insolating layer to isolate the connections from the fuel inside the
tank, this hole is required to let the ultrasonic waves propagates inside the tank to
measure the level of the fuel.
 The four pins of the Ultrasonic HC-SR04 will be connected to the microcontroller.
 The microcontroller and the GPRS module will be fitted inside the cabin of the
vehicle in order to facilitate the maintenance if required.
Page | 26
Finally, the needed power for the system will be fed from the battery of the vehicle and
since those component of the system is a very low power elements there will be no worry
about the consumed power from the battery of the vehicle.
Page | 27
CH 4 CONCLUSION ANDOBSERVATIONS
4.1 Experiment on the Sensor
At this part, we have tested the performance of the sensor in measuring the distances from
different objects.
As figures 4.1-1 to 4.1-4 show, the measured distance is displayed on an LCD with the object
is a rigid black body, from those pictures we can see that this sensor is very accurate with taking
into consideration that the object which we intend to measure its distance must be 2cm away
from the sensor as shown in the figures.
Figure 4.1-1: 12cm distance from a rigid body Figure 4.1-2: 16cm distance from a rigid body
Figure 4.1-3: 20cm distance from a rigid body Figure 4.1-4: 24cm distance from a rigid body
2cm
2cm12cm
20 cm 24 cm
16 cm
Page | 28
Also to ensure that the ultrasonic waves of this sensor don’t penetrate the surface of the
fuel we have performed this part to measure the distance between the sensor and the surface
of the water inside a container of water as shown in figure 4.1-5.
Figure 4.1-5: Test of the Sensor on Fluids
As drawnon the picture,the distance measuredbythe sensorisexactlythe distancebetweenthe
surface of the waterand the sensoras provedfromthe rulerinthe picture.
AS a result,we are nowsure that thissensorwill be able tomeasure exactlythe level of the fuel
inside the tankandthe ultrasonicwaveswon’tpenetrate the fuel.Finally,the remainingthingistodo
the filteringandgetthe propermeasurementwhenthe vehicleisinmotionona tiltedroad.
2c
m
5
cm
Heightof water
inside the container
Ultrasonic
Sensor
12 cm
17 cm
Page | 29
4.2 CONCLUSION
As a result of the high cost of the fuel, it is very essential for the companies – which have its
own transportation vehicles and vans- to identify and calculate its consumption and expenses
on the fuel so as to put their efficient and reliable budget.
Also, as we found from the survey, most of the local companies mentioned that it’s very
important for them to know as exact as possible their fuel consumption and expenses.
Moreover, we found there is a critical need for those companies to protect their vehicles from
the fuel theft whoever the thief.
From the need of our market in Palestine, we took the first step in our project and then
started to combine the main features of our system in order to meet the needs of those
companies and foundations. Our duty is to design a ‘smart’ system to mainly detect the fuel
theft in various conditions and secondly allow those companies and foundations to know
exactly their expenses on the fuel.
In the first part of our graduation project, we have studied the circumstances surrounding
the environment of the system and then identified the best and reliable components which will
be assembled and built in the next part of the graduation project in the next semester. The
main part is the sensor responsible to take the level of the fuel inside the tank and we have
chosen the Ultrasonic HC-SR04 sensor for that role, then we have selected the PIC16f877a
microcontroller to filter and process the Ultrasonic readings, finally we have preferred the
GPRS module to transmit the readings to the server of the company in order to store and
handle those readings as they want.
In the second part of our graduation project, we have built the system, combined the
sensors, added new elements like the LSM303DLH, derived mathematical equation to relate the
slope of the road with the fuel level, sent the readings to the microcontroller then through the
serial port to the computer.
One of the problems we faced was the lack and the high cost of the GPRS modules in our
market, as a result, we couldn’t perform the transmission using it, instead we have sent the
data using the serial port of the computer to a database to simulate the real database of the
target company.
Finally, based on our study in the electrical engineering department at an-Najah University,
we hope to design a valuable and useful system so as to contribute to solving one of the
Page | 30
problems which our companies face regarding the fuel theft and consumption, which – to some
extent- will help them to do their best in achieving their jobs as better as possible.
Page | 31
Bibliography
1. Digital signalprocessing techniquesforaccurateultrasonic. GregorioAndria,FilippoAttivissimo,
NicolaGiaquinto.2001, www.elsevier.com.
2. Freaks, ELEC. UltrasonicRanging ModuleHC - SR04.
3. www.sparkfun.com
4. www.robot-electronics.co.uk
5.Ltd, OLIMEX. www.olimex.com. olimex. [Online] june 2008.
https://www.olimex.com/Products/PIC/Development/PIC-GSM/.
6. MICROCHIP. PIC16F87X Data Sheet.2001.
7. LSM303DLM Sensormodule:3-axisaccelerometerand 3-axismagnetomete.www.st.com
8. STAR. WH1602D LCD datasheet.
Page | 32
APPENDEX A.1: The Code of the PIC16f877a
We have written the code in the second part of the project using the PICC language as
follows:
The ultrasonic code:
#include <ultraTest.h>
#include <LCD.C>
#include <math.h>
#use fast_io(B)
int32 echo,timer1; // distancein binary
float height,area,volume;
#int_CCP1
void CCP1_isr(void)
{
set_timer1(0);
clear_interrupt(INT_CCP1);
}
#int_CCP2
void CCP2_isr(void)
{
echo =ccp_2;
clear_interrupt(INT_CCP2);
}
void trig() // triger thesensor by 10usec pulseon the triger pin RB#
Page | 33
{
output_low(PIN_C3);
delay_us(3);
output_high(PIN_C3);
delay_us(10);
output_low(PIN_C3);
}
display()
{
//printf(LCD_PUTC,"fD=%gcmnV=%gL",height,volume);
printf(LCD_PUTC,"f%gcm",height);
printf("%g",height);
//printf(LCD_PUTC,"fecho=%Luntimer1=%Lu",echo,timer1);
}
void divide() // convert timeto distanceaccording to thedata sheet oftheultrasonicsensor
{
if(echo) height =echo/58.0; // distanceis measuredin cmaccording to
// the ultrasonic sensor RS323
volume =area*height*0.001; // volume(liter) ofthe fuel provided thatthearea ofthetank is known;
}
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //65.5 ms overflow
setup_ccp1(CCP_CAPTURE_RE);
setup_ccp2(CCP_CAPTURE_FE);
lcd_init();
Page | 34
enable_interrupts(INT_CCP1);
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);
//Example blinking LED program
while(true){
trig();
delay_ms(1);
divide();
display();
// delay_ms(1500);
}
}
The LSM303DLM code:
#include "D:adhami2c_testtest.h"
#include <LCD.C>
#include <LSM303DLH.h>
int data;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
Page | 35
setup_timer_2(T2_DISABLED,0,1);
lcd_init();
// TODO: USER CODE!!
enableDefault();
while(1){
readAcc();
printf("n%X",X_H_A);
delay_ms(1000);
};
}
#ifndef LSM303DLH_h
#define LSM303DLH_h
float m_max_x, m_max_y, m_max_z;
float m_min_x, m_min_y, m_min_z;
int X_L_A, X_H_A, Y_L_A, Y_H_A, Z_L_A, Z_H_A;
int X_L_M, X_H_M, Y_L_M, Y_H_M, Z_L_M, Z_H_M;
// address ofacceleometerand magnetometer
#define sad_w_a 0x30 //b'00110000'
#define sad_r_a 0x31 //b'00110001'
#define sad_w_m 0x3C//b'00111100'
#define sad_r_m 0x3D//b'00111101'
#define ACC_ADDRESS (0x30 >>1)
#define MAG_ADDRESS (0x3C >>1)
// register addresses
#define LSM303DLH_CTRL_REG1_A 0x20
Page | 36
#define LSM303DLH_CTRL_REG2_A 0x21
#define LSM303DLH_CTRL_REG3_A 0x22
#define LSM303DLH_CTRL_REG4_A 0x23
#define LSM303DLH_CTRL_REG5_A 0x24
#define LSM303DLH_HP_FILTER_RESET_A0x25
#define LSM303DLH_REFERENCE_A 0x26
#define LSM303DLH_STATUS_REG_A 0x27
#define LSM303DLH_OUT_X_L_A 0x28
#define LSM303DLH_OUT_X_H_A 0x29
#define LSM303DLH_OUT_Y_L_A 0x2A
#define LSM303DLH_OUT_Y_H_A 0x2B
#define LSM303DLH_OUT_Z_L_A 0x2C
#define LSM303DLH_OUT_Z_H_A 0x2D
#define LSM303DLH_INT1_CFG_A 0x30
#define LSM303DLH_INT1_SRC_A 0x31
#define LSM303DLH_INT1_THS_A 0x32
#define LSM303DLH_INT1_DURATION_A 0x33
#define LSM303DLH_INT2_CFG_A 0x34
#define LSM303DLH_INT2_SRC_A 0x35
#define LSM303DLH_INT2_THS_A 0x36
#define LSM303DLH_INT2_DURATION_A 0x37
#define LSM303DLH_CRA_REG_M 0x00
#define LSM303DLH_CRB_REG_M 0x01
#define LSM303DLH_MR_REG_M 0x02
#define LSM303DLH_OUT_X_H_M 0x03
#define LSM303DLH_OUT_X_L_M 0x04
Page | 37
#define LSM303DLH_OUT_Y_H_M 0x05
#define LSM303DLH_OUT_Y_L_M 0x06
#define LSM303DLH_OUT_Z_H_M 0x07
#define LSM303DLH_OUT_Z_L_M 0x08
#define LSM303DLH_SR_REG_M 0x09
#define LSM303DLH_IRA_REG_M 0x0A
#define LSM303DLH_IRB_REG_M 0x0B
#define LSM303DLH_IRC_REG_M 0x0C
void LSM303DLH()
{
// These arejustsomevalues for a particular unit; it is recommendedthat
// a calibration bedone for your particular unit.
m_max_x =+540; m_max_y =+500; m_max_z =180;
m_min_x =-520; m_min_y = -570; m_min_z = -770;
}
// Writes an accelerometer register
void writeAccReg(bytesub, byte data){
i2c_start();
i2c_write(sad_w_a);
i2c_write(sub);
i2c_write(data);
i2c_stop();
}
// Reads accelerometer register
int readAccReg(byte sub){
byte data;
Page | 38
i2c_start();
i2c_write(sad_w_a);
i2c_write(sub);
i2c_start();
i2c_write(sad_r_a);
data =i2c_read();
i2c_stop();
return data;
}
// Writes a magnetometer register
void writeMagReg(byte sub, byte data)
{
i2c_start();
i2c_write(sad_w_m);
i2c_write(sub);
i2c_write(data);
i2c_stop();
}
// Reads a magnetometer register
byte readMagReg(bytesub)
{
byte data;
i2c_start();
i2c_write(sad_w_m);
i2c_write(sub);
i2c_start();
i2c_write(sad_r_m);
Page | 39
data =i2c_read();
i2c_stop();
return data;
}
void enableDefault()
{
// Enable Accelerometer
// 0x27 =0b00100111
// Normal power mode, allaxes enabled
writeAccReg(LSM303DLH_CTRL_REG1_A, 0x27);
// Enable Magnetometer
// 0x00 =0b00000000
// Continuous conversionmode
writeMagReg(LSM303DLH_MR_REG_M, 0x00);
}
// Reads the 3accelerometer channels andstores them invector a
void readAcc()
{
X_L_A= readAccReg(LSM303DLH_OUT_X_L_A);
X_H_A =readAccReg(LSM303DLH_OUT_X_H_A);
Y_L_A = readAccReg(LSM303DLH_OUT_Y_L_A);
Y_H_A = readAccReg(LSM303DLH_OUT_Y_H_A);
Z_H_A = readAccReg(LSM303DLH_OUT_Z_L_A);
Z_H_A = readAccReg(LSM303DLH_OUT_Z_H_A);
/* i2c_start();
i2c_write(sad_w_a);
Page | 40
i2c_write(LSM303DLH_OUT_X_L_A);
i2c_start();
i2c_write(sad_r_a);
data =i2c_read();
i2c_stop();
Wire.beginTransmission(ACC_ADDRESS);
// assert theMSB oftheaddress to gettheaccelerometer
// to do slave-transmit subaddress updating.
Wire.send(LSM303DLH_OUT_X_L_A| (1 <<7));
Wire.endTransmission();
Wire.requestFrom(ACC_ADDRESS, 6);
while (Wire.available() <6);
uint8_t xla =Wire.receive();
uint8_t xha =Wire.receive();
uint8_t yla =Wire.receive();
uint8_t yha =Wire.receive();
uint8_t zla =Wire.receive();
uint8_t zha =Wire.receive();
a.x =(xha <<8 | xla) >>4;
a.y =(yha <<8 | yla) >>4;
a.z =(zha << 8 | zla) >> 4;
*/
}
// Reads the 3magnetometer channels and stores them invectorm
void readMag()
{
Page | 41
X_L_M= readAccReg(LSM303DLH_OUT_X_L_M);
X_H_M =readAccReg(LSM303DLH_OUT_X_H_M);
Y_L_M = readAccReg(LSM303DLH_OUT_Y_L_M);
Y_H_M = readAccReg(LSM303DLH_OUT_Y_H_M);
Z_H_M = readAccReg(LSM303DLH_OUT_Z_L_M);
Z_H_M = readAccReg(LSM303DLH_OUT_Z_H_M);
/*
Wire.beginTransmission(MAG_ADDRESS);
Wire.send(LSM303DLH_OUT_X_H_M);
Wire.endTransmission();
Wire.requestFrom(MAG_ADDRESS,6);
while (Wire.available() <6);
uint8_t xhm =Wire.receive();
uint8_t xlm =Wire.receive();
uint8_t yhm =Wire.receive();
uint8_t ylm =Wire.receive();
uint8_t zhm =Wire.receive();
uint8_t zlm =Wire.receive();
m.x =(xhm << 8 | xlm);
m.y =(yhm << 8 | ylm);
m.z = (zhm << 8 | zlm);
*/
}
// Reads all6 channels oftheLSM303DLH andstores them intheobject variables
void read()
{
Page | 42
readAcc();
readMag();
}
#endif
Page | 43
We have written the code using the Assembly language.
list p=16f877a ; list directiveto define processor
#include <p16f877a.inc> ; processor specificvariabledefinitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
; '__CONFIG' directive is used to embedconfiguration data within.asmfile.
; The labels following thedirectivearelocated intherespective.inc file.
; See respectivedata sheetfor additionalinformationon configurationword.
huns EQU 20h
tens EQU 21h
ones EQU 22h
bin_num1 EQU 23h ; variabletostorethedistanceinbinary form
bin_num2 EQU 24h
rising_tempL EQU 25h
rising_tempH EQU 26h
falling_tempL EQU 35h
falling_tempH EQU 36h
count EQU 27h ; counter for delay perposes
count_echoL EQU 28h ; LSByte for Echo duration
count_echoH EQU 29h ; MSByte for Echo duration
temp1 EQU 30h
temp2 EQU 31h
;**********************************************************************
ORG 0000H
GOTO start
ORG 0004H
goto isr
;---------------------------------------------------------------------
isr
btfsc PIR1,2 ; is the interruptfrom CCP1 (rising edge)?
GOTO rising ; yes, process rising
btfsc PIR2,0 ; no, check theiftheinterrupt is duetoCCP2?
GOTO falling ; yes, process falling
GOTO finished
rising
clrf TMR1H
clrf TMR1L
bcf PIR1,2
RETFIE
falling movf CCPR2H,w
movwf falling_tempH
movf CCPR2L,w
movwf falling_tempL
bcf PIR2,0
finished RETFIE
; _________________________________________________________________________
start
movlw b'11000000' ; enable GIEandPeripheral interrupts
movwf INTCON
banksel CCP1CON
movlw b'00000101'
movwf CCP1CON ; capture modeCPP1,every rising edge
movlw b'00000100'
movwf CCP2CON ; capture modeCCP2, every falling edge
MOVLW 01H
MOVWF T1CON
banksel PIE1
Page | 44
movlw b'00000100'
movwf PIE1 ; enable CCP1interrupt
movlw b'00000001'
movwf PIE2 ; enable CCP1interrupt
movlw b'00000110'
movwf TRISC ; To configure the Capture Mode ofCCP1 and CCP2
clrf TRISB ; RB3 Triger for the ultrasonic
banksel PORTB
clrf PORTB
;------------------------------------------------------------------------------------
; main code....................................
new_reading
CALL trig ; triger the ultrasonicsensor
CALL onems
CALL Divide ; divide thetime over 58 toget the distancein binary
CALL bintodec ; convert from binary todecimal
goto new_reading
;________________________________________________________________________________
; Subroutines ..................................
; Triger the sensor by10usecpulseon thetriger pin RB3
trig bcf PORTB,3
nob
nob
nob
bsf PORTB,3 ; triger is connectedto POTR B,3
movlw 05h
movwf count ; delay for morethan 10us
wait_de decfsz count
GOTO wait_de
bcf PORTB,3
RETURN
;..................................................................
; divide echo width(i.e. in terms oftime in1usec) over 58to get thedistance in(cm).
Divide movf falling_tempL,w ; save the timecounters in orderto redisplay it untilthenext trig
movwf temp1
movf falling_tempH,w
movwf temp2
movf falling_tempL,w ; check ifthe echo signal dosentreturn
btfss STATUS,Z
GOTO nonzero
movf falling_tempH,w
btfss STATUS,Z
GOTO nonzero
return
nonzero
movlw d'58' ; put the divisorin W
subwf falling_tempL ; count_echo1=count_echo1 -d'58'
btfss STATUS,C
GOTO Borrow
GOTO Div_2
Borrow
movlw 01h
subwf falling_tempH ; use subtract insteadofdecf
btfss STATUS,C ; ... because itsets the carry
GOTO Done ; generateda borrow sofinish
Div_2
incfsz bin_num1 ; LSByte is saved in bin_num1
GOTO nonzero
incf bin_num2 ; MSByte is saved inbin_num2
GOTO nonzero
Done
Page | 45
movf temp1,w ; return thetimecounters inorder toredisplay it until the next trig
movwf falling_tempL
movf temp2,w
movwf falling_tempH
RETURN
;.................................................................
; Convert from binary to decimal ..........................
bintodec clrf huns
clrf tens
clrf ones
movf bin_num2,w
btfsc STATUS,Z ; is the MSByte oftheechosignal zero?
GOTO low_byte ; yes, then go tothelowbytewhichis bin_num1
movlw b'11111110' ; no, then check ifitis morethand'256'=b'00000001'
andwf bin_num2
btfss STATUS,Z
GOTO outside ; yes, it is morethan d'256'then
;the distanceis more than 400cm i.e.over thesensor's range
movlw d'2' ; no, then it equals d'256'so thehundreds is two
movwf huns
movlw d'50' ; the tens is d'50'
addwf bin_num1
movlw d'6' ; the ones is d'6'
addwf bin_num1
;,,,, calculate thehundreds for theLSByteofthe echo signal
low_byte bsf STATUS,C ; set carry bit toperformsubtract operations
movlw d'100'
wait_hunssubwf bin_num1
incf huns
btfsc STATUS,C ; does the subtraction becomezero?
goto wait_huns ; No, calculatehundreds again
addwf bin_num1 ; Yes, add 100to binarynumber to becorrect
decf huns ; decrement huns counter tobecorrect
;,,,, calculate thetens
bsf STATUS,C
movlw d'10'
wait_tens subwf bin_num1
incf tens
btfsc STATUS,C
goto wait_tens
addwf bin_num1
decf tens
;,,,, calculate theones
movf bin_num1,w ; the ones aretheremaining in bin_num
movwf ones
outside clrf bin_num1
clrf bin_num2
RETURN ; return to theCALL Binary todecimal bintodec
;........................................................................
END

Contenu connexe

Tendances

Final Year Project Report
Final Year Project ReportFinal Year Project Report
Final Year Project Report
Neel Patel
 
Development of Automated Guided Vehicle (AGV)
Development of Automated Guided Vehicle (AGV)Development of Automated Guided Vehicle (AGV)
Development of Automated Guided Vehicle (AGV)
Nur Syafiqah Mustaffa
 

Tendances (20)

Smart shoe
Smart shoeSmart shoe
Smart shoe
 
plastic solaar cell
plastic solaar cellplastic solaar cell
plastic solaar cell
 
Smart IoT Device for Vehicle Theft
Smart IoT Device for Vehicle TheftSmart IoT Device for Vehicle Theft
Smart IoT Device for Vehicle Theft
 
BOMB DETECTION ROBOT BY USING GSM & GPS
BOMB DETECTION ROBOT BY USING GSM & GPSBOMB DETECTION ROBOT BY USING GSM & GPS
BOMB DETECTION ROBOT BY USING GSM & GPS
 
ACCIDENT PREVENTION AND DETECTION SYSTEM
ACCIDENT PREVENTION AND DETECTION SYSTEMACCIDENT PREVENTION AND DETECTION SYSTEM
ACCIDENT PREVENTION AND DETECTION SYSTEM
 
Graduation project Book (Self-Driving Car)
Graduation project Book (Self-Driving Car)Graduation project Book (Self-Driving Car)
Graduation project Book (Self-Driving Car)
 
Vehicle to vehicle communication
Vehicle to vehicle communication  Vehicle to vehicle communication
Vehicle to vehicle communication
 
Smart Meters
Smart MetersSmart Meters
Smart Meters
 
GPS Vehicle Tracking Technology
GPS Vehicle Tracking Technology GPS Vehicle Tracking Technology
GPS Vehicle Tracking Technology
 
Accident Detection System using Arduino Uno
Accident Detection System using Arduino UnoAccident Detection System using Arduino Uno
Accident Detection System using Arduino Uno
 
Google car ppt
Google car pptGoogle car ppt
Google car ppt
 
Anti theft security system for vehicle
Anti theft security system for vehicleAnti theft security system for vehicle
Anti theft security system for vehicle
 
Industrial training report
Industrial training reportIndustrial training report
Industrial training report
 
Smart Meters
Smart MetersSmart Meters
Smart Meters
 
Paper battery document and report
Paper battery document and reportPaper battery document and report
Paper battery document and report
 
A report on solar power plant visit
A report on solar power plant visitA report on solar power plant visit
A report on solar power plant visit
 
Automated Meter Reading System
Automated Meter Reading SystemAutomated Meter Reading System
Automated Meter Reading System
 
Final Year Project Report
Final Year Project ReportFinal Year Project Report
Final Year Project Report
 
Solar panel ppt
Solar panel pptSolar panel ppt
Solar panel ppt
 
Development of Automated Guided Vehicle (AGV)
Development of Automated Guided Vehicle (AGV)Development of Automated Guided Vehicle (AGV)
Development of Automated Guided Vehicle (AGV)
 

En vedette

Fuel theft prevention system
Fuel theft prevention systemFuel theft prevention system
Fuel theft prevention system
Mohit Mahaldar
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
slmnsvn
 
Analysis optimization and monitoring system
Analysis optimization and monitoring system Analysis optimization and monitoring system
Analysis optimization and monitoring system
slmnsvn
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
slmnsvn
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
slmnsvn
 
Rfid attendace system
Rfid attendace systemRfid attendace system
Rfid attendace system
slmnsvn
 
Analysis optimization and monitoring system
Analysis optimization and monitoring system Analysis optimization and monitoring system
Analysis optimization and monitoring system
slmnsvn
 
Dfmea for engine systems
Dfmea for engine systemsDfmea for engine systems
Dfmea for engine systems
Kamal Vora
 

En vedette (14)

Fuel theft prevention system
Fuel theft prevention systemFuel theft prevention system
Fuel theft prevention system
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
 
Analysis optimization and monitoring system
Analysis optimization and monitoring system Analysis optimization and monitoring system
Analysis optimization and monitoring system
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
 
Diesel theft detection - fuel pilferage prevention - generator- client case s...
Diesel theft detection - fuel pilferage prevention - generator- client case s...Diesel theft detection - fuel pilferage prevention - generator- client case s...
Diesel theft detection - fuel pilferage prevention - generator- client case s...
 
Smart home
Smart homeSmart home
Smart home
 
Fuel level sensor DUT-E - fuel theft prevention
Fuel level sensor DUT-E - fuel theft preventionFuel level sensor DUT-E - fuel theft prevention
Fuel level sensor DUT-E - fuel theft prevention
 
Quad pod transformable vehicle
Quad pod transformable vehicleQuad pod transformable vehicle
Quad pod transformable vehicle
 
Rfid attendace system
Rfid attendace systemRfid attendace system
Rfid attendace system
 
Fuel flow meters DFM - Wagencontrol
Fuel flow meters DFM - WagencontrolFuel flow meters DFM - Wagencontrol
Fuel flow meters DFM - Wagencontrol
 
Analysis optimization and monitoring system
Analysis optimization and monitoring system Analysis optimization and monitoring system
Analysis optimization and monitoring system
 
Dfmea for engine systems
Dfmea for engine systemsDfmea for engine systems
Dfmea for engine systems
 
Final Year Project Presentation
Final Year Project PresentationFinal Year Project Presentation
Final Year Project Presentation
 
글로벌 CDN과 동적 웹 가속 기술 (Global CDN & Dynamic Web Acceleration) - FNet Grand Conf...
글로벌 CDN과 동적 웹 가속 기술 (Global CDN & Dynamic Web Acceleration) - FNet Grand Conf...글로벌 CDN과 동적 웹 가속 기술 (Global CDN & Dynamic Web Acceleration) - FNet Grand Conf...
글로벌 CDN과 동적 웹 가속 기술 (Global CDN & Dynamic Web Acceleration) - FNet Grand Conf...
 

Similaire à Smart fuel theft detector

Low bridge avoidance system
Low bridge avoidance systemLow bridge avoidance system
Low bridge avoidance system
slmnsvn
 
milestone-5-stretching
milestone-5-stretchingmilestone-5-stretching
milestone-5-stretching
Johanna Jan
 
UETCL report
UETCL reportUETCL report
UETCL report
Jim Kats
 
4473439C_Smartexample
4473439C_Smartexample4473439C_Smartexample
4473439C_Smartexample
Nora Smart
 
CMP Engineers Capability Statement - 2014 - V3
CMP Engineers Capability Statement - 2014 - V3CMP Engineers Capability Statement - 2014 - V3
CMP Engineers Capability Statement - 2014 - V3
Peter McGiffin
 
Opinion Formation about Childhood Immunization and Disease Spread on Networks
Opinion Formation about Childhood Immunization and Disease Spread on NetworksOpinion Formation about Childhood Immunization and Disease Spread on Networks
Opinion Formation about Childhood Immunization and Disease Spread on Networks
Zhao Shanshan
 
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
Mostafa El-Beheiry
 

Similaire à Smart fuel theft detector (20)

Low bridge avoidance system
Low bridge avoidance systemLow bridge avoidance system
Low bridge avoidance system
 
milestone-5-stretching
milestone-5-stretchingmilestone-5-stretching
milestone-5-stretching
 
MSc_Dissertation
MSc_DissertationMSc_Dissertation
MSc_Dissertation
 
UETCL report
UETCL reportUETCL report
UETCL report
 
Evaluation of tdoa techniques for position
Evaluation of tdoa techniques for positionEvaluation of tdoa techniques for position
Evaluation of tdoa techniques for position
 
4473439C_Smartexample
4473439C_Smartexample4473439C_Smartexample
4473439C_Smartexample
 
Valentine One radar detector manual
Valentine One radar detector manualValentine One radar detector manual
Valentine One radar detector manual
 
Voice Recognition Service (VRS)
Voice Recognition Service (VRS)Voice Recognition Service (VRS)
Voice Recognition Service (VRS)
 
Sunidhi_MSc_F2015
Sunidhi_MSc_F2015Sunidhi_MSc_F2015
Sunidhi_MSc_F2015
 
CMP Engineers Capability Statement - 2014 - V3
CMP Engineers Capability Statement - 2014 - V3CMP Engineers Capability Statement - 2014 - V3
CMP Engineers Capability Statement - 2014 - V3
 
Advances in Renewable Energies and Power Technology.pdf
Advances in Renewable Energies and Power Technology.pdfAdvances in Renewable Energies and Power Technology.pdf
Advances in Renewable Energies and Power Technology.pdf
 
Opinion Formation about Childhood Immunization and Disease Spread on Networks
Opinion Formation about Childhood Immunization and Disease Spread on NetworksOpinion Formation about Childhood Immunization and Disease Spread on Networks
Opinion Formation about Childhood Immunization and Disease Spread on Networks
 
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
Challenges in VoIP Systems - Mostafa Ahmed Mostafa El Beheiry - First Draft F...
 
Jdsu book
Jdsu bookJdsu book
Jdsu book
 
Book telecommunications
Book telecommunications Book telecommunications
Book telecommunications
 
Metasploit
MetasploitMetasploit
Metasploit
 
OFDM Based Cognitive radio
OFDM Based Cognitive radioOFDM Based Cognitive radio
OFDM Based Cognitive radio
 
thesis_sillero
thesis_sillerothesis_sillero
thesis_sillero
 
Slotted ALOHA Random Access-Master.pdf
Slotted ALOHA Random Access-Master.pdfSlotted ALOHA Random Access-Master.pdf
Slotted ALOHA Random Access-Master.pdf
 
Emona-based Interactive Amplitude Modulation/Demodulation iLab
Emona-based Interactive Amplitude Modulation/Demodulation iLabEmona-based Interactive Amplitude Modulation/Demodulation iLab
Emona-based Interactive Amplitude Modulation/Demodulation iLab
 

Plus de slmnsvn

Power factor correction
Power factor correctionPower factor correction
Power factor correction
slmnsvn
 
Power factor correction
Power factor correctionPower factor correction
Power factor correction
slmnsvn
 
Optimum performances of ramallah
Optimum performances of ramallahOptimum performances of ramallah
Optimum performances of ramallah
slmnsvn
 
Optimum performances of ramallah
Optimum performances of ramallahOptimum performances of ramallah
Optimum performances of ramallah
slmnsvn
 
Optimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate networkOptimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate network
slmnsvn
 
Optimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate networkOptimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate network
slmnsvn
 
Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2
slmnsvn
 
Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2
slmnsvn
 
Optimum performance for aqraba electrical network
Optimum performance for aqraba electrical networkOptimum performance for aqraba electrical network
Optimum performance for aqraba electrical network
slmnsvn
 
Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...
slmnsvn
 
Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...
slmnsvn
 
Investigation effects-of-supplying-power-distrubition
Investigation effects-of-supplying-power-distrubitionInvestigation effects-of-supplying-power-distrubition
Investigation effects-of-supplying-power-distrubition
slmnsvn
 
Investigation of-effects-of-supplying-jenins-power
Investigation of-effects-of-supplying-jenins-powerInvestigation of-effects-of-supplying-jenins-power
Investigation of-effects-of-supplying-jenins-power
slmnsvn
 
Cell phone based dtmf controlled
Cell phone based dtmf controlledCell phone based dtmf controlled
Cell phone based dtmf controlled
slmnsvn
 
Cell phone based dtmf controlled
Cell phone based dtmf controlledCell phone based dtmf controlled
Cell phone based dtmf controlled
slmnsvn
 
Cell phone based dtmf
Cell phone based dtmfCell phone based dtmf
Cell phone based dtmf
slmnsvn
 

Plus de slmnsvn (20)

Power factor correction
Power factor correctionPower factor correction
Power factor correction
 
Power factor correction
Power factor correctionPower factor correction
Power factor correction
 
Optimum performances of ramallah
Optimum performances of ramallahOptimum performances of ramallah
Optimum performances of ramallah
 
Optimum performances of ramallah
Optimum performances of ramallahOptimum performances of ramallah
Optimum performances of ramallah
 
Optimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate networkOptimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate network
 
Optimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate networkOptimum performance of tulkarim governorate network
Optimum performance of tulkarim governorate network
 
Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2
 
Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2Optimum performance for aqraba electrical network 2
Optimum performance for aqraba electrical network 2
 
Optimum performance for aqraba electrical network
Optimum performance for aqraba electrical networkOptimum performance for aqraba electrical network
Optimum performance for aqraba electrical network
 
Multi tone test
Multi tone testMulti tone test
Multi tone test
 
Multi tone test
Multi tone testMulti tone test
Multi tone test
 
Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...
 
Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...Mini scada system for monitoring pv and wind installation in meteorology stat...
Mini scada system for monitoring pv and wind installation in meteorology stat...
 
Investigation effects-of-supplying-power-distrubition
Investigation effects-of-supplying-power-distrubitionInvestigation effects-of-supplying-power-distrubition
Investigation effects-of-supplying-power-distrubition
 
Investigation of-effects-of-supplying-jenins-power
Investigation of-effects-of-supplying-jenins-powerInvestigation of-effects-of-supplying-jenins-power
Investigation of-effects-of-supplying-jenins-power
 
Enable talk
Enable talkEnable talk
Enable talk
 
Enable talk
Enable talkEnable talk
Enable talk
 
Cell phone based dtmf controlled
Cell phone based dtmf controlledCell phone based dtmf controlled
Cell phone based dtmf controlled
 
Cell phone based dtmf controlled
Cell phone based dtmf controlledCell phone based dtmf controlled
Cell phone based dtmf controlled
 
Cell phone based dtmf
Cell phone based dtmfCell phone based dtmf
Cell phone based dtmf
 

Dernier

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Dernier (20)

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

Smart fuel theft detector

  • 1. Page | 1 SMART Fuel Theft Detector
  • 2. Page | 2 An-Najah National University Electrical Engineering Department Graduation Project 2 SMART Fuel Theft Detector Supervisor: Dr. Samer Mayyalih Prepared by: Amjad Rabayaa Adham Sawafta December 2013
  • 3. Page | 3 ‫اإلهــــــداء‬ ‫هللا‬ ‫بسم‬‫الرحيم‬ ‫الرحمن‬ ‫الحمد‬‫يعلمون‬ ‫ال‬ ‫والذين‬ ‫يعلمون‬ ‫الذين‬ ‫يستوي‬ ‫هل‬‫ل‬‫ق‬ .. " ‫التنزيل‬‫محكم‬ ‫في‬ ‫ائل‬‫الق‬ ‫العالمين‬‫رب‬‫هلل‬.. "‫والصالة‬‫األنام‬‫خير‬‫على‬ ‫والسالم‬ ‫على‬ ‫العالم‬ُ‫ل‬ْ‫ض‬َ‫وف‬ .. ‫ة‬َّ‫ن‬‫الج‬‫إلى‬ً‫ا‬‫طريق‬ ‫به‬ ‫له‬ ‫هللا‬ ‫سهل‬ ،ً‫ا‬‫علم‬ ‫فيه‬ ‫يلتمس‬ً‫ا‬‫طريق‬ ‫سلك‬ ‫من‬ .."‫ائل‬‫الق‬‫هللا‬ ‫عبد‬ ‫بن‬ ‫محمد‬‫القمر‬‫كفضل‬ ‫العابد‬ ‫و‬ ...‫الكواكب‬‫سائر‬ ‫على‬َّ‫أن‬‫منهاجا‬ ‫بذالك‬ ‫سطر‬ُّ‫ي‬‫ل‬ "‫األنبياء‬‫ورثة‬ ‫العلماء‬ً‫ا‬ّ‫رباني‬.‫والتعلم‬ ‫العلم‬‫حب‬‫على‬ً‫ا‬‫ائم‬‫ق‬ ‫بعد‬‫التوكل‬‫الوقت‬‫كل‬ ‫منا‬ ‫استنفذ‬‫لطالما‬ ‫الذي‬ ‫المتواضع‬‫اإلنجاز‬ ‫هذا‬ ‫نهدي‬ ,‫هللا‬ ‫يشكر‬ ‫ال‬ ‫الناس‬ ‫اليشكر‬ ‫من‬ ‫باب‬ ‫ومن‬ ,‫هللا‬‫على‬ ‫الكري‬‫هللا‬ ‫وجه‬ ‫نحو‬ ‫بذلك‬ ‫ماضين‬ ,‫والمثابرة‬ ‫الجد‬ ‫من‬ ‫طوال‬ ‫سنوات‬ ‫به‬ ‫تتوج‬ ‫إكليال‬ ‫بذلك‬ ‫ليكون‬ ‫والجهد‬‫م‬‫الجد‬‫على‬‫ائمة‬‫ق‬ ‫حياة‬‫نحو‬ , .‫والتضحية‬ ‫واإلجتهاد‬ ‫إليك‬..‫إلهي‬‫وخالقي‬ ‫الذي‬‫بطاعت‬ ‫إال‬ ‫النهار‬ ‫يطيب‬ ‫وال‬ ‫بشكره‬ ‫إال‬ ‫الليل‬‫يطيب‬ ‫ال‬‫ه‬‫إال‬ ‫ة‬ّ‫الجن‬‫تطيب‬ ‫وال‬ ‫بعفوه‬ ‫إال‬ ‫األخرة‬ ‫تطيب‬ ‫وال‬ ‫بذكره‬ ‫إال‬ ‫اللحظات‬ ‫تطيب‬ ‫وال‬ ‫برؤيته‬ ‫إلى‬..‫دي‬ّ‫سي‬‫وحبيبي‬ ‫يامن‬‫اعته‬‫بشف‬ ‫نطمع‬ ‫من‬ ‫يا‬ ‫امه‬‫لمق‬ ‫العروق‬ ‫بين‬ ‫الدم‬‫ويقف‬ ‫لذكره‬ ‫العيون‬ ‫وسط‬ ‫من‬ ‫الدمع‬‫يسيل‬ ‫محمد‬‫وسلم‬ ‫عليه‬ ‫هللا‬ ‫صلى‬ ‫إلى‬..‫تعالى‬ ‫هللا‬ ‫بعد‬ ‫الوجود‬‫في‬ ‫من‬ ‫كل‬ ‫سندي‬ّ‫ا‬‫من‬ ,‫هللا‬ ‫بعد‬ ‫ومالذي‬ ‫وقوتي‬‫ثروني‬‫واألمل‬ ‫اؤل‬‫والتف‬ ‫الصبر‬ ‫ومعنى‬ ‫الحياة‬ ‫معنى‬ ‫وعلموني‬ ‫أنفسهم‬‫على‬ ‫والدي‬‫إنتظار‬ ‫بدون‬ ‫العطاء‬‫علمني‬ ‫من‬ .. ‫العزيز‬ ‫أمي‬‫اء‬‫الشف‬‫وبلسم‬ ‫الحب‬‫رمز‬ .. ‫الحنون‬ ‫إخواني‬‫..الذ‬ ‫وأخواتي‬‫المعين‬‫نعم‬ ‫فكانوا‬ ‫والمؤازرة‬ ‫المساندة‬‫اشكال‬‫بكل‬ ‫امدوني‬ ‫ين‬ ‫أهلي‬... ‫بجانبي‬ ‫وقف‬ ‫من‬ ‫وكل‬ ‫بلدي‬ ‫وأهل‬ ‫وعشيرتي‬ ‫إلى‬..‫خطوت‬‫نخطوا‬ ‫ونحن‬ ‫ووداعهم‬ ‫شكرهم‬ ‫علينا‬ ‫وجب‬ ‫الذين‬‫نا‬‫يبخل‬ ‫لم‬ ‫الذين‬ ,‫الحياة‬‫غمار‬ ‫في‬ ‫األولى‬‫وا‬‫ووقتهم‬ ‫بعلمهم‬ ‫علينا‬ ‫الذين‬‫أينا‬‫ر‬‫األوفياء‬‫وسماحة‬ ‫العلماء‬‫وتواضع‬ ‫األباء‬‫محبة‬ ‫فيهم‬
  • 4. Page | 4 ‫الدكتور‬‫الكهربائية‬ ‫الهندسة‬‫قسم‬ ‫رئيس‬ ‫خماش‬‫ماهر‬ ‫الدكتور‬‫بريك‬ ‫عماد‬ ‫الدكتور‬‫خير‬‫كل‬ ‫ا‬ّ‫عن‬ ‫هللا‬ ‫اه‬‫ز‬‫ج‬ .. ‫المشروع‬ ‫هذا‬ ‫على‬ ‫افه‬‫ر‬‫بإش‬ ‫تفضل‬ ‫الذي‬‫ميالة‬ ‫سامر‬ ‫و‬‫الوطنية‬‫النجاح‬‫جامعة‬‫في‬ ‫الكهربائية‬ ‫الهندسة‬‫أسرة‬‫كل‬ ‫إلى‬‫م‬ ‫الذين‬‫والقهر‬ ‫والظلم‬ ‫الغدر‬‫زنازين‬ ‫في‬ .. ‫هناك‬ ‫الوا‬‫ز‬‫ا‬ ‫يامن‬‫الشهداء‬‫ألرض‬ ‫فداءا‬ ‫أعماركم‬‫دفع‬ ‫اليتم‬ ‫يامن‬ ‫بصبركم‬ ‫للنصر‬ ‫وحون‬ّ‫ل‬‫وت‬ ‫بصمودكم‬ ‫الحرية‬ ‫تكتبون‬ ‫نعم‬‫سالم‬ ‫الف‬ ‫ا‬ّ‫من‬ ‫لكم‬ .. ‫األسرى‬ ‫..أيها‬ ‫أما‬‫الوطن‬ ‫امتداد‬‫على‬ ‫النصر‬‫هة‬ّ‫فو‬ ‫ورسمتم‬ ‫اء‬‫البق‬‫حب‬‫فينا‬ ‫زرعتم‬ ‫من‬ ‫يا‬ ..‫أنتم‬ ‫نسألكم‬‫منكم‬ ‫لنستلهم‬ ‫األيادي‬ ‫تمدوا‬ ‫أن‬‫ما‬‫جهادكم‬‫ومضات‬ ‫على‬ ‫يحيينا‬ ‫سالم‬‫ريعا‬ ‫في‬ ‫األحياء‬‫أيها‬‫ن‬‫الشهادة‬
  • 5. Page | 5 Contents ACKNOWLEDGMENT...............................................................................Error! Bookmark not defined. Table of Figures..................................................................................................................................6 CH 1 SURVEY...................................................................................................................................7 1.1 THE SURVEY ........................................................................................................................7 1.2 RESULTS AND ANALYISIS ......................................................................................................9 CH 2 Introduction..........................................................................................................................11 2.1 PROBLEMTO SOLVE...........................................................................................................11 2.2 ABSTRACT.........................................................................................................................12 2.3 METHODOLOGY.................................................................................................................13 2.4 ENVIRONMENT OF WORK ..................................................................................................14 CH 3 SOLUTION.............................................................................................................................15 3.1 FUEL MEASURMENT...........................................................................................................15 3.1.1 THE FIRST PROPER SENSOR (HC-SR04) .........................................................................15 3.1.2 THE SECONDPROPER SENSOR(LSM303DLH)…………………………………………………………………16 3.1.3 MICROCONTROLLER.................................................................................................187 3.1.3 FILTERING & PROCESSING......................................................................................... 219 3.2 TRANSMISSION OFDATA……………………………………………………………………………………………………….22 3.2.1 GPRS MODULE……………………………………………………………………………………………………………….22 3.2.2 INTERFACING BETWEEN THE GPRS AND THE CONTROLLER ...........................................25 3.2.3 TRANSMISSION USING GPRS MODULE.........................................................................25 3.3 The Whole system .............................................................................................................25 CH 4 CONCLUSION ANDOBSERVATIONS…………………………………………………………………………………………….25 4.1 Experiment on the Sensor..................................................................................................27 4.2 CONCLUSION.....................................................................................................................29 Bibliography.....................................................................................................................................31 APPENDEX A.1: The Code of the PIC16f877a.......................................................................................32
  • 6. Page | 6 Table of Figures Figures1.2-1 The surveyresults………………………………………………………………………………………………………………7 Figure 3.1-1 Ultrasonic principle ........................................................................................................13 Figure 3.1-2 The HC-SR04 ultrasonic sensor........................................................................................14 Figure 3.1-3 The Principle of Work Ultrasonic Sensor...........................................................................17 Figure 3.1-4 Timing Diagram of the Ultrasonic Sensor.........................................................................17 Figure 3.1-5 The LSM303DLE slope sensor..........................................................................................20 Figure3.1-6 PIC16f877a…………………………...................................................................................................17 Figure 3.1-7 Flow Chartfor the Microcontroller .............................................................................. 2422 Figure 3.2-1 GPRS module.................................................................................................................25 Figure 4.1-1: 12cm distance from a rigid body ....................................................................................27 Figure 4.1-2: 16cm distance from a rigid body ....................................................................................27 Figure 4.1-3: 20cm distance from a rigid body ....................................................................................27 Figure 4.1-4: 24cm distance from a rigid body ....................................................................................27 Figure 4.1-5: Test of the Sensor on Fluids............................................................................................28
  • 7. Page | 7 CH 1 SURVEY 1.1 THE SURVEY Afterwe choose ourprojectidea we did a short survey about the projectto ensure thatthe system isimportantfor the ownersof transport companies, aswell as find out if they have usedotherdevices to solve the problem and how the success of these devices. In addition to that we want to identifythe extent of the Palestinian marketneed forthe project and the possibility of marketingit effectively. Our surveyis shownbelowinArabicaswe distributedit: ‫الى‬ ‫إرسالها‬ ‫و‬ ‫دقيق‬ ‫بشكل‬ ‫التنك‬ ‫داخل‬ ‫الوقود‬ ‫كمية‬ ‫حساب‬ ‫على‬ ‫يعمل‬ ‫جهاز‬ ‫بناء‬ ‫على‬ ‫المشروع‬ ‫فكرة‬ ‫تقوم‬ ‫تج‬ ‫مناسبة‬ ‫بطريقة‬ ‫الجهاز‬ ‫وصمم‬ ‫دوري‬ ‫بشكل‬ ‫الشركة‬ ‫مقر‬‫عله‬‫ثم‬ ‫ومن‬ ‫الوقود‬ ‫إستهالك‬ ‫مقدار‬‫تتبع‬ ‫على‬ ‫قادرا‬ ‫عن‬ ‫السرقة‬ ‫إكتشاف‬‫السرقة‬ ‫عن‬ ‫تبلغ‬ ‫فورية‬ ‫رسالة‬ ‫بإرسال‬ ‫يقوم‬ ‫حيث‬ ‫حدوثها‬ ‫د‬‫وكمية‬.‫المسروقة‬ ‫الوقود‬ ‫ت‬ ‫على‬ ‫العمل‬ ‫فريق‬ ‫تساعد‬ ‫بطريقة‬ ‫وضع‬ ‫التالي‬ ‫اإلستبيان‬‫وقع‬‫وساعات‬ ‫يوميا‬ ‫المسروقة‬ ‫الوقود‬ ‫كميات‬ ‫الوسائل‬ ‫جميع‬ ‫اإلعتبار‬ ‫بعين‬ ‫األخذ‬ ‫مع‬ ‫السرقة‬ ‫حالة‬ ‫مع‬ ‫التعامل‬ ‫طريقة‬ ‫من‬‫البيانات‬ ‫هذه‬ ‫تسهل‬ ‫حيث‬ ‫السرقة‬ .‫الوقود‬ ‫سرقة‬ ‫في‬ ‫المتبعة‬ ‫ما‬‫دوري‬ ‫بشكل‬ ‫المستهلكة‬ ‫الوقود‬ ‫لكميات‬ ‫الدقيقة‬ ‫المعرفة‬ ‫أهمية‬ ‫هي‬ ‫مهم‬‫جدا‬ ‫مهم‬ ‫محايد‬ ‫غير‬‫مهم‬ ‫الشعور‬‫ب‬‫الوقود‬ ‫سرقة‬ ‫متأكد‬‫السرقة‬ ‫وجود‬ ‫من‬ ‫شاك‬‫السرقة‬ ‫بوجود‬ ‫ال‬‫لي‬ ‫علم‬ ‫متأكد‬‫سرقة‬ ‫وجود‬ ‫عدم‬ ‫من‬ ‫في‬‫الوقود‬ ‫سرقة‬ ‫تكون‬ ‫الغالب‬ ‫أثناء‬‫المركبة‬ ‫عمل‬ ‫خارج‬‫المركبة‬ ‫عمل‬ ‫ساعات‬ ‫في‬‫السابقتين‬ ‫الحالتين‬ ‫كلتا‬ ‫في‬‫قبل‬ ‫من‬ ‫الوقود‬ ‫سرقة‬ ‫تكون‬ ‫الغالب‬ ‫سائق‬‫الشاحنة‬ ‫ناس‬ُ‫أ‬‫(أثناء‬ ‫العمل‬ ‫خارج‬ ‫اخرون‬)‫العمل‬ ‫عن‬ ‫المركبة‬ ‫توقف‬ ‫ال‬‫أعلم‬
  • 8. Page | 8 ‫بكم‬‫شهريا‬ ‫المسروقة‬ ‫الوقود‬ ‫كمية‬ ‫تقدر‬................................................................................................. ‫هل‬‫الوقود‬ ‫سرقة‬ ‫من‬ ‫يمنع‬ ‫أو‬ ‫عن‬ ‫يكشف‬ ‫جهاز‬ ‫شراء‬ ‫حاولت‬ ‫نعم‬ ‫ال‬ ‫إذا‬‫نعم‬ ‫اإلجابة‬ ‫كانت‬ ‫ما‬‫عمل‬ ‫طبيعة‬ ‫هي‬ ........................................................‫الجهاز؟‬..................................... ............................................................................................................................................ ‫ما‬‫سعر‬ ‫هو‬ ............................................................‫الجهاز؟‬......................................... ‫هل‬‫؟‬ ‫المشكلة‬ ‫حل‬ ‫على‬ ‫وقادرا‬ ‫اال‬ّ‫ع‬‫ف‬ ‫الجهاز‬ ‫كان‬ ‫نعم‬ ‫ال‬ ‫إذا‬‫؟‬ ‫برأيك‬ ‫السبب‬ ‫هو‬ ‫فما‬ ‫ال‬ ‫اإلجابة‬ ‫كانت‬ ............................................................................................. ............................................................................................................................................ ‫هل‬‫؟‬ ‫المشكلة‬ ‫حل‬ ‫لك‬ ‫يكفل‬ ‫جهاز‬ ‫لشراء‬ ‫مستعد‬‫أنت‬ ‫نعم‬ ‫متردد‬ ‫ال‬‫أرغب‬
  • 9. Page | 9 1.2 RESULTS AND ANALYISIS Evenour sample wasnotlarge enoughdue to the limitedcompaniesandfoundationswhichare nearto us, we can say the following:  The majorityof companiesstatedthatit isveryimportantforthemto identifyexactlytheir expenses onthe fuel consumption.  A significantnumberof the sample suffersfromuncertaintyinthe amountof itsfuel consumption.  Some of the companiesare sure thatthere issome kindof fuel theftfromtheirvehicles.  Some of the companieshave alreadybought asystemtofindtrackthe fuel consumptionin theirvehicles.  Some of the companiesmentionedthatthe fuel theftisperformedbypersonsnotfromthe drivers. To understandthe surveyoutputsee the figuresbellow. Figures1.2-1 the survey results
  • 10. Page | 10 As we expected,thisphenomenaispresentandneedtoa reliable andcost-effective solutionwhich can calculate the fuel consumptionanddetectthe fuel theftif happened.
  • 11. Page | 11 CH 2 Introduction 2.1 PROBLEM TO SOLVE Due to the high fuel price, fuel theft became worrying phenomenon and it is very important for companies and foundations to monitor its fuel consumption rate in order to put its best budget. According to the Palestinian distributing fuel stations the cost of one litter of diesel in excess of 5.7 NIS (as of 12:00 a.m. April 29, 2013), so any storage of fuel can be a target for theft as well as transportation vans. In our project we provide a smart electrical system to help our client to deal with this problem and we aim to protect our clients from the fuel theft especially the transportation vans and vehicles. Our duty to stop the fuel theft so, before we start the smart fuel level detector idea, we set some advice for the fuel consumers which can help to a void the fuel theft.  Consider installing a locking gas cap. Remember that many of the “fuel doors” that open remotely or with a key are flimsy and easily compromised.  Avoid parking in dark, isolated areas (especially for extended periods).  At home, park in a locked garage where possible. If you don’t have a garage, park as close as possible to the house and avoid parking on the street.  If you must park on a street or in a parking lot, attempt to locate your vehicle so the fuel door is visible to you or other residents in your area.  If you have bulk fuel on your property, ensure you lock the tank and or dispenser to prevent access. Our fuel level detector continuously monitors your tank fuel with the ultrasonic fuel detector, the easiest solution to prevent fuel theft and fraud. Fuel theft: the moment our system tracks an unusual rate of decrease in the fuel-level (i.e. in usual conditions, the vehicle consumes a certain amount of fuel; while in the theft case, the rate of decrease of the fuel will be faster than the usual case) the fuel-tracker will send an alarm via a GPRS module (may be a SMS) and can be automatically configured to ring an audible alarm when the fuel theft occurs. The tracker is sensitive enough to detect when someone tries to 'skim' excess fuel from a vehicles tank.
  • 12. Page | 12 2.2 ABSTRACT The level of the fuel, especially in cars and vehicles, is very important since it gives indication about the remaining amount of fuel in the tank of the vehicle. However, particularly, for the companies which have number of vehicles it is essential to monitor the fuel level at all times in order to identify its budget and expenses also to capture the fuel theft. The level measurement of fuel in the vehicle’s tank is a special case of general level measuring applications because:  The flammability of the fuel, so it is very dangerous to put any electrical devices or wires inside the fuel tank.  The very accurately closed tank, so it isn’t preferred to make holes other than the main opening.  The dynamic motion of the fuel, which means that the measuring process must take into consideration the road condition such that if the road is flat or has some slope (either positive or negative). In our project, we aim to design a smart fuel level measuring system which:  Measures the amount of fuel in the tank accurately and in real time.  Has the ability to measure the amount of fuel even if the vehicle is moving on a flat or has some slope roads.  Can store the measurements in order to do some extra process such as consumption rate per day or month … etc.  Can be configured with a microcontroller to send the measurements via GPRS.  Capture the fuel theft even if the vehicle is turned off! Finally, our scope of work will be:  Specify which kind of sensors will be suitable for our requirements.  Make some data processing such as Filtering.  Store the measurements.  Capable to make data communication (GPRS).  Display the measurements as graphical representation.  Alarm in case of fuel theft.
  • 13. Page | 13 2.3 METHODOLOGY The methodology will be followed at this project is to:  Identify the elements of the project and the functionality of each one.  Identify the circumstances which presents in the environment surrounding the project.  Find the best arrangement of the elements of the system in order to achieve the best performance.  Find the best and safe way to take the measurements of the fuel.  Write the best code of the microcontroller to filter and process the sensor’s measurement.  Connect the microcontroller to the GPRS module in order to send the measurements to the site of the company.
  • 14. Page | 14 2.4 ENVIRONMENT OF WORK For the work environment there are many criteria that must be taken into consideration. If we want to put the sensor on the surface of the tank we will be forced to make a suitable slot to fix the sensor, for this reason it must be very careful because small arc will lead to huge explosion. In addition of that, the large needed to speed and accurate transmission methods. So in our project we have taken a lot of things in consideration, for example:  Chemical properties of the diesel.  Small dimensions of the sensor.  The temperature effect on the sensor reading.  A suitable sensor which works at low voltage.  Good transmission methods like GPRS and GSM. All these things and more will make from our system as safe as possible.
  • 15. Page | 15 CH 3 SOLUTION 3.1 FUEL MEASURMENT 3.1.1 THE FIRST PROPERSENSOR (HC-SR04) In a large number of ultrasonic distance measurements, the operating principle is the estimation of time of flight (ToF) Tf. The sensor generates ultrasonic pulses and these pulses will be reflected to the receiver when it reaches the fuel surface as shown in figure 3.1-1. So that the distance can be estimated directly by the formula: V: represents the propagation velocity of the ultrasonic wave in the medium (air). Figure 3.1-1 Ultrasonic principle According to the previous equation we see that the distance depends directly on the propagation velocity of the ultrasonic wave and this quantity depends on the relative humidity and the temperature, and also on some chemical and physical parameters of the fluid. More over the time of flight will control the measured distance. In the ultrasonic system two kinds of sensing are possible (1) :  The continuous wave method  The pulse echo method In our project there are many things must be considered when we select the sensor kind, so we saw the advantages and the disadvantages for both kind. Let us start with the first type which is the continuous wave method. In this method two separate transmitting and receiving elements are used, so that the level is
  • 16. Page | 16 evaluated through the estimation of a phase shift. In this case good performance can be obtained, but a more complex hardware system is necessary. The pulse echo method, on the other hand, requires only one transducer that operates alternately in transmitting and receiving method. Also pulse echo method offers a simple and low cost solution, even it yields poorer results due to uncertainty in the time delay measurement .These results, in fact, can be improved by using a cheap software signal processing. However, our HC-SR04 ultrasonic sensor is included under the continuous wave method but with some modification which is instead of the output in the form of phase shift it is here a PWM (pulse width modulation) such that the time of flight is represented by the width of the echo signal from the ultrasonic. The HC-SR04 (2) ultrasonic sensor as shown in figure 2.3-1 is small and meets our requirements so as not to take large space on the tank. As shown, it has four legs:  VCC: 5 volt  GND: zero volt (ground).  Trig: a 10us 5 volt pulse to start the sensor.  Echo: the output signal of the sensor. Figure 3.1-2 The HC-SR04 ultrasonic sensor Ultrasonic ranging module HC - SR04 provides (2cm - 400cm) non-contact measurement function, the ranging accuracy can reach to 3mm. The module includes ultrasonic transmitter, receiver and control circuit. The basic principle of work, figure 3.1-2 clarifies this principle: 1- Using IO trigger for at least 10us high level signal. 2- The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back. 3- IF the signal back, through high level , time of high output IO duration is the time from sending ultrasonic to returning. 4- Test distance = (high level time X velocity of sound (340 m/sec) / 2
  • 17. Page | 17 Figure 3.1-3 The Principle of Work Ultrasonic Sensor Timing diagram Figure 3.1-4 Timing Diagram of the Ultrasonic Sensor The Timing diagram is shown in figure 2.3-2. We only need to supply a short 10uS pulse to the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in proportion .We can calculate the range through the time interval between sending trigger signal and receiving echo signal. The formula to calculate the distance is: uSec / 58 = centimeters or uSec / 148 =inch or the range = high level time * velocity (340 m/sec) / 2 It is recommended to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.
  • 18. Page | 18 3.1.2 THE SECOND PROPERSENSOR(LSM303DLH) Figure 3.1-5 The LSM303DLH slope sensor Description: The LSM303DLH is a system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. The various sensing elements are manufactured using specialized micromachining processes, while the IC interfaces are realized using a CMOS technology that allows the design of a dedicated circuit which is trimmed to better match the sensing element characteristics. The LSM303DLH includes an I2C serial bus interface that supports standard mode (100 kHz) and fast mode (400 kHz).The system can be configured to generate an interrupt signal by inertial wakeup/free-fall events, as well as by the position of the device itself. Thresholds and timing of interrupt generators are programmable on the fly by the end user. Magnetic and accelerometer parts can be enabled or put in power-down mode separately. The LSM303DLH is available in a plastic land grid array (LGA) package, and is guaranteed to operate over an extended temperature range from -30 to +85 °C. See the table below. (3) Sensor Features  Analog supply voltage: 2.5V to 3.3V.  Digital supply voltage IOs:1.8V.  Power-down mode.  3 magnetic field channels and 3 acceleration channels.  16 bit data out.  I2C serial interface.  2 independent programmable interrupt generators for free-fall and motion detection.  Embedded self-test. Applications  Compensated compassing.  Map rotation.  Position detection.
  • 19. Page | 19  Motion-activated function.  Free-fall detection.  Display orientation.  Vibration monitoring and compensation. In our project, we used this sensor to determine the slope of the road so as to find the actual fuel level even in the tilted roads this is due to the fact that most of our roads are tilted! So we have derived an equation which relates the slope of the tank with the distance from the Ultrasonic sensor to determine the fuel level as accurate as possible. However, the LSM303DLH sensor communicates through the I2C protocol which is differ from the Ultrasonic which is connected to the microcontroller directly, so we provide here some description of this protocol. As for the coding of this sensor, it is attached in the appendix. I2C serialinterface I²C (Inter-Integrated Circuit, referred to as I-squared-C, I-two-C, or IIC) is a multimaster serial single ended computer bus invented by Philips used for attaching low-speed peripherals to a motherboard, embedded system, cell phone or other electronic device. At the low end of the spectrum of communication options for "inside the box" communication is I2C .The name I2C is shorthand for a standard Inter-IC (integrated circuit) bus. I2C provides good support for communication with various slow, on-board peripheral devices that are accessed intermittently, while being extremely modest in its hardware resource needs. It is a simple, low-bandwidth, short-distance protocol. Most available I2C devices operate at speeds up to 400Kbps, with some venturing up into the low megahertz range. I2C is easy to use to link multiple devices together since it has a built-in addressing scheme. (4) 3.1.3 MICROCONTROLLER All kinds of sensors need some device to process its readings and measurements, so it’s common to find in such systems microcontrollers. The common microcontrollers are PIC and ARDUINO. In our project we will use the PIC microcontroller PIC16f877a which is shown in figure 3.1-5.
  • 20. Page | 20 Figure 3.1-6 PIC16f877a These microcontrollers can be connected to more than one sensor and devices such as small DC motors, LCD, computers and GPRS modules. Also theses microcontrollers can be programmed using high level languages in order to operate as the designer wants. The PIC16f877a microcontroller is manufactured by MICROCHIP© company. The oscillator which will be used is a crystal of 4 MHz frequency, which allows us to take number of readings from the sensors per minute in order to get the best and accurate reading in different conditions. The most important feature of the PIC16f877a for this project is the capture property which can trigger or start a timer when the rising edge of the echo signal (from the ultrasonic) reach the microcontroller, then the value of that timer can be directly treated as the time of flight Tf . However more details will be mentioned in Appendix A.1. However, the code of the microcontroller will convert measured distance by the ultrasonic into a volume reading depending on the shape and dimensions of the tank. It is important to mention that each kind of vehicles has its own tank shape and dimensions, so our system will be adaptive such that for each vehicle the dimensions of the tank must be taken into consideration in the programing process of the microcontroller which will be fitted on it.
  • 21. Page | 21 3.1.4 FILTERING & PROCESSING After we did the survey we saw that there is a great importance to stop the fuel theft as well as give accurate readings for the fuel level and in real time. As we said before, the main function of our system to tracks an unusual rate of decrease in the fuel-level and we said too the tracker is sensitive enough to detect when someone tries to 'skim' excess fuel from a vehicles tank. After we stared the project we saw that there are two main limitations to give an accurate reading in real time. Actually the two limitations are the same but in different position and each one required special method to solve. The two limitation leads to dynamic motion of the fuel. And because of the fuel inside the tank will be dynamic, so it is important to take number of readings from the ultrasonic and then make the filtering to it. We will perform the filtering process through the microcontroller such that we will do averaging to these readings and take its average. Then we will compare this reading of the fuel level with another reading after a specific time (this time is determined from the vehicle itself according to its usual consumption rate of fuel) then if the difference is greater than the usual consumption rate of fuel then a warning signal will be sent to the GPRS module which in turn will send it to the appropriate address to alarm for fuel theft. By the way, figure 2.1-4 shows a flow chart for our programed microcontroller. In this part we would like to explain the two limitations and what are the methods which we used to solve these two limitations.  The first problem occurs when the vehicle is moving on a flat road but this road has large Protrusions. See the figures bellow
  • 22. Page | 22 To solve this problem it is important to take number of readings from the ultrasonic sensor and then make the filtering to it. We will perform the filtering process through the microcontroller such that we will do averaging to these readings and take its average. To solve this problem we did a simple averaging for the values because the normal decreasing of the fuel level is small and so no needed to make a complicated filtering. See the below equation Simple filtration equation  The second limitation occurs when the vehicle is moving on a road has some slope (positive or negative) slope. See the figure bellow. Actually we sit some alternatives to solve this problem for example  The first method is to considerate the consumption rate only by reading the fuel level at specific time and then we will compare this reading of the fuel level with another reading after a specific time to calculate the consumption rate according the below equation. If the consumption rate is greater than the usual consumption rate of the vehicle, the microcontroller will send an alarm signal to the database on the company. In this way we can detect the fuel theft which the main function of our project. But the same time we lose an important thing which is know the fuel level in real time and so we will face some error in the fuel consumption.  The second method depends on both the fuel level and the consumption rate at the same time, and here we ignore the first reading (the reading which make a large variation). In this method we set a three probability. 1) Large change in both fuel level and consumption rate. In this case we ensure that there is a fuel theft or some problem in the fuel tank, so the microcontroller will send an alarm signal to the database on the company. 2) Large change in the fuel level and usual change in the consumption rate. In this case we ensure that the vehicle is moving on a road has some slope (positive or negative slope. And here the microcontroller will send an approximate fuel level which equals the previous fuel level (from the microcontroller memory) minus the consumption rate. In this method we give approximation readings, which is good
  • 23. Page | 23 comparing with the other alternatives on the market. But at the same time we faced a big problem in our country “Palestine” because a high percentage of the roads have a large slope, and so this method become un valuable in some cases. 3) Small change on the fuel level and large change on the consumption rate. In this case no probabilities and we ensure that there is a fuel theft from the fuel tank and so, the microcontroller will send an alarm signal to the database on the company.  The last method is depending on the same principle of the second method, but here with more accurate approximation. In this method we make an experiment to compare between the measured level and the slope of the fuel level to calculate the accurate “actual” level depending on the bellow equation. Where: D: the actual distance between the ultrasonic sensor and the fuel level D`: the measured distance between the ultrasonic sensor and the fuel level :the road slope (the measured angle by LSM303DLH sensor) However, we can configure and program the microcontroller to periodically send its reading to the GPRS module in order to allow the company to monitor and save the consumption of the fuel by its vehicle.
  • 24. Page | 24 Figure 3.1-7 Flow Chart for the Microcontroller 3.2 TRANSMISSION OF DATA 3.2.1 GPRS MODULE It is a device used to send data through the wireless communication networks; it needs a SIM card related to the cellular network which provides this service. Fortunately, the local cellular network provides this service with cheap cost. All what we need is to provide each module with a SIM card and connect it to the microcontroller to enable the GPRS module to send the measurements. By the way, the size of GPRS modules is small as shown in figure 3.2-1 which is very suitable for our project. Doesthe falling edge arrived from the echo Measure the echo time from the interrupt (rising edge) Increment counter YESNO Return from interrupt Delay (1 mSec) to allow the echo to interrupt Divide the echo time by 58 to get the distance in cm Convert from binary to decimal Send the reading to the GPRS START Enable Capture mode of the microcontroller Trigger The Sensor (Pulse for 10uS) Measure the echo time from the interrupt (rising edge)
  • 25. Page | 25 Figure 3.2-1 GPRS module 3.2.2 INTERFACING BETWEENTHE GPRS AND THE CONTROLLER PIC-GSM is excellent board for adding remote monitoring and control in remote places by GSM cellular network or Ethernet or internet network. (5) The GSM antenna is built in the board so no need for external expensive GSM antennas. PIC-GSM have two inputs which could be connected to alarm sensors or just buttons for user actions (like call pre-loaded phone numbers), on-board temperature sensor up to 30 meter distance from the module. So we can connect the microcontroller easily to it in order to achieve the communication between them. 3.2.3 TRANSMISSIONUSING GPRS MODULE The readings of the sensor will be sent through the GPRS module to a web server in order to store, process and display the fuel rate consumption for each vehicle to allow the company to benefit as best as possible to identify its budget. 3.3 The Whole system As an overall sight on our system, based on the circumstances mentioned in section 1.4, we have designed our system such that:  The ultrasonic HC-SR04 will be fitted on the surface of the tank with small hole (45X20 mm2) with insolating layer to isolate the connections from the fuel inside the tank, this hole is required to let the ultrasonic waves propagates inside the tank to measure the level of the fuel.  The four pins of the Ultrasonic HC-SR04 will be connected to the microcontroller.  The microcontroller and the GPRS module will be fitted inside the cabin of the vehicle in order to facilitate the maintenance if required.
  • 26. Page | 26 Finally, the needed power for the system will be fed from the battery of the vehicle and since those component of the system is a very low power elements there will be no worry about the consumed power from the battery of the vehicle.
  • 27. Page | 27 CH 4 CONCLUSION ANDOBSERVATIONS 4.1 Experiment on the Sensor At this part, we have tested the performance of the sensor in measuring the distances from different objects. As figures 4.1-1 to 4.1-4 show, the measured distance is displayed on an LCD with the object is a rigid black body, from those pictures we can see that this sensor is very accurate with taking into consideration that the object which we intend to measure its distance must be 2cm away from the sensor as shown in the figures. Figure 4.1-1: 12cm distance from a rigid body Figure 4.1-2: 16cm distance from a rigid body Figure 4.1-3: 20cm distance from a rigid body Figure 4.1-4: 24cm distance from a rigid body 2cm 2cm12cm 20 cm 24 cm 16 cm
  • 28. Page | 28 Also to ensure that the ultrasonic waves of this sensor don’t penetrate the surface of the fuel we have performed this part to measure the distance between the sensor and the surface of the water inside a container of water as shown in figure 4.1-5. Figure 4.1-5: Test of the Sensor on Fluids As drawnon the picture,the distance measuredbythe sensorisexactlythe distancebetweenthe surface of the waterand the sensoras provedfromthe rulerinthe picture. AS a result,we are nowsure that thissensorwill be able tomeasure exactlythe level of the fuel inside the tankandthe ultrasonicwaveswon’tpenetrate the fuel.Finally,the remainingthingistodo the filteringandgetthe propermeasurementwhenthe vehicleisinmotionona tiltedroad. 2c m 5 cm Heightof water inside the container Ultrasonic Sensor 12 cm 17 cm
  • 29. Page | 29 4.2 CONCLUSION As a result of the high cost of the fuel, it is very essential for the companies – which have its own transportation vehicles and vans- to identify and calculate its consumption and expenses on the fuel so as to put their efficient and reliable budget. Also, as we found from the survey, most of the local companies mentioned that it’s very important for them to know as exact as possible their fuel consumption and expenses. Moreover, we found there is a critical need for those companies to protect their vehicles from the fuel theft whoever the thief. From the need of our market in Palestine, we took the first step in our project and then started to combine the main features of our system in order to meet the needs of those companies and foundations. Our duty is to design a ‘smart’ system to mainly detect the fuel theft in various conditions and secondly allow those companies and foundations to know exactly their expenses on the fuel. In the first part of our graduation project, we have studied the circumstances surrounding the environment of the system and then identified the best and reliable components which will be assembled and built in the next part of the graduation project in the next semester. The main part is the sensor responsible to take the level of the fuel inside the tank and we have chosen the Ultrasonic HC-SR04 sensor for that role, then we have selected the PIC16f877a microcontroller to filter and process the Ultrasonic readings, finally we have preferred the GPRS module to transmit the readings to the server of the company in order to store and handle those readings as they want. In the second part of our graduation project, we have built the system, combined the sensors, added new elements like the LSM303DLH, derived mathematical equation to relate the slope of the road with the fuel level, sent the readings to the microcontroller then through the serial port to the computer. One of the problems we faced was the lack and the high cost of the GPRS modules in our market, as a result, we couldn’t perform the transmission using it, instead we have sent the data using the serial port of the computer to a database to simulate the real database of the target company. Finally, based on our study in the electrical engineering department at an-Najah University, we hope to design a valuable and useful system so as to contribute to solving one of the
  • 30. Page | 30 problems which our companies face regarding the fuel theft and consumption, which – to some extent- will help them to do their best in achieving their jobs as better as possible.
  • 31. Page | 31 Bibliography 1. Digital signalprocessing techniquesforaccurateultrasonic. GregorioAndria,FilippoAttivissimo, NicolaGiaquinto.2001, www.elsevier.com. 2. Freaks, ELEC. UltrasonicRanging ModuleHC - SR04. 3. www.sparkfun.com 4. www.robot-electronics.co.uk 5.Ltd, OLIMEX. www.olimex.com. olimex. [Online] june 2008. https://www.olimex.com/Products/PIC/Development/PIC-GSM/. 6. MICROCHIP. PIC16F87X Data Sheet.2001. 7. LSM303DLM Sensormodule:3-axisaccelerometerand 3-axismagnetomete.www.st.com 8. STAR. WH1602D LCD datasheet.
  • 32. Page | 32 APPENDEX A.1: The Code of the PIC16f877a We have written the code in the second part of the project using the PICC language as follows: The ultrasonic code: #include <ultraTest.h> #include <LCD.C> #include <math.h> #use fast_io(B) int32 echo,timer1; // distancein binary float height,area,volume; #int_CCP1 void CCP1_isr(void) { set_timer1(0); clear_interrupt(INT_CCP1); } #int_CCP2 void CCP2_isr(void) { echo =ccp_2; clear_interrupt(INT_CCP2); } void trig() // triger thesensor by 10usec pulseon the triger pin RB#
  • 33. Page | 33 { output_low(PIN_C3); delay_us(3); output_high(PIN_C3); delay_us(10); output_low(PIN_C3); } display() { //printf(LCD_PUTC,"fD=%gcmnV=%gL",height,volume); printf(LCD_PUTC,"f%gcm",height); printf("%g",height); //printf(LCD_PUTC,"fecho=%Luntimer1=%Lu",echo,timer1); } void divide() // convert timeto distanceaccording to thedata sheet oftheultrasonicsensor { if(echo) height =echo/58.0; // distanceis measuredin cmaccording to // the ultrasonic sensor RS323 volume =area*height*0.001; // volume(liter) ofthe fuel provided thatthearea ofthetank is known; } void main() { setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //65.5 ms overflow setup_ccp1(CCP_CAPTURE_RE); setup_ccp2(CCP_CAPTURE_FE); lcd_init();
  • 34. Page | 34 enable_interrupts(INT_CCP1); enable_interrupts(INT_CCP2); enable_interrupts(GLOBAL); //Example blinking LED program while(true){ trig(); delay_ms(1); divide(); display(); // delay_ms(1500); } } The LSM303DLM code: #include "D:adhami2c_testtest.h" #include <LCD.C> #include <LSM303DLH.h> int data; void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED);
  • 35. Page | 35 setup_timer_2(T2_DISABLED,0,1); lcd_init(); // TODO: USER CODE!! enableDefault(); while(1){ readAcc(); printf("n%X",X_H_A); delay_ms(1000); }; } #ifndef LSM303DLH_h #define LSM303DLH_h float m_max_x, m_max_y, m_max_z; float m_min_x, m_min_y, m_min_z; int X_L_A, X_H_A, Y_L_A, Y_H_A, Z_L_A, Z_H_A; int X_L_M, X_H_M, Y_L_M, Y_H_M, Z_L_M, Z_H_M; // address ofacceleometerand magnetometer #define sad_w_a 0x30 //b'00110000' #define sad_r_a 0x31 //b'00110001' #define sad_w_m 0x3C//b'00111100' #define sad_r_m 0x3D//b'00111101' #define ACC_ADDRESS (0x30 >>1) #define MAG_ADDRESS (0x3C >>1) // register addresses #define LSM303DLH_CTRL_REG1_A 0x20
  • 36. Page | 36 #define LSM303DLH_CTRL_REG2_A 0x21 #define LSM303DLH_CTRL_REG3_A 0x22 #define LSM303DLH_CTRL_REG4_A 0x23 #define LSM303DLH_CTRL_REG5_A 0x24 #define LSM303DLH_HP_FILTER_RESET_A0x25 #define LSM303DLH_REFERENCE_A 0x26 #define LSM303DLH_STATUS_REG_A 0x27 #define LSM303DLH_OUT_X_L_A 0x28 #define LSM303DLH_OUT_X_H_A 0x29 #define LSM303DLH_OUT_Y_L_A 0x2A #define LSM303DLH_OUT_Y_H_A 0x2B #define LSM303DLH_OUT_Z_L_A 0x2C #define LSM303DLH_OUT_Z_H_A 0x2D #define LSM303DLH_INT1_CFG_A 0x30 #define LSM303DLH_INT1_SRC_A 0x31 #define LSM303DLH_INT1_THS_A 0x32 #define LSM303DLH_INT1_DURATION_A 0x33 #define LSM303DLH_INT2_CFG_A 0x34 #define LSM303DLH_INT2_SRC_A 0x35 #define LSM303DLH_INT2_THS_A 0x36 #define LSM303DLH_INT2_DURATION_A 0x37 #define LSM303DLH_CRA_REG_M 0x00 #define LSM303DLH_CRB_REG_M 0x01 #define LSM303DLH_MR_REG_M 0x02 #define LSM303DLH_OUT_X_H_M 0x03 #define LSM303DLH_OUT_X_L_M 0x04
  • 37. Page | 37 #define LSM303DLH_OUT_Y_H_M 0x05 #define LSM303DLH_OUT_Y_L_M 0x06 #define LSM303DLH_OUT_Z_H_M 0x07 #define LSM303DLH_OUT_Z_L_M 0x08 #define LSM303DLH_SR_REG_M 0x09 #define LSM303DLH_IRA_REG_M 0x0A #define LSM303DLH_IRB_REG_M 0x0B #define LSM303DLH_IRC_REG_M 0x0C void LSM303DLH() { // These arejustsomevalues for a particular unit; it is recommendedthat // a calibration bedone for your particular unit. m_max_x =+540; m_max_y =+500; m_max_z =180; m_min_x =-520; m_min_y = -570; m_min_z = -770; } // Writes an accelerometer register void writeAccReg(bytesub, byte data){ i2c_start(); i2c_write(sad_w_a); i2c_write(sub); i2c_write(data); i2c_stop(); } // Reads accelerometer register int readAccReg(byte sub){ byte data;
  • 38. Page | 38 i2c_start(); i2c_write(sad_w_a); i2c_write(sub); i2c_start(); i2c_write(sad_r_a); data =i2c_read(); i2c_stop(); return data; } // Writes a magnetometer register void writeMagReg(byte sub, byte data) { i2c_start(); i2c_write(sad_w_m); i2c_write(sub); i2c_write(data); i2c_stop(); } // Reads a magnetometer register byte readMagReg(bytesub) { byte data; i2c_start(); i2c_write(sad_w_m); i2c_write(sub); i2c_start(); i2c_write(sad_r_m);
  • 39. Page | 39 data =i2c_read(); i2c_stop(); return data; } void enableDefault() { // Enable Accelerometer // 0x27 =0b00100111 // Normal power mode, allaxes enabled writeAccReg(LSM303DLH_CTRL_REG1_A, 0x27); // Enable Magnetometer // 0x00 =0b00000000 // Continuous conversionmode writeMagReg(LSM303DLH_MR_REG_M, 0x00); } // Reads the 3accelerometer channels andstores them invector a void readAcc() { X_L_A= readAccReg(LSM303DLH_OUT_X_L_A); X_H_A =readAccReg(LSM303DLH_OUT_X_H_A); Y_L_A = readAccReg(LSM303DLH_OUT_Y_L_A); Y_H_A = readAccReg(LSM303DLH_OUT_Y_H_A); Z_H_A = readAccReg(LSM303DLH_OUT_Z_L_A); Z_H_A = readAccReg(LSM303DLH_OUT_Z_H_A); /* i2c_start(); i2c_write(sad_w_a);
  • 40. Page | 40 i2c_write(LSM303DLH_OUT_X_L_A); i2c_start(); i2c_write(sad_r_a); data =i2c_read(); i2c_stop(); Wire.beginTransmission(ACC_ADDRESS); // assert theMSB oftheaddress to gettheaccelerometer // to do slave-transmit subaddress updating. Wire.send(LSM303DLH_OUT_X_L_A| (1 <<7)); Wire.endTransmission(); Wire.requestFrom(ACC_ADDRESS, 6); while (Wire.available() <6); uint8_t xla =Wire.receive(); uint8_t xha =Wire.receive(); uint8_t yla =Wire.receive(); uint8_t yha =Wire.receive(); uint8_t zla =Wire.receive(); uint8_t zha =Wire.receive(); a.x =(xha <<8 | xla) >>4; a.y =(yha <<8 | yla) >>4; a.z =(zha << 8 | zla) >> 4; */ } // Reads the 3magnetometer channels and stores them invectorm void readMag() {
  • 41. Page | 41 X_L_M= readAccReg(LSM303DLH_OUT_X_L_M); X_H_M =readAccReg(LSM303DLH_OUT_X_H_M); Y_L_M = readAccReg(LSM303DLH_OUT_Y_L_M); Y_H_M = readAccReg(LSM303DLH_OUT_Y_H_M); Z_H_M = readAccReg(LSM303DLH_OUT_Z_L_M); Z_H_M = readAccReg(LSM303DLH_OUT_Z_H_M); /* Wire.beginTransmission(MAG_ADDRESS); Wire.send(LSM303DLH_OUT_X_H_M); Wire.endTransmission(); Wire.requestFrom(MAG_ADDRESS,6); while (Wire.available() <6); uint8_t xhm =Wire.receive(); uint8_t xlm =Wire.receive(); uint8_t yhm =Wire.receive(); uint8_t ylm =Wire.receive(); uint8_t zhm =Wire.receive(); uint8_t zlm =Wire.receive(); m.x =(xhm << 8 | xlm); m.y =(yhm << 8 | ylm); m.z = (zhm << 8 | zlm); */ } // Reads all6 channels oftheLSM303DLH andstores them intheobject variables void read() {
  • 43. Page | 43 We have written the code using the Assembly language. list p=16f877a ; list directiveto define processor #include <p16f877a.inc> ; processor specificvariabledefinitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF ; '__CONFIG' directive is used to embedconfiguration data within.asmfile. ; The labels following thedirectivearelocated intherespective.inc file. ; See respectivedata sheetfor additionalinformationon configurationword. huns EQU 20h tens EQU 21h ones EQU 22h bin_num1 EQU 23h ; variabletostorethedistanceinbinary form bin_num2 EQU 24h rising_tempL EQU 25h rising_tempH EQU 26h falling_tempL EQU 35h falling_tempH EQU 36h count EQU 27h ; counter for delay perposes count_echoL EQU 28h ; LSByte for Echo duration count_echoH EQU 29h ; MSByte for Echo duration temp1 EQU 30h temp2 EQU 31h ;********************************************************************** ORG 0000H GOTO start ORG 0004H goto isr ;--------------------------------------------------------------------- isr btfsc PIR1,2 ; is the interruptfrom CCP1 (rising edge)? GOTO rising ; yes, process rising btfsc PIR2,0 ; no, check theiftheinterrupt is duetoCCP2? GOTO falling ; yes, process falling GOTO finished rising clrf TMR1H clrf TMR1L bcf PIR1,2 RETFIE falling movf CCPR2H,w movwf falling_tempH movf CCPR2L,w movwf falling_tempL bcf PIR2,0 finished RETFIE ; _________________________________________________________________________ start movlw b'11000000' ; enable GIEandPeripheral interrupts movwf INTCON banksel CCP1CON movlw b'00000101' movwf CCP1CON ; capture modeCPP1,every rising edge movlw b'00000100' movwf CCP2CON ; capture modeCCP2, every falling edge MOVLW 01H MOVWF T1CON banksel PIE1
  • 44. Page | 44 movlw b'00000100' movwf PIE1 ; enable CCP1interrupt movlw b'00000001' movwf PIE2 ; enable CCP1interrupt movlw b'00000110' movwf TRISC ; To configure the Capture Mode ofCCP1 and CCP2 clrf TRISB ; RB3 Triger for the ultrasonic banksel PORTB clrf PORTB ;------------------------------------------------------------------------------------ ; main code.................................... new_reading CALL trig ; triger the ultrasonicsensor CALL onems CALL Divide ; divide thetime over 58 toget the distancein binary CALL bintodec ; convert from binary todecimal goto new_reading ;________________________________________________________________________________ ; Subroutines .................................. ; Triger the sensor by10usecpulseon thetriger pin RB3 trig bcf PORTB,3 nob nob nob bsf PORTB,3 ; triger is connectedto POTR B,3 movlw 05h movwf count ; delay for morethan 10us wait_de decfsz count GOTO wait_de bcf PORTB,3 RETURN ;.................................................................. ; divide echo width(i.e. in terms oftime in1usec) over 58to get thedistance in(cm). Divide movf falling_tempL,w ; save the timecounters in orderto redisplay it untilthenext trig movwf temp1 movf falling_tempH,w movwf temp2 movf falling_tempL,w ; check ifthe echo signal dosentreturn btfss STATUS,Z GOTO nonzero movf falling_tempH,w btfss STATUS,Z GOTO nonzero return nonzero movlw d'58' ; put the divisorin W subwf falling_tempL ; count_echo1=count_echo1 -d'58' btfss STATUS,C GOTO Borrow GOTO Div_2 Borrow movlw 01h subwf falling_tempH ; use subtract insteadofdecf btfss STATUS,C ; ... because itsets the carry GOTO Done ; generateda borrow sofinish Div_2 incfsz bin_num1 ; LSByte is saved in bin_num1 GOTO nonzero incf bin_num2 ; MSByte is saved inbin_num2 GOTO nonzero Done
  • 45. Page | 45 movf temp1,w ; return thetimecounters inorder toredisplay it until the next trig movwf falling_tempL movf temp2,w movwf falling_tempH RETURN ;................................................................. ; Convert from binary to decimal .......................... bintodec clrf huns clrf tens clrf ones movf bin_num2,w btfsc STATUS,Z ; is the MSByte oftheechosignal zero? GOTO low_byte ; yes, then go tothelowbytewhichis bin_num1 movlw b'11111110' ; no, then check ifitis morethand'256'=b'00000001' andwf bin_num2 btfss STATUS,Z GOTO outside ; yes, it is morethan d'256'then ;the distanceis more than 400cm i.e.over thesensor's range movlw d'2' ; no, then it equals d'256'so thehundreds is two movwf huns movlw d'50' ; the tens is d'50' addwf bin_num1 movlw d'6' ; the ones is d'6' addwf bin_num1 ;,,,, calculate thehundreds for theLSByteofthe echo signal low_byte bsf STATUS,C ; set carry bit toperformsubtract operations movlw d'100' wait_hunssubwf bin_num1 incf huns btfsc STATUS,C ; does the subtraction becomezero? goto wait_huns ; No, calculatehundreds again addwf bin_num1 ; Yes, add 100to binarynumber to becorrect decf huns ; decrement huns counter tobecorrect ;,,,, calculate thetens bsf STATUS,C movlw d'10' wait_tens subwf bin_num1 incf tens btfsc STATUS,C goto wait_tens addwf bin_num1 decf tens ;,,,, calculate theones movf bin_num1,w ; the ones aretheremaining in bin_num movwf ones outside clrf bin_num1 clrf bin_num2 RETURN ; return to theCALL Binary todecimal bintodec ;........................................................................ END