int SENSOR_PIN = A0;
int MIN_ADC = 0;
const int MAX_ADC = 1023;
int readFuelSensor(){
return analogRead(SENSOR_PIN);
}
int convertToPercentage(int sensorValue){
return map(sensorValue, MIN_ADC, MAX_ADC, 0, 100);
}
void displayFuellevel(int raw, int percent){
Serial.print("Raw: ");
Serial.print(raw);
Serial.print(" | Fuel Level: ");
Serial.print(percent);
Serial.println(" %");
}
void setup() {
Serial.begin(9600);
}
void loop() {
int rawValue = readFuelSensor();
int fuelPrcent = convertToPercentage(rawValue);
displayFuellevel(rawValue, fuelPrcent);
delay(300);
}