What is a fuel level sensor and how to change it? Capacitive fuel level sensor on ATMega8A Assemble a digital fuel level sensor with your own hands

The microcontroller circuits discussed below display readings from a 40L fuel sensor on a two-digit digital indicator with a common anad. The structures are powered from the vehicle's on-board network. The original car sensor in the tank is connected to the “in” input.

Design calibration: When we press the button, flashing zeros will appear on the digital indicator, this means that we have an empty tank. If it really is out of fuel, press the button again. If there is gasoline in it, you need to pump it out and press the button.


The display should show 02 (2 liters) - fill strictly two liters and press the button. Then code 04 lights up, add another 2 liters and press the button.

Next, we proceed in the same way for all values ​​​​on the indicators. After calibration, 40 will appear on the display, which means 40 liters of gasoline in the tank (because that’s how it is) and the flashing will stop. The device has entered measurement mode. We don’t touch the button anymore so as not to reset the settings. When the car fuel level drops below six liters, the display begins to flash, this prompts the driver to stop at a gas station. From the link above you can get firmware with different calibration steps, as well as a drawing of the printed circuit board.

The board has three contacts - two of them receive power supply (connector J2). Input J1 is connected to the measuring contact of the standard indicator. Since the device is connected in parallel, there is no need to make any changes to the vehicle's wiring.

Calibration After the firmware is installed, the controller program has a test setting and when a voltage in the range of 0..15 V is received at the input, it should show on the display from 0..40L. Therefore, a working calibration of the readings is required. In the case of minimal calibration, two points are required - an empty and a full tank. A maximum of 64 points can be calibrated. The tank must be completely empty at the start of calibration. To enter this mode, press and hold the "Calibrate" and "Minus" buttons and apply power. Three lines should appear on the display - this means that the microcontroller has reset the old values ​​and is ready to memorize new ones.

Then we do everything exactly according to the instructions.


Soon it will be a year since I posted mine on Datagor and it’s been more than two years since I myself have been using this indicator. And it has never let me down, going to a gas station when there are 2-3 liters left in the tank has become the norm, and this is not extreme or window dressing, when you know that these 2 or 3 liters are definitely there and that they will be enough to get to the next few gas stations you treat take this calmly, no comparison with the flashing light of a standard device.
This is where I end my philosophizing - let's get down to business!

It’s probably not clear why version V.3 actually existed when there was no version 2, here it is


But it turned out to be unsuccessful; switching stabilizers on the MC33063 were used for power supply, which produce ripples in both directions and I was never able to get rid of them. And since the idea of ​​​​creating a KIT appeared, it was decided to make a new version, with reliable power supply, with protection of all input circuits and on parts that meet operating conditions, first of all, a temperature range of -40..+125°C.
This is how the new 3rd version appeared, made according to almost all the rules, with updated firmware.

KIT, unfortunately, was not in demand, but a lot of time was spent on it, and now it is collecting dust on the shelf, or rather in its folder.
And so that the work does not go to waste, I am posting all the documentation on the project, I will be glad if it is useful to someone.

From Igor (Datagor):
When analyzing personal correspondence, comments to the first article and after conducting sample surveys, it was found that people want not only a very high-quality gas meter, but also a watch with an alarm clock, etc. and so on (and there was a little Chinese inside and running for beer), which turns this wonderful and completely independent development into another on-board computer (BC). At the same time, people wanted to pay no more than 500 rubles for this bookmaker in assembled form. And this won’t fit through any gates at all...
We didn’t create a bookmaker and didn’t open a subscription to the whale against such a sad background.
Dear Sergei (HSL), in any case - our honor and thanks!
The quality of his developments is at the highest level.

So, in order...

Scheme

Processor block diagram, there are 2 modifications A5 and A2
Scheme A5

Scheme A2


The difference is in the connection of the AREF signal (reference voltage), in option A5 it is taken from the +5V power bus, in option A2 it is taken from an internal source.
The main modification is A5, A2 was made to expand the functionality in case it is not possible to calibrate the tank with the main modification.
On the board this is done by different installations of elements R11, C4, C6; this will be described in more detail below in the instructions.
The display board connector is also used for in-circuit programming

Display block diagram


This unit turned out to be universal, it contains a display, controls, and a stabilizer for powering the display, so it can be used with other devices.

Boards

CPU board


The connector for connecting the display board is also used for in-circuit programming of the MK.

Display board


The display is connected via a standard connector and attached to the board with double-sided tape.

Specifications

Supply voltage 8-30 V
Night mode backlight activation voltage 10-20 V
Fuel sensor resistance (recommended) 250-500 Ohm
Voltage display resolution 0.1 V
Display voltage range 8 -30 V
The resolution of displaying the amount of fuel is 1 liter.
Supported tank capacity range 30-99 l.
Inertia range 1-10 sec.
Range of brightness gradations 0-255 units.
Contrast gradation range 1-15 units.

Device main mode capabilities

Digital fuel level and voltage indicator allows you to control:
  • The on-board network voltage is displayed with an accuracy of up to 0.1 volts, the permissible operating voltage range is 8-30 Volts.
  • The remaining fuel in the tank is displayed with an accuracy of 1 liter, the permissible measurement range is 30-99 liters. The recommended resistance of the sensor in the tank is 250-500 Ohms.
  • The device is connected to the following points: ground, power, sensor in the tank, dashboard lighting or dimensions.

Device customization options

  • Possibility of setting the tank capacity from 30 to 99 liters.
  • Possibility of liter calibration of the selected container.
  • The ability to smooth out the effects of the sensor swinging in the tank by measuring the fuel level ten times and displaying the average value, with a choice of measurement time from 1 to 10 seconds.
  • The ability to set the brightness of the display backlight separately for day and night operation. The operating mode is determined by the fact that the dimensions and dashboard lighting are turned on.
  • Ability to set normal or inverse display mode.
  • Ability to set display contrast level.

Description of the operation and controls of the device

Controls


Control is carried out by buttons Menu, Ok, Up, Down
Menu– in the main mode, enter the settings mode. In settings mode, return to the previous menu without saving current changes and exit settings mode.
Ok- Valid only in setup mode. Entering the selected item, saving current parameters in non-volatile memory.
Up– Valid only in setup mode. Move up through menu items, increase the current value.
Down– Valid only in setup mode. Move down through menu items, decrease the current value.

Operating modes
Basic mode


The device enters the main mode 2 seconds after supply voltage is applied to it. The voltage readings appear immediately, the remaining fuel readings appear with a delay due to the inertia setting, 1-10 seconds.

Settings mode


The settings mode is designed to configure the device for specific operating conditions. The settings mode is entered using the button Menu

Menu items
Tank capacity


allows you to set the volume of the tank used. Menu buttons Up/Down varies from 30 to 99 liters. To save the selected volume, press the button Ok. To exit to the menu without saving the changes made, you must press the button Menu.

Calibration


allows you to calibrate the tank capacity by liter. Calibration is carried out after selecting the required tank volume in the menu Tank capacity.
Liters– at this point, use the buttons Up/Down The required liter cell value is set to record the calibration value. The calibration value is recorded using the button Ok.
Sensor– shows the current value of the residue sensor
fuel. When the button is pressed Ok this value is entered into the current memory cell selected in the menu item Liters.
In memory– shows the value stored in memory corresponding to the currently selected value in item Liters,memory cell.

Inertia


allows you to set the period for measuring the remaining fuel. Menu buttons Up/Down varies within 1 - 10 seconds. During the selected period of time, at regular intervals, 10 measurements of the remaining fuel are taken, after which the average value is calculated.

Backlight


allows you to set the brightness of the backlight during the day and at night. The fact of day and night is determined by turning on the dimensions and the dashboard lighting. Buttons Up/Down select the desired item for Day/Night adjustment. To enter the mode for changing the selected value, you must press the button Ok, then press the buttons Up/Down set the required backlight brightness value from 0 to 255. To save the set value, press the button Ok, to exit the current item without saving changes, you must press the button Menu.

Inversion


allows you to select the normal/inverse display mode. The desired item is selected using the buttons Up/Down. The selected value is saved using the button Ok. Exit the current item without saving changes using the button Menu.

Contrast


allows you to set the desired display contrast. Menu buttons Up/Down varies from 1 to 15. The selected value is saved using the button Ok. Exit the current item without saving using the button Menu.

Connection and initial setup


Connect the device according to the markings.
[-] Ground, to connect the ground it is advisable to choose a reliable contact.
[+] Plus the on-board power supply, 12 volts, is connected to any point on the on-board network after the ignition switch.
[G] Dimensions, connects to the power supply circuit of the dimensions or dashboard lighting
[F] Fuel sensor, to eliminate the influence of the original sensor, it is advisable to disconnect it and connect the device directly to the sensor line in the tank.
Turn on the ignition, connect a voltmeter in parallel to the power supply and
check the voltage readings of the indicator, if necessary, adjust the indicator readings with a trimming resistor R2

Published 09/25/2012

Knowing the fuel level in the tank is not only “cool,” but sometimes vital. In some cases, it is difficult to assess the fuel level in the tank due to its location or lack of transparency. For such cases, there are fuel level sensors. Today, float sensors are the most common. The operating principle of such sensors is quite simple. The float mechanism, depending on the fuel level in the tank, changes the position of the moving contact of the potentiometer. The voltage reading on the potentiometer is measured and converted into human-readable form. However, it is not always possible to install a float sensor due to its size. In addition, in devices where roll is a normal condition, for example, ultralight aircraft, the float mechanism may become skewed and jammed. In addition, the position of the tank in the ground and flight positions may differ, which may alter the operation of the float mechanism. However, there are other ways to measure fuel level. I'm talking about capacitive fuel sensor. It is especially relevant if there is a need to get rid of moving parts.

Measuring principle and features

This method is based on measuring the electrical capacitance of the sensor, which, in turn, depends on the fuel level. The sensor used to measure the fuel level is called a capacitive fuel level sensor. The design of the sensor is quite simple and is nothing more than a capacitor. It consists of two plates, between which there is a gap that can be filled with fuel. The sensor can be made in the form of two metal plates or tubes inserted into one another. In this case, the surfaces of the two electrodes (capacitor plates) should not have electrical contact, and the gap between the plates should be freely filled with fuel when the sensor is immersed and just as freely released when the fuel level decreases. As fuel fills the space between the plates of the capacitor (sensor), its capacity changes. This method is only suitable for liquids that do not conduct electricity. This method will not allow you to measure the water level. Gasoline and other types of liquid fuels do not conduct electricity. By measuring the electrical capacitance of the sensor, you can estimate the fuel level in the tank. I would like to draw attention to some of the disadvantages of this measurement method. The fact is that the dielectric properties of the fuel can change when the chemical composition of the fuel changes. Those. When changing fuel type, you may have to calibrate the device. Despite this, this method allows you to install the sensor in the tank at an angle, or even mount it in the tank filler cap. The sensor has no moving parts, which is extremely necessary in some cases.

Is it safe to place an electrical circuit in a tank? Many people are concerned about this issue. What if there is a spark? Our sensor circuit is powered by a voltage of 5V, and the sensor is charged through a resistor of several megaohms. Under these conditions, spark formation is impossible. A voltage of 5V is negligible to cause a breakdown spark. In addition, an electric fuel level sensor already “floats” in the tank of any car. Low voltages and currents cannot cause a spark and ignition of the fuel.

I did not set myself the task of obtaining a super accurate sensor capable of measuring the fuel level to within 1mm and with an error of 0.1%, although this is quite possible. Considering that the sensor was created for devices where the fuel in the tank will be mobile, we are quite happy with a budget option with an error of 5%.

The sensor module circuit is based on measuring the charging time of the sensor. The higher the fuel level, the higher the sensor capacity, the longer it will take to charge the sensor (capacitor). The scheme works as follows. Uses built-in microcontroller ATMega8A analog comparator.
To the comparator input PD7 half the supply voltage is supplied through a resistive divider R3,R4. At the moment when the sensor is charged to this voltage, the comparator will operate. On the leg PD6 logical is set «0» . The sensor is discharged through a resistor R2. After which exit PD6 switches and works as a comparator input, the timer starts, and the sensor begins to charge through the resistor R1. When the voltage set at the input is reached PD7, the comparator is triggered, the timer stops. The timer readings are used for calculations. To ensure stability, the microcontroller must be clocked with quartz. The higher the frequency at which the controller operates, the higher the measurement accuracy. In our scheme ATMega8A clocked by quartz 16MHz. Measurements are taken continuously, averaged and sent once per second via the serial port UART at speed 9600 as a numeric value. This is where the functions of the sensor module end.

As a sensor, I used two strips of foil PCB 1.5 mm thick with dimensions: 290 × 20 mm. The strips are glued together foil to foil through small non-conductive spacers. The distance between the plates is 1.5 mm. They can be made to almost any length. You can trim it if necessary. It is especially important to ensure a uniform gap between the plates along the entire length of the “capacitor”.

The display module is responsible for displaying the data received from the capacitive sensor module. This module can be designed according to your requirements. Data can be displayed on an LED bar, on a display, as in our case, on a dial indicator, or any other display device. If necessary, the sensor module can be connected to a computer via an adapter.

The display module works as follows. Numerical data is received from the sensor module via the port UART at speed 9600 , fuel level readings are calculated and displayed. But in order to perform a correct recalculation, the display module will need to know at least two sensor values ​​- the numerical reading of the sensor when the tank is empty and the numerical reading of the sensor when the tank is full. To do this, after installing the sensor, the device calibration procedure is performed. The display module remembers the readings when the tank is empty and full, stores it in its non-volatile memory and performs a recalculation in accordance with these data. Since the module does not require special performance, its microcontroller ATMega8A operates on frequency 2MHz from the built-in RC oscillator.

Instrument calibration procedure:
- the fuel tank must be empty, the device must be turned off
-press and hold the button
- turn on the power of the device
-release the button
- “SET 0” will appear on the screen. Make sure the tank is empty and press the button.
- “SET 100” will appear on the screen. Fill the fuel tank full and press the button.
- calibration is completed.

PCB example:

Sensor module board

Manufacturers install many devices in a car. The driver monitors the speed, distance traveled, temperature, fuel level... In the case of water-powered equipment, the prerogative of choosing measuring instruments is up to the user. The skipper himself decides what exactly to control.

A level gauge on a boat or boat is an important device. It is dangerous to be left without gasoline far from the coast. It is also necessary to control the amount of drinking or technical water in order to replenish supplies on time.

For both water and fuel

Previously, liquid level sensors were strictly divided into water and fuel. The key difference lay in the floats, which react differently to water and oil products. Subsequently, manufacturers improved technology and unified the device. Today, the same submersible sensors are lowered into both boats and water tanks. The only differences are in the symbols on the sign - the water icon or the gas station icon.

The use of stainless and petroleum-oil-resistant materials protects against corrosion and other damage, but such a level gauge does not work with contaminated liquid. Impurities and mechanical inclusions will damage it. Designed for wastewater.

Differences in types, designs and standards

What to focus on starting from scratch? Usually the sensor is purchased first. It is selected according to the depth of the fuel tank (or other tank, the volume of contents of which needs to be measured). The flange dimensions are usually standard: sensor manufacturers are guided by the dimensions of the tanks.

Based on their operating principle, sensors are divided into several groups. The most common are two of them.

Reed float sensor Due to its simplicity and reliability, it is used in many measurement systems. It is a guide tube, inside which, following the liquid, a float moves vertically, in contact with the reed switches. The tube cannot be shortened: the working range of the sensor is “built into” its length.

The second common option is float switch with potentiometer. The operating principle is based on changing resistance. This type is convenient because it can be adjusted for tanks of different heights. Just a salvation for shipowners who, having manufactured a tank according to individual dimensions, are faced with the impossibility of choosing a depth gauge from standard ones. The depth of the fuel tank is, say, 283 mm. And the sensors are 275 or 300 mm! With a large tank area, every centimeter of depth means a considerable volume of liquid. So sensors that can be adjusted are indispensable in such cases.

USA and EURO

Both sensors and level indicators have two resistance standards: European range (10-190 ohms) and American (240-33 ohms).

A pair with matching range standards must be correctly installed: 10 - empty tank, 190 - full (240 and 33, respectively). If the pointer and sensor do not match the operating signal, the indicator will not work correctly and show the opposite.

Accordingly, different standards cannot be mechanically combined: the European range does not “fit” with the American one. But there is a way out. Any pointer with any sensor will help synchronize.

Less common are systems that operate on other principles. For example, based on changes in current strength. A practical option for stationary containers of known volume. Due to precise timing and a digital indicator, you can keep a punctual record of fluid consumption, for example, when refueling cars.

Ultrasonic sensors are even less common, but those that work according to the modern NMEA-2000 protocol are gradually gaining popularity. Their convenience is based on the ability to connect level gauges with “smart” systems. Data can be transmitted to any distance; computers will not only inform you about the current fuel consumption, but also warn you how far you can travel with the remaining fuel.

Black and white, arrows or numbers...

Signs are usually chosen based on taste preferences in design and the style of decorating the interior of the vessel. Manufacturers offer different options: white, black, gold, with and without rims, digital and analog. You can choose an indicator for both conservatives (wood, fabric, leather) and high-tech connoisseurs; both cheaper and cooler.

The digital fuel level indicator circuit is highly repeatable and even with little experience working with microcontrollers, assembly and settings, no problems will arise. To program the avr microcontroller, I assembled the simplest programmer - the so-called Gromov programmer, it is excellent for both in-circuit programming and conventional programming, an article on this programmer is on the website. Now I drive and don’t worry about refueling “whether there’s enough or not enough” :) The schematic diagram of the indicator is shown below, click to enlarge:

And now more about this device, photographs with an installation view in my execution, and photographs and setup instructions from the original author are in the archive.


Here's what this device does:

1. Displays the remaining fuel accurate to the nearest liter, the supported tank volume is selectable from 30 to 99 liters
2. Displays the voltage of the on-board network
3. Compensates for the swing of the float in the tank by repeated (the number is selected in the menu) measurements and displaying the arithmetic average value.
4. Changes the brightness of the backlight depending on the light level, 2 modes, day/night, determined by turning on the dashboard backlight.
5. Changes the indicator display mode to normal/inverse.

List of parts of the indicator on the microcontroller:

R1 - 1 kOhm
R2 - 75 kOhm
R3 - 10 kOhm trimmer
R4 - 4.7 kOhm
R5, R6, R8-R11 - 10 kOhm
R23, R12-R15 - 3.3 kOhm
R24, R16-R19 - 1.8 kOhm
R20 - 2 kOhm * selected depending on the backlight
R21 - 240 Ohm
R22 - 1 kOhm * selected and set to constant
C1, C2, C15 - 0.01 μ
C3, C4, C6-C11,C13-C15 - 0.1 μ
C5 - 47 microns
C12 - 4.7 microns
L1 - 100 mH
DD1-LM7805
DD2 - ATMega8
DD3 - LM317T
VT1 - IRFZ44
LCD1 - Nokia 1110/1200/1110i/1112

The PC10 connector is not indicated in the diagram; buttons and pins for programming the MK are connected through it.


I decided to make two boards, one for installing the display, the second the main one, the boards are round, the case diameter is 50 mm. I couldn’t find a mating part for the indicator connector, so I wired it for the cable, unsoldered the connector from it and soldered the cable directly onto the board from the back side, placing the display itself on double-sided tape.


The main board is formally two-sided, but the reverse side is all used underground; on the reverse side only stabilizers and a transistor are installed, the remaining parts are almost all SMD installed on the track side. Holes with square "ground" pads are soldered with jumpers, the remaining holes on the "ground" side are drilled out.


The two boards are connected to each other using contacts from some long-disassembled connector. In the case, the boards are fixed with one screw; a threaded bushing is soldered under it on the main board. There are no buttons as such, they are not needed often, only during initial setup and calibration, so they are simply connected to the PC10 connector, which is located on the back of the case; unfortunately, there are no photos of it. Signals for programming the MK are also output to this connector.


Setting up the digital fuel level indicator

1. Programming of the MK is done in-circuit, using any programmer, fuses are set as follows.

2. Setting voltage readings. To configure, we connect the indicator to a voltage of 12-14 V, connect a voltmeter to the same source and use the tuning resistor R3 to set the same value as the voltmeter shows.

3. Software setup. We set the tank capacity and calibrate it. We calibrate the tank as follows, start with an empty tank, set the calibration menu to 0 liters and press OK, then fill the tank with 1 liter, set the liters value to 1 and press OK again, and so on with each liter until the tank is full. The process is certainly slow, but you only need to do it once. If you also record the sensor readings during calibration, then if you need to repeat the device or if it fails, you can enter the values ​​directly into the firmware and not have to worry about calibration. We set the remaining settings to your taste. The design was assembled and tested by Ivan Fedorov.

koreada.ru - About cars - Information portal