Arduino Fuel Theft Detector Project

Hi, guys. I’m building a fuel theft alert to send text messages to the owners phone using a gsm module.
The sensor that detects the fuel drop is the the arduino ultrasonic sensor.
In the arduino void loop i put an if function in there for when the fuel level drops to a certain value. The challenge is the fuel drops when the driver himself is dropping. Im wiring the device so it’s only activated when the ignition is turned off. I want the device to register the new fuel it comes on as the initial. Is there any code i can use.
i’ve tried saving the distance in another variable and adding a value to it in the id loop but that doesn’t work. Help please. i’m defending it on Monday.

I want an unauthorized drop to trigger the alerts.
This unauthorized drop should be at any level the fuel is at. that’s why i want it to register the first level as initial anytime the device comes on. The device comes on when the car ignition goes off. because when driving normal fuel drop(authorized) isn’t supposed to trigger the alerts


#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
#include <NewPing.h>
const int trigPin = 13;
const int echoPin = 10;
float duration, distance;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

void setup()

{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(19200);
SIM900.begin(19200);
delay(2000);
Serial.begin(19200);
Serial.print(“Initializing…”); //setup for gsm shield
lcd.begin(16,2);
delay(2000);
lcd.print(“Initializing…”);

delay(2000);
lcd.clear();

delay(2000);
lcd.print(“Assembling Parts…”);

delay(2000);
lcd.clear();

delay(2000);
lcd.print(“GSM Shield…”);

delay(2000);
lcd.clear();

delay(2000);
lcd.print(“Level Sensor…”);

delay(2000);
lcd.clear();

delay(2000);
lcd.setCursor(0,1);
lcd.print(“Welcome Joe!”);

delay(4500);
lcd.clear();

lcd.setCursor(0,1);
lcd.print(“STATUS:Safe”);

}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = (duration*0.343)/2;

Serial.print("Distance: ");
Serial.print(distance);
Serial.print(“cm”);
delay(2000);

if((distance>=50)&&(distance<=90
))
{

lcd.setCursor(0,1);
lcd.print("Dist: ");
lcd.print(distance);
lcd.print(“cm”);
delay(500);
lcd.setCursor(0,1);
lcd.print(“STATUS: ALERT!!!”);
delay(500);
lcd.clear();

SIM900.println(“ATD +233546368451;”);
delay(10000);
SIM900.println();
delay(1000);
SIM900.print(“AT+CMGF=1\r”);
delay(1000);
SIM900.println(“AT+CMGS="+233546368451"\r”);
delay(1000);
SIM900.println(“CHECK YOUR VEHICLE OR CALL AUTHORITIES”);
delay(1000);
SIM900.println((char)26);
delay(1000);
SIM900.println();
delay(5000);
Serial.println(“SMS sent successfully”);
delay(1000);
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(“cm”);
delay(2000);

lcd.setCursor(0,1);
lcd.print(“STATUS:Safe”);
}
else return;
}

What heppens when you take 3 or more readings in setup, average them and use that number stored in a variable as the initial?

Yeah, it's actually impossible to figure out who dropped fuel. Isn't it convenient just to measure the level of fuel as shown here?

the containers might differ from each other because it’s a fuel tank. So different cars have different tanks

I don’t want just the distance
I want an unauthorized drop to trigger the alerts.
This unauthorized drop should be at any level the fuel is at. that’s why i want it to register the first level as initial anytime the device comes on. The device comes on when the car ignition goes off. because when driving normal fuel drop(authorized) isn’t supposed to trigger the alerts

This seems like what I’ve been looking for
But the codes aren’t attached please

I would not put any type of sensor in your fuel tank.

There is already a float in the tank, since this system only works when the ignition is off, you can insert a T-junction in that wiring and use the float directly.

There are variations, but most fuel floats that I've worked with give you a resistive reading. This is easy to read to the level that you need using it as one leg of a voltage divider and reading it from an analog pin.

You will have to allow 12v from the battery using a MOSFET, but I'm assuming you already have it tapped to there to power the Arduino.

Thanks for your reply
I get you but I can’t change the project now
I’d have to buy some new parts but my project is tomorrow.
This works perfectly and can be added to the tank as an accessory.
Only problem I’ve now is the alert being triggered when the fuel drops at any level after the ignition is off

A tank cup with lock and key not good?

Oh sorry. The guy is selling the project. He has not made the code open-source.

I can tell when someone has NEVER removed a fuel tank and tried to modify it. Have you designed for both metal and plastic fuel tanks?

1 Like

Is this an academic project and not something that will be built in reality?

it’s an academic project

Seems like you need to take an initial reading when the device starts up, and that this line should be based on that initial reading changing.

Yes exactly but i don’t know how to do that
i’ve tried saving the distance in a variable and making another variable the increased distance but still. the device doesn’t even wait for the condition when i do this. it just keeps getting activated.
can you suggest/write a code for me

No

Yes. Start a new file with just code for the distance sensor.
Before the setup of this new program create a variable called initial_distance.
In the setup take a distance reading and store it in the initial_distance variable.
In the loop take a distance reading. If the difference between the initial_reading and the loop reading is greater than some threshold, like 2cm, then raise the alarm on the serial monitor.
Test this program. If it works, then integrate it into your larger program.
If it works

I have a couple of thoughts:

  1. After the ignition goes off the 1st reading should wait at least a 20 seconds or so for the fuel to stop sloshing around.

  2. If someone gets in or out of the car, or loads the trunk the fuel will slosh about and confound your readings.

  3. You would be better off calculating the rate of change of fuel.

  4. For the various tanks; If on installation the installer was asked for the approximate height of the tank, you could use that to determine the % lost if unauthorized removal has/is occurred.

  5. You need to consider the fill action (which is performed with the ignition off).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.