Float sensor and IOT

so im making a project that can measure the volume of the fuel remaining on the fuel tank by using float as sensor … the vout when fuel is empty = 430 and vout when fuel is full = 30, is there any suggestion on making my project even better?

here’s my coding so far:

const int numReadings = 10; // Need to do some smoothing of the readings for fuel level

// Define the number of samples to keep track of. The higher the number,

// the more the readings will be smoothed, but the slower the output will

// respond to the input. Using a constant rather than a normal variable lets

// use this value to determine the size of the readings array.

int readings[numReadings]; // the readings from the analog input

int index = 0; // the index of the current reading

int total = 0; // the running total

int averagefuel = 0; // the average of fuel reading as an analog input (calculated)

int percentage = 0; // percentage of tank capacity remaining (calculated)

int inputPin = A0; // analog input from fuel sendor (measured)

int fuelled = 10; // led write location for fuel led warning light (defined)

int vout = 0; // fuel sensor voltage from analog input (calculated)

int rtwo = 0; // resistance across fuel sending unit (calculated)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup()
{
Serial.begin(9600); // initialize serial communication with computer:

for (int thisReading = 0; thisReading < numReadings; thisReading++) // initialize all the readings to 0:

readings[thisReading] = 0;

lcd.begin(16, 2); // set up the LCD’s number of columns and rows:

pinMode(0, INPUT); // configure analog pins as inputs

pinMode(1, INPUT);

pinMode(2, INPUT);

}

void loop() {

total= total - readings[index]; // subtract the last reading:

readings[index] = analogRead(inputPin); // read from the sensor:

total= total + readings[index]; // add the reading to the total:

index = index + 1; // advance to the next position in the array:

if (index >= numReadings) // if we’re at the end of the array…

index = 0; // …wrap around to the beginning:

averagefuel = total / numReadings; // calculate the average:

float vout = averagefuel * (5.0 / 430.0); // calculate vout

float rtwo = 1000 / ((5/vout)-1); // calculate rtwo (R1 on board is 1000 ohms)

if(rtwo < 75) percentage = 100; // takes ohm range of tank (1050 to 70) and divides it up by 12 gallons or 8%

else if (rtwo < 151) percentage = 92; // starts checking to see if its full and works its way down

else if (rtwo <233 ) percentage = 84;

else if (rtwo < 315) percentage = 76;

else if (rtwo < 396) percentage = 68;

lcd.setCursor(0, 0); // Fuel status display on LCD

lcd.print(“FUEL LEVEL”);

lcd.print(" ");

lcd.setCursor(12,0);

lcd.print(percentage);

lcd.setCursor(15, 0);

lcd.print("%");

lcd.setCursor(0,1);

delay(1000);

}

is there any suggestion on making my project even better?

Yes, please start by reading the rules of forum, paying attention to the parts about how to ask useful questions and properly posting code. It’s a sticky post at the top of every forum subsection. Here’s a link:

How to use this forum - please read

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi,
You don't need to convert the RAW analog data to volts and resistance.
You can use a function called map to convert RAW to percentage of full.

https://www.arduino.cc/en/pmwiki.php?n=Reference/Map

This will enable you a smooth transition from 0 to 100% if that is what you want.
You can also have a bar graph across the LCD display as an indication of fuel level.

Tom.... :slight_smile:

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between complete functional blocks. Double spacing in particular makes it extremely difficult to follow.