Hey guys. I'm working on retrofitting my bike from just a low fuel warning light (which doesn't work anyway) to a float level guage from a later year of the same bike. I have the fuel sender and I have a gauge working on a 16x2 LCD. What I want is to smooth the readings so the gauge isn't all over the place going down the road.
I had implemented it in code but the problem is the gauge starts off form the bottom as the readings and average pile up. Also for some reason with the smoothing once the values started to pile up my LCD display would go all screwy and every portion would fill up with a full square and random divide signs and space invader characters would pop in and out.
Here's the code as I have it now which works perfectly, just with no smoothing.
/*
*LCD Fuel Gauge for Honda SuperHawk 16L Tank
*http://www.superhawkforum.com/forums/technical-discussion-28/fuel-gauge-mods-33365/
*Basic concept found at http://www.pddnet.com/articles/2014/01/designing-arduino-fuel-gauge-warning-lights
*Code by Will Lyon 7/26/2015. Contact: will.lyon12584@gmail.com
*Uses the LcdBarGraph1.5 Library for Arduino. Author: Balázs Kelemen. Contact: prampec+arduino@gmail.com
*LCDBarGraph library can be found here: http://playground.arduino.cc/Code/LcdBarGraph#Download
*Designed to be used with the Adafruit 16x2 RGB LCD (both negative and positive work properly)
*5V to fuel sensor Grn/Blk
*Fuel sensor Gry/Blk to Analog 0 with 10k resistor to GND
*/
#include <LiquidCrystal.h> // Include Liquid Crystal library
#include <LcdBarGraph.h> // Include LCD Bar Graph library
byte lcdNumCols = 16; // 16 columns in the 16x2 LCD
byte sensorPin = A0; // Fuel float sensor 5V input with 10k resistor to GND and Analog 0
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // LCD connected to digital 7-12
LcdBarGraph lbg(&lcd,16,0,1); // Parameters for LCD bar grah library
const int redPin = 5; // Red LCD backlight on Digital pin 5
const int grnPin = 6; // Green LCD backlight on Digital pin 6
void setup() {
Serial.begin(9600); // Initialize communication with PC via serial monitor
pinMode(redPin, OUTPUT); // Configure red LED pin as output
pinMode(grnPin, OUTPUT); // Configure green LED pin as output
pinMode(sensorPin, INPUT); // Configure the fuel level sensor pin (A0) as an input
lcd.begin(2, lcdNumCols); // Define LCD as having 2 rows and refer to the above byte for number of columns
lcd.clear(); // Clear the LCD display
delay(100); // Wait 100ms
}
void loop() {
int level = analogRead(sensorPin); // Label sensor reading as "level"
level = map(level, 624, 946, 0 ,1023); // Map the sensor's 624E/946F readings to 0-1023 for proper graph display
lcd.setCursor(0, 0); // Set cursor to top left of display
lcd.print("E || F"); // Static full/empty readout on the LCD
lbg.drawValue( level, 1023); // Draw graph as fuel level reading
if (level < 200) // If the mapped value is below 200 (approx. 3L fuel remaining)
{
analogWrite (grnPin, 255); // Turn the green LCD backlight off
analogWrite (redPin, 0); // Turn the red LCD backlight on
}
else // Otherwise
{
analogWrite (grnPin, 0); // Turn the green LCD backlight on
analogWrite (redPin, 255); // turn the red LCD backlight off
}
delay(100); // Delay between readings
}
Any help is greatly appreciated. Thanks!
Here's a video of how it works currently: https://photos.google.com/share/AF1QipPTjZQtcFW9HBCw5SEVOGHq9Fh1uWIqKFjy_9rUXuSbnHad5mt_8jSzTAJaN2pwcA?key=Vllfd2JkRTE3ejNVTlFRcG1QbGhUM21lVV9FaDBn