Designed and delivered a prototype for a Brazilian client in need of direct sensing of the fuel level in a Volvo truck.
In the Spring of 2014, I was approached by a client who wanted a hardware sensor and interface for use in monitoring fuel levels in his clients trucks. Most cars and trucks have a fuel sender that floats in the gas tank which monitors the fuel level and sends a voltage signal to the car's gas gauge. My task was to intercept this signal, translate it into a tank percentage value, and transmit the data via both RS-232 and RS-485 protocols. An added twist, there were four possible tank sizes that needed to be configurable. This prototype was successfully delivered to the client.
There were several parts to this project. Part 1. The Hardware: I augmented an Arduino Uno micro controller with the necessary circuitry which included a unity gain high impedance voltage follower circuit, a dip switch array for tank size selection, and components to output the signal in RS-485 format. Photos can be seen below. A PDF version of the schematic can be seen here. Part 2. The Look-up Table: I was supplied with a figure that depicted the layout and values of the resistor network that varied as the float arm moved up and down. I was also given five key data points, the voltage values that should be expected at empty, quarter tank, half tank, three quarter tank and full tank. I used MATLAB, in particular their Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) tool to create a piece-wise smooth curve fit for the data. Cubic and quadratic spline interpolations did not go directly through each point and created unwanted slope inflection points, which made the piece-wise shape preserving method the most useful method for the curve fit. PCHIP preserves the shape of the data and respects monotonicity, which for our case means the voltage in decreasing monotonically as tank percentage goes up. Also, at point where the original function has a local extremum, the interpolation curve will also have local extremum. More about PCHIP here. My steps were are follows:
Step A: Plot the values of Fuel Sender voltage versus tank level (5 values)
Step B: Use basic fitting tools within the plot window to visually inspect different interpolation equations. Attemped using 2nd and 3rd order splines and finally settled with a 'shape-preserving interpolant' called PCHIP (piecewise cubic Hermite interpolation) which had best fit, it ran directly through supplied control points, and each piece-wise section of the curve had each endpoint as both local max and min. In other words, the curve never went above either control point as happened in the first segment using the cubic spline method. See below for two curves that didn't satisfy the problem.
Step C: evaluated piecewise cubic hermite interpolation for x values which represent the percentage values of the tank:
Step D: code values into corresponding ADC equivalent values. The voltage values were then converted to raw ADC values. I referenced the ADC to 3.3V for this application. This raw ADC values can be seen inside the firmwave code on my GitHub page, link here and also at the end of this page. They are housed inside an integer array called: ADCLookUpTable;
Part 3: The Firmware
The code takes a running average of sensor readings and translates them into tank level percentages. The output is in the following format:
Fuel Sender Reading Device Protocol
The device outputs it's data in both RS-232 and RS-485 data standard. Only TX, RX and GND wires are used. For both RS-232 and RS-485 the baud rate is set internally to 9600 baud.
The data is structured as follows:
[Tank Code] [Three Spaces] [Tank level in liters] [Three Spaces] [Tank level in Gallons]
for example, if the device is set to read a passenger vehicle tank, the expected output would be as follows:
PV 30.0 7.92
There is an internal physical switch on the device that can be set to determine the tank size. There are currently 4 tank sizes:
PV – Passenger Vehicle DT – Delivery Truck TT – Trailer truck TM – Trailer Truck Modified
Here is a link to the Schematic of the Project: Schematic
Here is a link to the Arduino firmware code on my GitHub: Firmware
Here are some photos from the project: