MPG - miles per gallon
14.7 grams of air to 1 gram of gasoline - ideal air/fuel ratio
6.17 pounds per gallon - density of gasoline
4.54 grams per pound - conversion
VSS - vehicle speed in kilometers per hour
0.621371 miles per hour/kilometers per hour - conversion
3600 seconds per hour - conversion
MAF - mass air flow rate in 100 grams per second
100 - to correct MAF to give grams per second

Is this what other software uses to calculate MPG? Are there other methods?

I just got my OBD2 All-In-One yesterday, and have just started playing around with it and OBD Gauge. I'm going to try and add the above formula to OBD Gauge and see what it gives. I'd really appreciate any info. Thanks

As you can see, the last two terms correct for temperature and pressure. If BARO happens to be from the MAP sensor, then we've got that. If AAT happens to be intake air temperature (IAT), then we've got that. Even if we don't have these values, the result won't be changed by a great deal.

Peak airflow is trickier. The easy and completely inaccurate route to get peak airflow would be to just multiply the engine displacement by RPM (divided by 2, since it takes two revolutions in a 4-stroke engine). However this assumes 100% volumetric efficiency (VE), which is generally not the case. We'd need the map of VE to RPMs, which of course the ECU happily holds within its silicon.

So we're missing a few crucial things. Perhaps we could at least get some value that's proportional to MPG. I'll try some things out.

Anyone else here have any ideas?

1998 Honda Civic LX
In VERY early planning stages now
---------------------------------
Awesome avatar from DannyWork@Flickr

Internal combustion engines are often called aspirated engines because they are "air-breathing" machines. These engines burn a combination of air and fuel mixed at the stoichiometric ratio 14.7 to 1.17 In the past, fuel and air were mixed in the carburetor, relying on the venturi effect of the pipework to render the fuel into an aerosol.18 Modern systems rely on fuel injection, a process governed by the car's engine computer unit (ECU).19 A variety of sensors feed into the ECU providing real-time information so the computer can manipulate engine performance for optimal emissions. The ECU can regulate fuel flow precisely to match air intake or even adjust the spark timing for various RPM and engine loads.

A rough approximation of fuel use can be made through calculations on engine sensor data. Estimates on fuel consumption will be approximately equal to dividing the amount of airflow through the engine by 14.7, the stoichiometric ratio.20 Engine mass airflow may be determined either with an MAF (Mass Air Flow) sensor or through calculations on the MAP (Manifold Absolute Pressure) sensor.

Using these equations, I can compare the fuel requirements for different driving speeds. To collect the necessary data, I configured the DigiMoto software to log data on the engine's RPM, intake temperature and manifold pressure. For the tests, I drove the Jeep at 45, 55, 65 and 75mph along the same stretch of Riverwatch Parkway. To ensure consistency, logging only took place after the appropriate speed was reached and locked into with cruise control.21 During the drive, the windows were left up for consistent aerodynamics and the air conditioning was left off to eliminate extra engine variables. The engine intake added approximately 13° of heat to the ambient air temperature resulting in 103° Fahrenheit (312.5° Kelvin).

So there you have it. I also have a Honda Civic and was wondering how you would calculate instant MPG when you don't have an MAF sensor. From the equation above it looks like you use the RPM, MAP, and intake air temperatures instead. I haven't taken my laptop, OBD-II reader, and car out for a spin yet to test it out but it should give everyone a start...

I'd recommend reading the entire article - it was very interesting. This guy did his research.

and also Bruce Lightner's formula, assumes a perfect stoichiometric combustion of typical gasoline.
It will give reasonable values most of the time.
The results may differ from the correct ones due to:
1. Some (defective) engines may not have a perfectly Stoichiometric tuning.
2. Some gasoline may have different octane grade and modern cars will automatically tune the mixture ratio.
3. In the warm-up and during throttle change, the combustion is not stoichiometric.

Problems 1. and 3. can be corrected if we have access to the Lambda factor, measured from the exhaust gas:

Fuel Mass = Engine Mass Airflow / (Stoichiometric Ratio*Lambda)

I still dont know how to correct problem 2. Any ideas?

A note on Diesel engines:
A Diesel engine does not use stoichiometric combustion.
So, a reasonable approach of the fuel mass can only be achieved with the Lambda correction and the value of 14.5 for the Stoichiometric Ratio.
The density of Diesel fuel is 7.03 lbs/gal.

2. Some gasoline may have different octane grade and modern cars will automatically tune the mixture ratio.

Fuel Mass = Engine Mass Airflow / (Stoichiometric Ratio*Lambda)

JML

The lambda sensors are used to compensate for the varying grades of gasoline (well, they compensate for everything and only look at the composition of the exhaust gases). I suspect your correction calculation would be close enough.

Watch out, I have a soldering iron and a ham radio license (it's worse, it's an extra class license too!) and am not afraid to use them!

MPG - miles per gallon
14.7 grams of air to 1 gram of gasoline - ideal air/fuel ratio
6.17 pounds per gallon - density of gasoline
4.54 grams per pound - conversion
VSS - vehicle speed in kilometers per hour
0.621371 miles per hour/kilometers per hour - conversion
3600 seconds per hour - conversion
MAF - mass air flow rate in 100 grams per second
100 - to correct MAF to give grams per second

Is this what other software uses to calculate MPG? Are there other methods?

I just got my OBD2 All-In-One yesterday, and have just started playing around with it and OBD Gauge. I'm going to try and add the above formula to OBD Gauge and see what it gives. I'd really appreciate any info. Thanks

For the record, the first "one-line" MPG formula above, taken from my Circuit Cellar article, is off by 100! The "4.54" should in fact be "454". The correct formula is:

Note that OBD-II VSS reading is in kilometers/hour and MAF reading is grams/sec times 100.

This formula works very well in a modern automobile because the engine computer spends almost 100% of its time managing the fuel-air-ratio to 14.7, which it can do very well because of the "closed loop" feedback from the O2 sensor(s).

In fact, the accuracy of this method has been proven in literally tens of thousands of gasoline-powered vehicles. Accuracy within a few percent is typical, often limited by the accuracy of the vehicle speed reading (i.e., VSS).

As for other ways of doing this, especially if you don't have a MAF sensor, by knowing the displacement of the engine, and after a simple "calibration" using fuel tank "fill-up" data to find the only unknown, namely the "volumetric efficiency" (VE) of the engine, MAF can be calculated from RPM, MAP and IAT. With VE, one can use the following formulas to calculate a synthetic "mass air-flow" (MAF) in grams per second, all without a MAF sensor, using the "Ideal Gas Law", as follows:

IMAP = RPM * MAP / IAT
MAF = (IMAP/120)*(VE/100)*(ED)*(MM)/(R)

where manifold absolute pressure (MAP) is in kPa, intake air temp (IAT) is in degrees Kelvin, R is 8.314 J/°K/mole and the average molecular mass of air (MM) is 28.97 g/mole. Note that, in the above formula, the volumetric efficiency of the (4-cycle!) engine is measured in percent and the engine displacement (ED) is in liters.

The VE of my 1999 7.4L Chevy Suburban is about 65%. Smaller, higher performance engines can have VE's of 85% or higher.

I would suggest trying to use injector pulse width instead if it is available. Not all engines run at stoich all the time. For instance, some of the lean-burn Civics run closer to 17:1 when cruising. Also, when you floor it and your car goes into open loop, you may be running closer 12:1 to keep from popping your motor. Or before your car is warmed up in the winter, it is probably running open-loop. Wiring in a wide-band O2 sensor to accurately read the A/F ratio in realtime in conjunction with your MAF readings would be more accurate than just assuming you are running at stoich.