What is the best way to get fuel consumption (MPG) using OBD2 parameters.
Below formula is simple but not most accurate, any other formula to get an accurate estimation. The value for vehicle speed is delivered in Km/Hr, to convert to miles multiply by 0.621317. To calculate MPG divide the MPH by GPH. The final math expression for MPG will be:
For Gasoline Engine
MPG =VSS * 7.718/MAF
I would like to know for Diesel Engine to calculate instant consumption. Also I am trying to calculate it independent of car model from parameter available from obd2 standard.
Some links which might be useful for those who are looking into same topic.
That's the formula for instant consumption.
If you want to work out average consumption, work out the total volume of fuel used over time and divide by the total distance traveled over the same period.
UPDATE: That is what the ratio SHOULD be. unless you want to melt pistons or lose power. The air/fuel ratio isn't supposed to change unless you change the type of fuel, e.g. to 102 octane Petrol or Ethanol. That calculation is probably the most accurate you'll get unless you want to make it horribly complex by
Mind you, on the off-chance you're working on a Toyota: Toyota has an extra sensor that actually measures how much fuel is being injected into the engine. So you can just read that PID. But for other cars, the given formula is the standard.
UPDATE 2: some common Air/Fuel Ratios:
You'll also need to consider that when the engine is under high loads, the Air/Fuel ratio changes downward.