@Gryd3: I think the Arduino is "overkill" for an embedded microprocessor project as simple as this one, but it is (1) what the OP has; (2) is fairly easy to get up and running; (3) is "supported" by zillions of sketches available for free download to help point the way; and (4) has plenty of I/O bits made easily available for external use on easy-to-jumper pins. Plus, it takes dozens of "shields" that do all sorts of interesting things, available from a slew of manufacturers. It's like a Tinker Toy set for computers. Most (okay: all) sketches will have to be modified to suit a particular application, meaning the OP will need to learn the limited version of C/C++ language supported by the Arduino compiler. But professional programming or coding experience is definitely NOT required. So, I think he made a good choice with which to start out and get his feet wet (so to speak).
As a personal preference, I would much rather the OP learn assembly for the Microchip PIC series of reduced instruction set computers (RISC) because it gets you much closer to the hardware. You can also program PICs using a free Microchip C compiler (as
@chopnhack does) with virtually no penalty in code execution time. There are also better optimizing (but not free) C compilers for PICs if you are really serious about NOT using assembly. Either way, there will be a learning curve for the software aspect. And another learning curve connecting up the MOSFETs to a resistor network to produce a (more or less) linearly variable resistor. One disadvantage (if you don't roll your own) is the requirement for a programming pod such as the Microchip PICKit 3 or the older PICKit 2. The Arduino of course downloads your compiled program to non-volatile memory on the AVR microcontroller using a small "bootstrap" program that is embedded in the AVR chip and is "ready-to-go" as soon as you connect the Arduino to the USB port on your computer.
I would have thought a programmable current sink or source would work wouldn't it. This effectively alters it's resistance by drawing or supplying more or less current dependant on the voltage setting on the input. Not that familiar with fuel gauges so might not work.
Adam
After giving it some thought, and doing some research on how
some analog moving-needle fuel gauges typically work, I think a programmable current sink could be made to work. I don't think this is an easy or viable solution compared to a simple resistor network.
@Calabashmc: It seemed to me that a switched resistor network would be simpler, and I still think it is. But not as simple as I first thought. I don't know how to make a binary-controlled variable resistance network without putting a switch contact across each resistor to switch it in and out. That complicates things because it's not just a matter of grounding or not grounding a resistor with a MOSFET, which at first I thought was all you needed. If you string a bunch of resistors in series, placing a MOSFET switch across each one brings on a big problem of how to drive the gate of each MOSFET. The simple solution to that is to use isolated reed relay switches. You may still need a MOSFET to drive the coil of the reed relay, depending on relay-coil voltage and current requirements.
So, let's face up to the fact that putting switch contacts in parallel with resistors connected in series, and selected to have values in an increasing
binary sequence, is not only sufficient but it is also necessary.
The solution is inexpensive reed relays controlling a binary-valued resistor chain whose total series value adds up to 90 ohms. If only five bits of analog conversion are used (providing 32 discrete fuel-gauge readings between empty and full) this might be the simplest solution: 45 Ω, 22 Ω, 11 Ω, 5 Ω, and 2 Ω resistors in series will add up to 85 ohms, which is probably close enough to 90 ohms. The string could be trimmed to add up to exactly 90 ohms by inserting a 100 Ω trim potentiometer in place of the 45 Ω resistor. Hook-up these five resistors in series, with a reed-relay switch connected across each one, and short-out the resistors with the reed relays actuated in a binary sequence. The reed relay coils can probably be directly driven with the Arduino digital outputs, but if not, the 2N7000 MOSFETs will drive the coils.
Drive the five relay coils with the five most significant digits of the Arduino A/D output and there you have it. Or Bob's your Uncle. It probably won't be a linear or monotonic variable resistance unless the resistor values are tweeked for good binary ratios... total resistance divided by 2, 4, 8, 16, and 32 for the five resistors. It becomes really difficult to extend the precision of this method to six or more bits of resolution. The binary ratios require ever better and more exact values if monotonicity is to be preserved.
Five bits is a good practical limit for a home-constructed, binary controlled, variable resistor. If you can tolerate a higher minimum resistance, commercial
digital potentiometer products (such as Microchip's MCP41100 you linked to earlier) are available at reasonable cost.
Advantage of the method described above is it has no ground to worry about. It's just a string of five resistors connected in series, along with five relays whose normally-open contacts are connected across the resistors. Disadvantage is the relatively slow response of the reed relays. Fuel-gauge update rate should be limited to less than ten updates per second to avoid excessive relay chatter. Digitizing the analog input to eight bits and keeping only the five most significant bits helps minimize chatter too, but there isn't much that can be done with fuel sloshing around in the tank and creating large variations in the ultrasonic-derived fuel-level sensor.
@Gryd3: My main concern was size, although the Arduino AVR technology is available installed on a tiny board, to which you would have to add the switched resistor network and reed relays on a separate board. I have a couple of Arduino UNOs to play with, along with several shields and two Zigbee transceivers. They make "what if" projects pretty simple and easy to breadboard, but the final result is not very compact. I use them for "proof of concept" mostly. For this project a prototyping shield, such as this
Arduino Protoshield, should be used for mounting and connecting the five resistors and five reed relays. Here is an
example SPST reed relay whose coil can be driven directly by an Arduino digital output pin.
The PICs (I have several versions of those too) require a bit more head scratching because Microchip always crams twelve pounds of stuff into a twelve ounce bag. You have to be on your toes to know what is enabled automagically on power-up, what you have to specifically disable if you don't want to use the default start-up condition, which pins can be used and for what they can used (all the pins have multiple functions... if they could figure out how to do it, Microchip would multiplex power and ground on one pin and then use that pin for I/O too), what happens after a reset or interrupt occurs... yada, yada, yada. It's all there in the Microchip datasheets, but not particularly organized as a tutorial. You have to dig for it. Still, for most embedded microprocessor projects, it's hard to beat the PIC form-factor and its built-in capabilities. I am a huge fan-boy for Texas Instruments products, the MSP430 series in particular, but I reserve those for rather more complicated embedded applications. The Microchip PIC comes in ridiculously complicated and sophisticated versions, too, but I haven't gone there yet.
But let's see how well
@Calabashmc does with the Arduino. We don't want to hand him schematics and a parts list, do we? Where's the fun in that?