MPGuino MPG Gauge for fuel injected vehicles

I think this is working well enough to call it a creation, so say hello to the MPGuino, part of the efforts for improving energy monitoring.

It has numerous screens that display instant/current trip data simultaneously, or instant/tank data, or jumbo mpg numbers for instant/current/tank, or more detailed tank and current trip data. It is proving to be extremely precise at tracking fuel usage and distance (knock on wood)

There has been quite a lot of input/testing/patience from many people on it that made this possible, and I have to send lots of love to the folks at arduino for making it so easy to get started in microprocessors and to everyone for all their examples that they share.

There are some pretty cool/advanced concepts in the code, sorry it isn't better documented at the moment. But some of the highlights:

Event scheduler: predefine your event functions and schedule the next time they should be called (in milliseconds), very useful for debouncing in an interrupt scheme, and anytime you want to schedule some work.

microseconds and elapsedmicroseconds: functions to get the "current" time in microseconds and to determine the elapsed time in microseconds, not exact microseconds mind you but a couple orders of magnitude more precisely than milliseconds. This arrangement also allows you to time just about any number of events simultaneously regardless of how many timers are on the chip.

*note: these functions required the use of a custom ISR on timer 2, the code does not depend on timer1 or timer0 at all. I hope to add some music/tone functions on timer1 at some point and arduino is in charge of timer0

Arrays of function pointers

Class definitions of Objects


Interrupts for injectors, buttons, speed signal

EProm for storing setup values

Progmem to reduce ram usage

String formatting routines

64 bit math routines (standard ones didn't fit)

double digit display precision (except for bignums)

Button/Screen navigation

Value editor

Non consecutive LCD data pins.

CPU utilization and free ram monitor.

And the code is all "cut and paste" (been trying to keep it as simple as possible to get it loaded)

But of course, the coolest thing about it is that this is a real, genuine, useful mpg gauge that folks are already using to learn to drive more efficiently and save gas for whatever reasons you might have for wanting to do that.

The source is kept here:

Here are a couple installed in my car (you really just need one :) ):

Here is an arduino friendly wiring diagram: Please note that the lcd is upside down

Here is the very first one I built:

They can also be made from scratch for like $20 if you know what you are doing:

More info (installation, details, etc):

Thanks again, Dave.

Event scheduler... I want one!

Can it be broken off and packaged as a library for reuse elsewhere? Perhaps with those microsecond-related functions as well...

re: library, I'm not arduino savvy enough, but help yourself to this implementation. If you can add a function hook to the timer0_millis++ section that the library sets when it is loaded and then coordinate with the timer_0_clock_cycles parts and the appropriate registers then it is doable without using another timer.

FYI, just noticed 0012 was available and I tried loading it. It looks like you can only get the mpguino code to fit with 0011 for now. I really feel like I'm abusing the ide to be running so close to the size limit in 0011 anyway, was worried it might not fit in 0012.

Binary sketch size: 16772 bytes (of a 14336 byte maximum). Is there any obvious things that have grown since 0011 that might be removable? I struggle with the C.

All I know is the list in the announcement in the forum contains some things that are acknowledged to increase sketch sizes.

I'll take a dive in your code and see if I can steal the event scheduler et al. Thanks again!

Great work on this project Dave! Any update on the kit from Spiff?

Thanks Dig,

re: spif, haven’t heard. I’ve raised a little scratch from selling a couple prototypes so I’m working on a kit/pre-fab deal to help fund the project directly (and keep more folks from getting in over their head on the DIY).

very nice - seriously.

but I did grin when I saw the chip with its legs in the air.

Nice project, ugly construction, but if it works that's what counts ;D

Thanks for sharing.


Very nice! I like automotive projects, esp ones that do efficiency stuff.

Just curious though, why is the input being taken from the injector pulses rather than measuring the flow of fuel on the gas line? I know some cars have a bypass fuel system, but that could be handled pretty easily.

Very nice! I like automotive projects, esp ones that do efficiency stuff.

Just curious though, why is the input being taken from the injector pulses rather than measuring the flow of fuel on the gas line? I know some cars have a bypass fuel system, but that could be handled pretty easily.

Not my project of course but if fuel consumption can be determined by the duty cycle of a fuel injector as shown that has to be a whole lot cheaper, simpler and more reliable then any kind of flow meter. Once the initial calibration constant values are known, it's a simple digital input pulse timing routine.


"ugly construction"

LOL, well I'm a get it working first kinda guy, no fair critiquing prototype construction ;)

I have learned a few things since then though:

I've reworked the MPGuino (MPGduino?) a little by separating the display from the "logic" -- the display board can now be mounted separately from the Arduino-side stuff, which should make for smaller and neater installation. Also, I've added a small 2x2 jumper to allow for easier selection of backlight polarity. Finally, I've added a photocell and resistor that can be used to automagically dim the backlight at night, in bad weather, or whenever the interior of the vehicle is "dark" to help preserve night vision or keep the display from being a nuisance/distraction. Schematics and board layouts on my blog:

I was reading my April 2009 copy of IEEE Spectrum (My first, I only recently bothered to pay for membership) and I noticed an article about the MPGuino, so I thought it proper enough to bump it to the top.

It is on page 20, and also online at:


Nice :)

i will take the code pieces displaying the numbers on the LCD, that looks nice 8-)

hey im a do it yourself kinda guy and was wondering if someone could help me out on this project by making a parts list of everything i need to get this thing created. my brother is a programmer so im not real concerned with that so much as that parts i need and how many. if anyone could help out it would be greatly appreciated. thanks -YacMan

You should find everything at the wiki.

I own both Camry and RAV4 (pre 2000 ) and Scangauge doesn't work because the OBD2 connector is not true OBD2 (I guess Toyota felt that they'd rather keep data scanning in-shop. So.. my interest in MPGGuage as a working alternative. My question relates to connection of the MPGGuage. Is it at all possible to connect the MPGGuage through the onboard obd2 rather than running more wires for the connection. I suspect an answer might be that I should find out what the OBD2 onboads pinouts are. Any ideas where I should look for these answers? Thanks