Fuel Remaining Calculation

Hi there!

I'm building a little vehicle computer based on a Teensy 3.2 board and am wondering how I might be able to work out average MPG and then a "miles to empty" figure.

I have a link into the CAN-BUS so I can pull any PIDs necessary (2019 GM engine so should be latest CAN version). I also will have fuel level analogue in and have a trip and odometer already built in.

I'm thinking that the best way would probably be to look at the injector times and work out the amount of fuel injected over a given sample time, stored with the distance traveled by the car in that time. The data should then be averaged over a given time or distance (maybe the previous 10 minutes or 10 miles?) then an average mpg calculated, then compared with the remaining fuel level to achieve a distance to empty.

First question - are there any better suggestions? I have searched for a while and can't really find any examples of this...

Second question - what would be the best approach to do this with arduino? Perhaps a large array? I'm not really sure how to approach this being quite new to arduino. Does anyone have any suggestions or sample code to take a look at?

Thanks!

My car does something similar... I can choose, instantaneous, average and some other stuff for fuel consumption monitoring.

As for fuel remaining, it will calculate remaining fuel based on level, then calculate the range based on what the engine is consuming at the time. I'm sure there's some sort of averaging going on. I believe at some point it just declares LOW FUEL warning... (2 gallons? maybe)

I'm not sure how it works and I've never tried to work this out, this is based on observation over 10 years... but works well, I've never run out of gas.

The Harley is even easier... I reset my trip A at fill up... look at the gauge and fill up when i get to 100 miles or when the light comes on.

Step #1: Determine if the engine controller intersects with this...

https://www.google.com/search?q=OpenXC

If the answer is "it does" then you are good to go. All the data you need is available. (Though, you will still very likely have to do some work.)