E21 Fuel Gauge ConverterWichit Sirichote, wichit.sirichote@gmail.com
Build a fuel gauge converter for E21 with a nano 328 board.
Simple circuit converts the 0-190 Ohms fuel level sensor to the 90-5 Ohms, BMW E21 fuel gauge. The circuit is built with a nano 328 board using one channel ADC, and two channels PWM output. The 0-190 Ohms sensor is connected to ADC channel 0 with a voltage divider. The two channels output are PWM1 and PWM2 pins. PWM1 drives the E21 needle and PWM2 drives the empty light. The firmware reads the analog input, makes a five-point moving average, scaling the readings, and sends the PWM signal. Source code is available for customizing your own sensor.
Converter board and E21 fuel gauge. Block diagram
Hardware
The fuel level sensor is connected to the source resistor, R2 150 Ohms, making the voltage divider circuit. Changing the sensor resistance from 0-190 Ohms will provide DC voltage changing at ADC0 pin.The output channel1, PWM1 drives the E21 gauge by Q1, NPN transistor with 5 Ohms current limiting resistor.
The output channel2, PWM2 drives the empty light by Q2, NPN transistor.
The circuit is powered from +12V car battery. Diode D1 prevents wrong polarity wiring.
Schematic, click to enlarge Software
The control firmware is developed using Arduino IDE. Initial code sets 9600 serial port, then makes the needle sweep test. Main code reads the sensor level, makes a five-point moving average, scales it into E21 gauge and sends PWM signal. .
/* BMW E21 Fuel sensor converter Display is for Empty 5.5, Full 90 Ohms Test with E36 Fuel level sensor Empty 0 Ohm, Full 190 Ohms Mega328 chip reads analog A0, converts to PWM at D9. Calibrated at +14V power supply */int PWM = 9; // the PWM pin drives needle int EMPTY =10; // this pin drives EMPTY Lampconst int analogInPin = A0; // Analog input pin that the fuel sensor is attached toint sensorValue = 0; // value read from the fuel level sensor int outputValue = 0; // value output to the PWM (analog out)int Ohm; int tick;int x[5];int i; int j=0; int k= 100; // loweset PWMvoid start_sweep() { sensorValue = analogRead(analogInPin); sensorValue = 1441 - sensorValue; outputValue = map(sensorValue, 0, 1023, 0, 255); if(outputValue>255) outputValue=255; for(i=100; i<outputValue; i++) { analogWrite(PWM,i); delay(50); } }void start_test() { for (i=90; i<255; i++) { analogWrite(PWM, i); delay(30); }analogWrite(EMPTY, 50); delay(1000); for (i=255; i>100; i--) { analogWrite(PWM, i); delay(30); } analogWrite(EMPTY, 0); delay(1000); start_sweep(); }// the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: pinMode(PWM, OUTPUT); pinMode(EMPTY, OUTPUT); Serial.begin(9600); start_test(); // analogWrite(EMPTY, 50); // test empty light }// the loop routine runs over and over again forever: void loop() { sensorValue = analogRead(analogInPin);x[0]=x[1]; x[1]=x[2]; x[2]=x[3]; x[3]=x[4]; x[4]= sensorValue;sensorValue=(x[0]+x[1]+x[2]+x[3]+x[4])/5;// convert ADC readings to 0-190 Ohms sensor // y = -x + 1441 sensorValue = 1441 - sensorValue;Ohm = (sensorValue*3)/10 -114;if(Ohm<0) Ohm = 0; Serial.print(sensorValue); Serial.print(", "); Serial.print(Ohm); Serial.print(", ");// map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); if(j++ >=5) { // if(j==5) k=outputValue-100; j=6; // outputValue = outputValue-k; if(outputValue<100) outputValue=100; if(outputValue>255) outputValue=255; analogWrite(PWM,outputValue);// if(k--<=0) k=0;} // Serial.print(k); Serial.print(", "); Serial.print(outputValue); Serial.println();if(Ohm<=20) analogWrite(EMPTY, 50); else analogWrite(EMPTY, 0); delay(30); }
Empty lamp turns on near lowest fuel level (PWM2 is 50%)
Wiring signals: +12V, GND, Needle, and Empty lamp
PARTS LIST
Semiconductors
Q2,Q1 BC337
D1 1N4001
U1 328NANO
Resistors (all resistors are 1/8W +/-5%)
R1 5 Ohms 1/2W
R2 150/1/2W
R3,R4 1k, 1/8W
Capacitors
1 1 C1 220uF, 25V, electrolytic capacitor
2 1 C2 100uF, 16V, electrolytic capacitor
Additional parts
JP1 4 HEADER
J1 CON2, wire solderingKit is available on request.
Download
Hardware schematic, Source codeMore information, please contact Wichit Sirichote, wichit.sirichote@gmail.com
May 18, 2024