Hello all I'm working on a oil tank level system using the ultrasonic sensor.
I have it working but I can't figure out how to do the inch to gallon conversion.
I have tried to search for it but no luck any help would be great thanks here's my code.
#include "Ultrasonic.h"
#include <LiquidCrystal.h>
#define TRIG_PIN 10
#define ECHO_PIN 8
#define buzzer_pin 9
int sensorPin = 8;
int buzzerpin = 9;
int sensorMin = 5 ;
int sensorMax = 24 ;
int sensorValue = 0 ;
Ultrasonic OurModule(TRIG_PIN, ECHO_PIN);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(buzzerpin, OUTPUT);
float h;
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print(" Oil Tank ");
lcd.setCursor(0, 1);
lcd.print(" Level Display ");
delay(5000);
lcd.setCursor(6, 8);
}
void loop()
{
int Gallons;
lcd.clear();
lcd.setCursor(5, 0);
lcd.print(OurModule.Ranging(INC));
lcd.print("Gall");
lcd.setCursor(0,1);
lcd.print(" Oil Tank Level ");
delay(2000);
sensorValue = (OurModule.Ranging(INC));
if (sensorValue < sensorMin){
digitalWrite(buzzerpin, HIGH);
delay(60);
digitalWrite(buzzerpin,LOW);
delay(10);
lcd.clear();
lcd.setCursor(4,0);
lcd.print ("Warning");
lcd.setCursor(6,8);
lcd.print ("Full");
delay(5000);
}
else {
lcd.setCursor(6,8);
lcd.print(" Oil Tank Level ");
}}