I am working on this project to show propane tank level. Basically, the circuit has two potentiometers, one is for adjusting the LCD contrast and the other is the actual sensor. It has one green LED that stays solid as long as the tank level is above 10% and another red LED that blinks when the sensor falls below 10%.
NOTE: This is for a large capacity propane tank that has a sensor port not like a barbeque tank.
The issue I'm trying to solve is how to better calculate the sensor reading more accurately to show 100% when full and 0% when completely empty. Currently it shows reading like 99.2% for full and .78 for empty. The sensor is also not exactly 10K, 10.75k is the actual reading.
This is the code I am using:
int myVoltPin = A2; // Initialize variable to Analog pin A2
int readVal; // Initialize variable to hold sensor value
float v2; // Initialize variable used to calculate display %
int delayT = 250; // Initialize variable for serial print *Optional
int ledPin13 = 13; // Initialize digital pin 13
int ledPin8 = 8; // Initialize digital pin 8
#include <LiquidCrystal.h> // include the library code:
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // initialize the library by associating any needed LCD interface pin
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // with the arduino pin number it is connected to
void setup()
{
pinMode(ledPin13, OUTPUT); // Set pinmode on pin 13 to OUTPUT
pinMode(ledPin8, OUTPUT); // Set pinmode on pin 8 to OUTPUT
Serial.begin(9600); // Set baud rate to 9600
lcd.begin(16, 2); // Set the cursor to column 16, line 2
lcd.print("Tank Monitor"); // Print a message to the LCD.
}
void loop() {
readVal = analogRead(myVoltPin); // Read sensor resistance
v2 = (5.15 / 1023.) * readVal; // Calculate value from sensor to proper scale
//Serial.println(v2); // optional serial print calculated sensor value during adjustment
//delay(delayT); // Optional delay for serual print of calculated sensor value during adjustment
if (v2 <= 0.50) // Set condition to run if calculated sensor value is less than or equal to .5 value
{ // This will blink the LED set on the condition
digitalWrite(ledPin13, HIGH); // Set digital pin 13 to HIGH
delay(100); // Delay ON time for digital pin 13
digitalWrite(ledPin13, LOW); // Set digital pin 13 to LOW
delay(500); // Delay OFF time for digital pin 13
}
if (v2 >= 0.51) // Set condition to run if calculated sensor vaue is greater than or equal to .51
{ // This will keep this LED on while the condition is true
digitalWrite(ledPin8, HIGH); // Set digital pin 8 to HIGH
} else // If condition is false then run cpde below
{
digitalWrite(ledPin8, LOW); // Set digital pin 8 to low if condition is no longer true
}
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print(v2 * 20.); // Print calculated value multiplied by 20 to the LCD on line 1.
lcd.setCursor(5, 1); // set the cursor to column 5, line 1
lcd.print("%"); // Print % character after calculated value to LCD on line 1
lcd.setCursor(7, 1); // set the cursor to column 7, line 1
lcd.print("to empty"); // Print message after % character to LCD on line 1
}
This is the breadboard layout:

This is the schematic:
And here is the component list:
Name - Quantity - Description
U1 - 1 - Arduino Uno R3
RpotSensor Resistance, RpotContrast Adjust - 2 - 10 kΩ Potentiometer
DWarning LED - 1 - Red LED
DStatus LED - 1 - Green LED
RWarning, RStatus, RBacklight Resistor - 3 - 220 Ω Resistor
U2 - 1 - LMB162ABC LCD 16 x 2
