58
SMART Fuel Theft Detector Page | 1

Smart fuel theft detector

  • Upload
    slmnsvn

  • View
    78

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Smart fuel theft detector

SMART Fuel Theft Detector

Page | 1

Page 2: Smart fuel theft detector

An-Najah National University

Page | 2

Page 3: Smart fuel theft detector

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: Smart fuel theft detector

اإلهــــــداء

الرحيم الرحمن الله بسم

الحمد لله رب العالمين القائل في محكم التنزيل " .. قل هل يستوي الذين يعلمون والذين ال يعلمون .. "والصالة والسالم على خير األنام محمد بن عبد الله القائل".. من سلك طريقا يلتمسة .. وفضل العالم على العابد كفضل القمر على سائر فيه علما، سهل الله له به طريقا إلى الجنالكواكب... وأن العلماء ورثة األنبياء" ليسطر بذالك منهاجا ربانيا قائما على حب العلم والتعلم.

بعد التوكل على الله, ومن باب من اليشكر الناس ال يشكر الله, نهدي هذا اإلنجاز المتواضع الذي لطالما استنفذ منا كل الوقت والجهد ليكون بذلك إكليال تتوج به سنوات طوال من الجد والمثابرة,

ماضين بذلك نحو وجه الله الكريم, نحو حياة قائمة على الجد واإلجتهاد والتضحية.

إلهي وخالقيإليك ..

الذي ال يطيب الليل إال بشكره وال يطيب النهار إال بطاعته وال تطيب اللحظات إال بذكره وال تطيباألخرة إال بعفوه وال تطيب الجنة إال برؤيته

.. سيدي وحبيبيإلى

يامن يسيل الدمع من وسط العيون لذكره ويقف الدم بين العروق لمقامه يا من نطمع بشفاعته

محمد صلى الله عليه وسلم

كل من في الوجود بعد الله تعالىإلى ..

سندي وقوتي ومالذي بعد الله, من اثروني على أنفسهم وعلموني معنى الحياة ومعنى الصبروالتفاؤل واألمل

والدي العزيز .. من علمني العطاء بدون إنتظار

أمي الحنون .. رمز الحب وبلسم الشفاء

إخواني وأخواتي ..الذين امدوني بكل اشكال المساندة والمؤازرة فكانوا نعم المعين

أهلي وعشيرتي وأهل بلدي وكل من وقف بجانبي ...

.. الذين وجب علينا شكرهم ووداعهم ونحن نخطوا خطوتنا األولى في غمار الحياة, الذين لمإلىيبخلوا علينا بعلمهم ووقتهم

الذين رأينا فيهم محبة األباء وتواضع العلماء وسماحة األوفياء

الدكتور ماهر خماش رئيس قسم الهندسة الكهربائية

الدكتور عماد بريك

Page | 4

Page 5: Smart fuel theft detector

الدكتور سامر ميالة الذي تفضل بإشرافه على هذا المشروع .. جزاه الله عنا كل خير

و كل أسرة الهندسة الكهربائية في جامعة النجاح الوطنية

الذين مازالوا هناك .. في زنازين الغدر والظلم والقهرإلى

يامن تكتبون الحرية بصمودكم وتلوحون للنصر بصبركم يامن اليتم دفع أعماركم فداءا ألرضالشهداء

نعم..أيها األسرى .. لكم منا الف سالم

أما أنتم.. يا من زرعتم فينا حب البقاء ورسمتم فوهة النصر على امتداد الوطن

نسألكم أن تمدوا األيادي لنستلهم منكم ما يحيينا على ومضات جهادكم

سالم أيها األحياء في ريعان الشهادة

Page | 5

Page 6: Smart fuel theft detector

ContentsACKNOWLEDGMENT...................................................................................................................................2

Table of Figures...........................................................................................................................................2

CH 1 SURVEY............................................................................................................................................2

1.1 THE SURVEY.................................................................................................................................2

1.2 RESULTS AND ANALYISIS..............................................................................................................2

CH 2 Introduction.....................................................................................................................................2

2.1 PROBLEM TO SOLVE....................................................................................................................2

2.2 ABSTRACT....................................................................................................................................2

2.3 METHODOLOGY...........................................................................................................................2

2.4 ENVIRONMENT OF WORK............................................................................................................2

CH 3 SOLUTION........................................................................................................................................2

3.1 FUEL MEASURMENT....................................................................................................................2

3.1.1 THE FIRST PROPER SENSOR (HC-SR04).................................................................................2

3.1.2 THE SECOND PROPER SENSOR (LSM303DLH)…………………………………………………………………16

3.1.3 MICROCONTROLLER..........................................................................................................27

3.1.3 FILTERING & PROCESSING..................................................................................................29

3.2 TRANSMISSION OF DATA……………………………………………………………………………………………………….22

3.2.1 GPRS MODULE……………………………………………………………………………………………………………….22

3.2.2 INTERFACING BETWEEN THE GPRS AND THE CONTROLLER.................................................2

3.2.3 TRANSMISSION USING GPRS MODULE................................................................................2

3.3 The Whole system.......................................................................................................................2

CH 4 CONCLUSION AND OBSERVATIONS…………………………………………………………………………………………….25

4.1 Experiment on the Sensor...........................................................................................................2

4.2 CONCLUSION...............................................................................................................................2

Bibliography................................................................................................................................................2

APPENDEX A.1: The Code of the PIC16f877a...............................................................................................2

Page | 6

Page 7: Smart fuel theft detector

Table of FiguresFigures 1.2-1 The survey results………………………………………………………………………………………………………………7Figure 3.1-1 Ultrasonic principle................................................................................................................13Figure 3.1-2 The HC-SR04 ultrasonic sensor..............................................................................................14Figure 3.1-3 The Principle of Work Ultrasonic Sensor..................................................................................2Figure 3.1-4 Timing Diagram of the Ultrasonic Sensor................................................................................2Figure 3.1-5 The LSM303DLE slope sensor...................................................................................................2Figure3.1-6 PIC16f877a…………………………...................................................................................................17Figure 3.1-7 Flow Chart for the Microcontroller......................................................................................222Figure 3.2-1 GPRS module...........................................................................................................................2Figure 4.1-1: 12cm distance from a rigid body............................................................................................2Figure 4.1-2: 16cm distance from a rigid body............................................................................................2Figure 4.1-3: 20cm distance from a rigid body............................................................................................2Figure 4.1-4: 24cm distance from a rigid body............................................................................................2Figure 4.1-5: Test of the Sensor on Fluids....................................................................................................2

Page | 7

Page 8: Smart fuel theft detector

CH 1 SURVEY

1.1 THE SURVEY

After we choose our project idea we did a short survey about the project to ensure that the system

is important for the owners of transport companies, as well as find out if they have used other devices to solve the problem and how the success of these devices. In addition to that we want to identify the extent of the Palestinian market need for the project and the possibility of marketing it effectively.

Our survey is shown below in Arabic as we distributed it:

تقوم فكرة المشروع على بناء جهاز يعمل على حساب كمية الوقود داخل التنك بشكل دقيق و إرسالها الى مقر الشركة بشكل دوري وصمم الجهاز بطريقة مناسبة تجعله قادرا على تتبع مقدار إستهالك الوقود ومن ثم إكتشاف السرقة عند

حدوثها حيث يقوم بإرسال رسالة فورية تبلغ عن السرقة وكمية الوقود المسروقة. اإلستبيان التالي وضع بطريقة تساعد فريق العمل على توقع كميات الوقود

المسروقة يوميا وساعات السرقة حيث تسهل هذه البيانات من طريقة التعامل معحالة السرقة مع األخذ بعين اإلعتبار جميع الوسائل المتبعة في سرقة الوقود.

ما هي أهمية المعرفة الدقيقة لكميات الوقود المستهلكة بشكل دوري مهم جدامهم محايدغير مهم

الشعور بسرقة الوقودمتأكد من وجود السرقةشاك بوجود السرقة ال علم ليمتأكد من عدم وجود سرقة

في الغالب تكون سرقة الوقودأثناء عمل المركبةخارج ساعات عمل المركبةفي كلتا الحالتين السابقتين

في الغالب تكون سرقة الوقود من قبلسائق الشاحنة)أناس اخرون خارج العمل )أثناء توقف المركبة عن العملال أعلم

Page | 8

Page 9: Smart fuel theft detector

بكم تقدر كمية الوقود المسروقة شهريا .................................................................................................

هل حاولت شراء جهاز يكشف عن أو يمنع من سرقة الوقودنعمال

إذا كانت اإلجابة نعمما هي طبيعة عمل

الجهاز؟.............................................................................................

............................................................................................................................................

ما هو سعر الجهاز؟...........................................................

..........................................هل كان الجهاز فعاال وقادرا على حل المشكلة ؟

نعمال

إذا كانت اإلجابة ال فما هو السبب برأيك ؟ ......................................................................................

........................................................................................................

...........................................هل أنت مستعد لشراء جهاز يكفل لك حل المشكلة ؟

نعممتردد ال أرغب

Page | 9

Page 10: Smart fuel theft detector

1.2 RESULTS AND ANALYISIS

Even our sample was not large enough due to the limited companies and foundations which are near to us, we can say the following:

The majority of companies stated that it is very important for them to identify exactly their expenses on the fuel consumption.

A significant number of the sample suffers from uncertainty in the amount of its fuel consumption.

Some of the companies are sure that there is some kind of fuel theft from their vehicles. Some of the companies have already bought a system to find track the fuel consumption in

their vehicles. Some of the companies mentioned that the fuel theft is performed by persons not from the

drivers.

To understand the survey output see the figures bellow.

Figures1.2-1 the survey results

Page | 10

Page 11: Smart fuel theft detector

As we expected, this phenomena is present and need to a reliable and cost-effective solution which can calculate the fuel consumption and detect the fuel theft if happened.

Page | 11

Page 12: Smart fuel theft detector

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

Page 13: Smart fuel theft detector

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

Page 14: Smart fuel theft detector

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

Page 15: Smart fuel theft detector

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

Page 16: Smart fuel theft detector

CH 3 SOLUTION

3.1 FUEL MEASURMENT

3.1.1 THE FIRST PROPER SENSOR (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 evaluated through the estimation of a phase shift. In this case good performance can be obtained, but a more complex hardware system is necessary.

Page | 16

Page 17: Smart fuel theft detector

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

Page 18: Smart fuel theft detector

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 =inchor 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.

3.1.2 THE SECOND PROPER SENSOR (LSM303DLH)

Page | 18

Page 19: Smart fuel theft detector

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. Motion-activated function. Free-fall detection. Display orientation.

Page | 19

Page 20: Smart fuel theft detector

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 serial interface

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

Page 21: Smart fuel theft detector

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

Page 22: Smart fuel theft detector

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

Page 23: Smart fuel theft detector

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

Page | 23

Page 24: Smart fuel theft detector

consumption rate. In this method we give approximation readings, which is good 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 levelD`: 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

Page 25: Smart fuel theft detector

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)

Does the falling edge arrived

from the echo

Measure the echo time from the interrupt (rising edge)

Increment counter

YESNO

Return from interrupt

Figure 3.1-7 Flow Chart for the Microcontroller

3.2 TRANSMISSION OF DATA

3.2.1GPRS 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.

Page | 25

Page 26: Smart fuel theft detector

Figure 3.2-5 GPRS module

3.2.2INTERFACING BETWEEN THE 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.3TRANSMISSION USING 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

Page 27: Smart fuel theft detector

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

Page 28: Smart fuel theft detector

12cm

2cm

2cm16 cm

20 cm 24 cm

CH 4 CONCLUSION AND OBSERVATIONS

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-6: 12cm distance from a rigid body Figure 4.1-7: 16cm distance from a rigid body

Figure 4.1-8: 20cm distance from a rigid body Figure 4.1-9: 24cm distance from a rigid body

Page | 28

Page 29: Smart fuel theft detector

2cm

5 cmHeight of water inside the container

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-10: Test of the Sensor on Fluids

As drawn on the picture, the distance measured by the sensor is exactly the distance between the surface of the water and the sensor as proved from the ruler in the picture.

AS a result, we are now sure that this sensor will be able to measure exactly the level of the fuel inside the tank and the ultrasonic waves won’t penetrate the fuel. Finally, the remaining thing is to do the filtering and get the proper measurement when the vehicle is in motion on a tilted road.

Page | 29

Ultrasonic Sensor

12 cm

17 cm

Page 30: Smart fuel theft detector

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

Page 31: Smart fuel theft detector

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

Page 32: Smart fuel theft detector

Bibliography1. Digital signal processing techniques for accurate ultrasonic. Gregorio Andria, Filippo Attivissimo, Nicola Giaquinto. 2001, www.elsevier.com.

2. Freaks, ELEC. Ultrasonic Ranging Module HC - 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 Sensor module:3-axis accelerometer and 3-axis magnetomete. www.st.com8. STAR. WH1602D LCD datasheet.

Page | 32

Page 33: Smart fuel theft detector

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; // distance in 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);

}

Page | 33

Page 34: Smart fuel theft detector

void trig() // triger the sensor by 10usec pulse on the triger pin RB#

{

output_low(PIN_C3);

delay_us(3);

output_high(PIN_C3);

delay_us(10);

output_low(PIN_C3);

}

display()

{

//printf(LCD_PUTC,"\fD=%gcm\nV=%gL",height,volume);

printf(LCD_PUTC,"\f%gcm",height);

printf("%g",height);

//printf(LCD_PUTC,"\fecho=%Lu\ntimer1=%Lu",echo,timer1);

}

void divide() // convert time to distance according to the data sheet of the ultrasonic sensor

{

if(echo) height = echo/58.0; // distance is measured in cm according to

// the ultrasonic sensor RS323

volume = area*height*0.001; // volume(liter) of the fuel provided that the area of the tank 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);

Page | 34

Page 35: Smart fuel theft detector

lcd_init();

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:\adham\i2c_test\test.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);

Page | 35

Page 36: Smart fuel theft detector

setup_timer_1(T1_DISABLED);

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 of acceleometer and 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

Page | 36

Page 37: Smart fuel theft detector

#define LSM303DLH_CTRL_REG1_A 0x20

#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_A 0x25

#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

Page | 37

Page 38: Smart fuel theft detector

#define LSM303DLH_OUT_X_L_M 0x04

#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 are just some values for a particular unit; it is recommended that

// a calibration be done 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(byte sub, byte data){

i2c_start();

i2c_write(sad_w_a);

i2c_write(sub);

i2c_write(data);

i2c_stop();

}

// Reads accelerometer register

int readAccReg(byte sub){

Page | 38

Page 39: Smart fuel theft detector

byte data;

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(byte sub)

{

byte data;

i2c_start();

i2c_write(sad_w_m);

i2c_write(sub);

i2c_start();

Page | 39

Page 40: Smart fuel theft detector

i2c_write(sad_r_m);

data = i2c_read();

i2c_stop();

return data;

}

void enableDefault()

{

// Enable Accelerometer

// 0x27 = 0b00100111

// Normal power mode, all axes enabled

writeAccReg(LSM303DLH_CTRL_REG1_A, 0x27);

// Enable Magnetometer

// 0x00 = 0b00000000

// Continuous conversion mode

writeMagReg(LSM303DLH_MR_REG_M, 0x00);

}

// Reads the 3 accelerometer channels and stores them in vector 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();

Page | 40

Page 41: Smart fuel theft detector

i2c_write(sad_w_a);

i2c_write(LSM303DLH_OUT_X_L_A);

i2c_start();

i2c_write(sad_r_a);

data = i2c_read();

i2c_stop();

Wire.beginTransmission(ACC_ADDRESS);

// assert the MSB of the address to get the accelerometer

// 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 3 magnetometer channels and stores them in vector m

void readMag()

Page | 41

Page 42: Smart fuel theft detector

{

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 all 6 channels of the LSM303DLH and stores them in the object variables

void read()

Page | 42

Page 43: Smart fuel theft detector

{

readAcc();

readMag();

}

#endif

Page | 43

Page 44: Smart fuel theft detector

We have written the code using the Assembly language.

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.; The labels following the directive are located in the respective .inc file.; See respective data sheet for additional information on configuration word.

huns EQU 20htens EQU 21hones EQU 22hbin_num1 EQU 23h ; variable to store the distance in binary formbin_num2 EQU 24hrising_tempL EQU 25hrising_tempH EQU 26hfalling_tempL EQU 35hfalling_tempH EQU 36hcount EQU 27h ; counter for delay perposescount_echoL EQU 28h ; LSByte for Echo durationcount_echoH EQU 29h ; MSByte for Echo durationtemp1 EQU 30htemp2 EQU 31h;**********************************************************************ORG 0000HGOTO start

ORG 0004Hgoto isr;---------------------------------------------------------------------isr

btfsc PIR1,2 ; is the interrupt from CCP1 (rising edge)?GOTO rising ; yes, process risingbtfsc PIR2,0 ; no, check the if the interrupt is due to CCP2?GOTO falling ; yes, process fallingGOTO finished

risingclrf TMR1Hclrf TMR1Lbcf PIR1,2RETFIE

falling movf CCPR2H,wmovwf falling_tempHmovf CCPR2L,wmovwf falling_tempLbcf PIR2,0

finished RETFIE

; _________________________________________________________________________

startmovlw b'11000000' ; enable GIE and Peripheral interruptsmovwf INTCONbanksel CCP1CONmovlw b'00000101'movwf CCP1CON ; capture mode CPP1, every rising edgemovlw b'00000100'movwf CCP2CON ; capture mode CCP2, every falling edgeMOVLW 01HMOVWF T1CON

Page | 44

Page 45: Smart fuel theft detector

banksel PIE1movlw b'00000100'movwf PIE1 ; enable CCP1 interruptmovlw b'00000001'movwf PIE2 ; enable CCP1 interruptmovlw b'00000110'movwf TRISC ; To configure the Capture Mode of CCP1 and CCP2clrf TRISB ; RB3 Triger for the ultrasonicbanksel PORTBclrf PORTB

;------------------------------------------------------------------------------------; main code ....................................new_reading

CALL trig ; triger the ultrasonic sensorCALL onemsCALL Divide ; divide the time over 58 to get the distance in binaryCALL bintodec ; convert from binary to decimal

goto new_reading;________________________________________________________________________________; Subroutines ..................................; Triger the sensor by 10usec pulse on the triger pin RB3

trig bcf PORTB,3nobnobnobbsf PORTB,3 ; triger is connected to POTR B,3movlw 05hmovwf count ; delay for more than 10us

wait_de decfsz countGOTO wait_debcf PORTB,3RETURN

;..................................................................; divide echo width (i.e. in terms of time in 1usec) over 58 to get the distance in (cm).

Divide movf falling_tempL,w ; save the time counters in order to redisplay it until the next trigmovwf temp1movf falling_tempH,wmovwf temp2

movf falling_tempL,w ; check if the echo signal dosent returnbtfss STATUS,ZGOTO nonzeromovf falling_tempH,wbtfss STATUS,ZGOTO nonzeroreturn

nonzeromovlw d'58' ; put the divisor in Wsubwf falling_tempL ; count_echo1 = count_echo1 - d'58'btfss STATUS,CGOTO BorrowGOTO Div_2

Borrow movlw 01hsubwf falling_tempH ; use subtract instead of decfbtfss STATUS,C ; ... because it sets the carryGOTO Done ; generated a borrow so finish

Div_2 incfsz bin_num1 ; LSByte is saved in bin_num1GOTO nonzeroincf bin_num2 ; MSByte is saved in bin_num2GOTO nonzero

Page | 45

Page 46: Smart fuel theft detector

Done movf temp1,w ; return the time counters in order to redisplay it until the next trig movwf falling_tempLmovf temp2,wmovwf falling_tempH

RETURN ;.................................................................; Convert from binary to decimal ..........................

bintodec clrf hunsclrf tensclrf ones

movf bin_num2,wbtfsc STATUS,Z ; is the MSByte of the echo signal zero?GOTO low_byte ; yes, then go to the low byte which is bin_num1movlw b'11111110' ; no, then check if it is more than d'256' = b'0000 0001'andwf bin_num2btfss STATUS,ZGOTO outside ; yes, it is more than d'256' then

;the distance is more than 400cm i.e. over the sensor's rangemovlw d'2' ; no, then it equals d'256' so the hundreds is twomovwf hunsmovlw d'50' ; the tens is d'50'addwf bin_num1movlw d'6' ; the ones is d'6'addwf bin_num1

;,,,, calculate the hundreds for the LSByte of the echo signal

low_byte bsf STATUS,C ; set carry bit to perform subtract operationsmovlw d'100'

wait_huns subwf bin_num1incf hunsbtfsc STATUS,C ; does the subtraction become zero?goto wait_huns ; No, calculate hundreds againaddwf bin_num1 ; Yes, add 100 to binary number to be correctdecf huns ; decrement huns counter to be correct

;,,,, calculate the tensbsf STATUS,Cmovlw d'10'

wait_tens subwf bin_num1incf tensbtfsc STATUS,Cgoto wait_tensaddwf bin_num1decf tens

;,,,, calculate the onesmovf bin_num1,w ; the ones are the remaining in bin_nummovwf ones

outside clrf bin_num1 clrf bin_num2

RETURN ; return to the CALL Binary to decimal bintodec;........................................................................END

Page | 46