I got a Resistive sender fuel gauge sketch off the internet that I have adapted. The Resistive sender is a floating magnet that activates read switches to vary the resistance. Using a stable 5v power source and 100-ohm resistor I have a voltage bridge that is connected to the sender and pin A1. The original sketch uses this to get the voltage into liters:
TankValue0 = map(sensorTankValue0, 352, 824, 0, 100);
if (TankValue0 < 0) {
TankValue0 = 0;
}
if (TankValue0 > 100) {
TankValue0 = 100;
The lower range is not too far off but as you get to the top it is out to lunch.
I have mapped the segments of MY float sensor's intervals, and have found there to be 17 distinct points-- I measured the voltage at each point and made a table (I mean like on paper) to relate the measured voltage at a given point to a distance in mm, and then converted that to the relevant metric of liters in a tank when the float switch is reading a given voltage.
V | L |
---|---|
4.04 | 94 |
3.981 | 88 |
3.902 | 84 |
3.81 | 81 |
3.703 | 77 |
3.637 | 72 |
3.564 | 69 |
3.483 | 65 |
3.393 | 61 |
3.293 | 57 |
3.18 | 53 |
3.053 | 50 |
2.908 | 46 |
2.546 | 42 |
2.192 | 38 |
1.726 | 35 |
How do I get that information into the sketch to give me a read-out of L in my tank?
I have no programming knowledge really. I work with Arduino IDE a lot, but only using sketches other people have written. So, I have a huge basic knowledge gap. So, please bare that in mind.
This is the whole sketch:
#include <LiquidCrystal_I2C.h>
int TankValue0;
int TankValue1;
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.clear();
lcd.print("WORD");
lcd.setCursor(0, 1);
lcd.print("TO");
delay(1500);
lcd.clear();
lcd.print("YO ");
lcd.setCursor(0, 1);
lcd.print("MOMMA");
delay(2000);
lcd.clear();
pinMode(A0, INPUT);
Serial.begin(9600); // starting the Serial Monitor
}
void loop() {
int sensorTankValue0 = analogRead(A0);
int sensorTankValue1 = analogRead(A1);
TankValue0 = map(sensorTankValue0, 352, 824, 34, 94);
TankValue1 = map(sensorTankValue1, 785, 310, 0, 100);
if (TankValue0 < 0) {
TankValue0 = 0;
}
if (TankValue1 < 0) {
TankValue1 = 0;
}
if (TankValue0 > 100) {
TankValue0 = 100;
}
if (TankValue1 > 100) {
TankValue1 = 100;
}
lcd.print("S.V. SAVANNAH");
lcd.setCursor(0, 1);
delay(100);
lcd.print("DAY TANK ");
lcd.print(TankValue0);
lcd.print("%");
lcd.setCursor(0, 0);
delay(1000);
lcd.clear();
}