# How read/calculate the amount of consumed fuel estimated for a travel?

I read some Question like that but the best that i found is to fill the tank and read how many km you can do with that tank and register it.

But i'm developing an application that read information with phone via the OBD2 port. And i can read type of fuel, engine coolant temp, rpm and speed. Also i know the distance and duration of user travel and i would calculate an estimation if the tank level can be enough for the travel.

It's possible to do that with the obd2 connected with the phone? I don't need very precise value but something that let the user if the fuel can't be enough for the travel.... Like a control every 5 min of some parameters that calculate the consume in real time...

I need some particular Pids of OBD besides rpm, speed, fuel level and fuel type?

EDIT

Here a table with all PIDs in mode 01 (real time data) that i can read if the car support related pid... PIDs table on wikipedia

EDIT 2

I read that is impossible to get distance traveled from obd2...the only thinks that i can read from it (if my car support it) is the PID 015E = Engine fuel rate (L/h). Or i can use the GPS that every tot time (5 min) can find location user and with: travel_total_distance - percur_distance_from_GPS(taken by start distance travel - total_distance_travel that is less every time)....

EDIT 3

I try to use the MAF for calculating Fuel Consumption reading this Link but my car don't support the MAF PID, 0110 i get NO DATA response, so this formula is not good. The only think that is supported to all car is the speed car and with this i can use some inverse formula and get distance traveled.

Speed = Distance/Time, so Distance = Speed x Time.... i get time monitoring using phone from start travel to lecture consuming and calculate the percurred km.... anyway with this method the result is obsolete if car is stopped because 0km/h = no consuming :D :D (and it's wrong)...maybe i can set some standard value if the car is stopped but the motor is on.

instantaneous Distance D = VSS * t/3600

instantaneous Fuel F = 1 /(14.75 * 6.26) * MAF * t/60 instantaneous

MPG = D / F

VSS = Vehicle

Speed Sensor MAF = Mass Air Flow Sensor

Any suggestions?

IMAGE OF APP THAT CALCULATE CONSUMPTION

Legenda translations: Km percorsi = percurred km Livello carburante = Tank level fuel Consumo stimato = stimed consumption Km percorribili = km that the car can percur with the remaining fuel

• Related on StackOverflow: stackoverflow.com/q/17170646/101039 Oct 18, 2017 at 16:23
• Technically the same question, but the answer is just "how to buy and install an ODBII adapter"... mechanics.stackexchange.com/q/27882/12030 Oct 18, 2017 at 16:24
• The key to the calculation is the value from the Mass Air Flow sensor, the vehicle speed, and the proper air/fuel ratio of your vehicles fuel type. Oct 18, 2017 at 16:25
• Yes they are similar but for me not the same...anyway can be helpfull for some steps of my question Oct 19, 2017 at 9:39
• Here is an offhand comment that is not a specific answer, however: If you have a phone that speaks "bluetooth" to an OBD adapter, it most certainly has a GPS capability. I have not been a "developer" for decades, but if you have access to the phone API for the GPS data, most of your hard work will be done. I suspect the interface between that core API and your code would be the hardest part. As others have implied, this mitigates all the "tire pressure/driving style/coasting/parked running" details and becomes a simple question of * calculated GPS distance/fuel % delta* Oct 21, 2017 at 19:57

You are overcomplicating things.

• The car knows how much fuel is left in the tank, that's what the fuel gauge is for, and many (but not all) vehicles relay this info through the OBD2 connector.
• You can also get the mileage through the OBD2 connector.
• Then, do math.

One of my vehicles has a fuel mileage thing included, and I was surprised at how much the instantaneous fuel efficiency changed from coasting to hard acceleration. This information will be useless for what you are intending to do. Instead, just get how much total fuel has been used (either from the last fillup or from the last app reset), just by:

• when you check the fuel level, if it went up, the car got refueled. Save this new fuel level for your next calculations, and store the previous fuel consumed tally if you plan on using it later. Also save the odometer reading taken at this time.
• if the fuel level went down, the car has been driven. Subtract the current fuel level from the last saved fuel level, that's how much fuel was used. If you are resetting your calculations every fillup, use this number. If you are continuing your calculations from the last time the app was reset, add this amount to the previous fuel tally (but don't overwrite the previous fuel tally).
• get the odometer reading and subtract it from the odometer reading at last refueling, that's your distance driven since the last refueling. Also subtract the current odometer reading from the last time the app was reset, that is your trip distance driven.
• Do simple math to get fuel efficiency since last fillup and last app reset (distance / fuel used = MPG, fuel used / distance * 100 = L/100 km)
• If the user inputs the distance needing to be driven for the entire trip, your app can calculate the amount of fuel needed (at the start of the trip), and update this figure every time you take a reading. (miles left / MPG = gallons needed, km left * L/100 km / 100 = litres needed; if the amount of fuel needed is bigger than current fuel level, you will need to make at least 1 more fuel stop)

Don't worry about rpms, uphills, downhills, traffic, headwind, tailwind, sidewind, nowind, rain, snow, hot, dry, good tires, bad tires, stroke length, bore size, spark plug gap, or how long since the driver's last eaten meatloaf. These things affect fuel efficiency, yes, but they are not things you can calculate. There are more things affecting fuel efficiency than the OBD2 connector can tell you about. Just use the fuel used and the distance travelled.

• Hahahahha sir your are the BEST. I'm italian so i need to understand better what you say using some traslater for technical parts and i will try your suggestion. But the only problem about level fuel is the type. Because i can only read the % of fuel tank but not the total liters or Kg for CNG and GPL.... have some suggestion? Or only hands write from user the the level of inputed fuel? Oct 18, 2017 at 18:53
• Sorry can you explain what is MPG? And from obd2 i can't read mileage (for me km percurred)...only the on board car computer can manage Km (distance).... or i'm wrong? Oct 18, 2017 at 19:00
• @Dario "MPG" is the acronym for "miles per gallon," the measure of fuel-efficiency using Imperial units (miles and gallons). "Mileage" is a generic term that means "distance travelled," it can be in miles or km, depending on the computer. :) Oct 19, 2017 at 5:02
• @Dario If you only have the percentage of fuel tank, then require the user to input the size of the fuel tank when they setup a profile for their vehicle. You can probably get a serial number from thew OBD2 connector so people can have multiple profiles in the app, one for each vehicle. :) Oct 19, 2017 at 5:10
• @Dario Sure, that would allow you to calculate range. But I think people would like the know their actual L/100 km. Just ask the user what the fuel tank size is when they create a profile. Oct 20, 2017 at 5:07

Was going to add as a comment but run out of space...

Interesting idea, probably should have patented it before putting it in the public domain, can see this being useful to GPS peeps/MAP peeps.

Anyways I am see this a number of separate needs:

1) tank size and engine size, you need to basically be able to estimate used per stroke and how many strokes you have in the tank.

2) Need to be able to estimate gas used at certain RPM.

3) Need to know how far you get with certain RPMs for a certain quantity of gas.

4) Need to add fuzzy factor for terrain (hills, etc), weather (snow, wind, etc), gas type (high octain, etc), engines running off spec (leaks, etc).

5) Need to know actual gas left in tank (don't have a way of figuring this out) so the app can use this and the above calcs to let you know if you need to fill up. How are you planning to address this?

If it were me I would look at average driving habits (50/60kph in town + 100/120 highway) and get average RPMS at these speeds, and actual measured gas consumption per engine size. You would need to sample many cars - perhaps crowd source it. That is unless there is already published data on this.

Then you have a way of taking the engine size, RPM and historical average data and infer gas use real time. If you hold down the accelerator, the gas use calc will increase and the estimated travel. Sounds like an interesting project, have fun.

• I'm not sure how this gives the OP information about the PID they're requesting? (No, I didn't download you, but pretty sure this is the reason you were.) Oct 18, 2017 at 17:07
• OP is a software developer clearly (see profile). So am I. So was giving my answer from perspective of developer to developer. I don't mind down votes, just giving my opinion. As I mention on outlet, was gonna just post as a comment because I did not have an answer. Would you channel pros have recommended sending private IM to OP instead? Oct 18, 2017 at 17:12
• It's recommended for chatter outside answering the question to take it to a chat room, whether the Pitstop, or creating your own. Oct 18, 2017 at 17:54
• Hi Chris, i don't need patent because a lot of people had same idea like mine :D :D .... the problem is how to calculate the best consume during the travel. My idea is time query from obd and perform calculation for real time data. About fuel level, yes you can see the % of fuel with PID 015E if i'm right. Oct 18, 2017 at 18:58