Technical Discussion Topics related to Technical Issues

Fuel gauge mods

Thread Tools
 
Search this Thread
 
Old 07-30-2015, 04:38 PM
  #31  
Senior Member
SuperSport
 
NZSpokes's Avatar
 
Join Date: Apr 2014
Location: Auckland, new Zealand
Posts: 932
NZSpokes is on a distinguished road
You had me at fuel gauge. After that you lost me.

All I know is if its cheap enough I want one.
NZSpokes is offline  
Old 07-30-2015, 04:50 PM
  #32  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Originally Posted by NZSpokes
You had me at fuel gauge. After that you lost me.

All I know is if its cheap enough I want one.
Should be rather inexpensive. ~$15 for the LCD, $3 for the PCB and a buck worth of resistors and capacitors and some wire and then of course an 01-up float gauge (I got mine on eBay for $20). The enclosure will be the tricky part. I need to find the best place to mount it for easy visibility and so it looks decent
SXRguyinMA is offline  
Old 08-14-2015, 06:42 PM
  #33  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Ok so after a lot of back and forth and a lot of time spent trying to find somehere to put this large LCD and its accompanying case I've decided to ditch it.

What I'm going to use instead is this nice small 10-segment LED bar graph assembly:10 Segment LED Bargraph Array Fixed Tri Color New | eBay

It will do just as good of a job but be much smaller. This means smaller PCB(s) which more than likely means going to all SMT components.
SXRguyinMA is offline  
Old 09-23-2015, 01:32 PM
  #34  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Ok so I finally had more time to get this working good with the new LED display. I added in some delays and averaging to get the graph to move fluidly and not bounce all ove rthe place in direct relation to the float's movements. Here's the current code:

Code:
/*
 *LED Fuel Gauge for Honda SuperHawk 16L Tank
 *https://www.superhawkforum.com
 *Code by Will Lyon 9/23/2015. Contact: will.lyon12584@gmail.com
 *5V to fuel sensor Grn/Blk
 *Fuel sensor Gry/Blk to Analog 0 with 10k resistor to GND
 *220 ohm resistor to each led and GND
*/

const int sensorPin = A0;       // the pin that the potentiometer is attached to
const int ledCount = 10;        // the number of LEDs in the bar graph
const int numReadings = 30;     // use this value to determine the size of the readings array

int ledPins[] = { 
  2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
int readings[numReadings];      // the readings from teh fuel level gauge
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average


void setup() {
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {  // loop over the pin array and set them all to output:
    pinMode(ledPins[thisLed], OUTPUT);
  }
  Serial.begin(9600);
  for (int thisReading = 0; thisReading < numReadings; // initialize all readings to zero
thisReading++) {
  readings[thisReading] = 0;
  }
}

void loop() {
  total = total - readings[readIndex];        // subtract the last reading
  readings[readIndex] = analogRead(sensorPin);// read from the sensor
  total = total + readings[readIndex];        // add the reading to the total
  readIndex = readIndex + 1;                  // advance to the next position in the array
  if (readIndex >= numReadings) {             // if we're at the end of the array
    readIndex = 0;                            // wrap around to the beginning
  }
  average = total / numReadings;              // calculate the average
  Serial.println(average);                    // send it to the pc as ASCII digits
  delay(1000);                                // delay in between readings for stability
//  int level = analogRead(sensorPin);  // read the potentiometer:
  average = map(average, 580, 913, 0, ledCount); // map the result to a range from 0 to the number of LEDs:

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed == average-1) {
      digitalWrite(ledPins[thisLed], HIGH);
    } 
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW); 
    }
  }
  delay(100);
}
Once the video is done uploading I'll post it
SXRguyinMA is offline  
Old 09-24-2015, 06:21 AM
  #35  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Here's the video: https://goo.gl/photos/WMbeiffdJmd5DYsT8

The final code posted above runs the graph slower than in the video just so it's not bouncing all over the place as much. The only downside is that it takes a few seconds (5-10) for it to build up enough readings to get the gauge working. That's something I want to work on. I want to figure out how to code it so that when it first powers on it takes a reading and uses that as the display level for 10 or so seconds. Then switch to using the average part of the code. I'll figure it out
SXRguyinMA is offline  
Old 10-03-2015, 09:30 AM
  #36  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Ok final code (as of right now lol). Changes: added more readings and longer delay between readings to further slow the movement of the gauge. Added sweeap sequence for the LED's at startup (purely cosmetic). I also had help getting it to read the real float value at startup so that it doesn't start from empty and work its way up.

Code:
/*
*LED Fuel Gauge for Honda SuperHawk 16L Tank
*https://www.superhawkforum.com
*Code by Will Lyon 10/3/2015. Contact: will.lyon12584@gmail.com
*Help from user Doug Jefferies on the Element 14 Forums
*5V to fuel sensor Grn/Blk
*Fuel sensor Gry/Blk to Analog 0 with 10k resistor to GND
*220 ohm resistor to each led and GND
*/

const int sensorPin = A0;       // the pin that the potentiometer is attached to
const int ledCount = 10;        // the number of LEDs in the bar graph
const int numReadings = 35;     // use this value to determine the size of the readings array

int ledPins[] = {
  2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
int readings[numReadings];      // the readings from the fuel level gauge
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
int averagingCount = 0;         // checks the number of values in the Index
int timer = 75;                 // timer for inital LED sweep
int pinCount = 10;              // number of LED pins

void setup() {
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {      // loop over the pin array and set them all to output
    pinMode(ledPins[thisLed], OUTPUT);
  }
  for (int thisReading = 0; thisReading < numReadings;        // initialize all readings to zero
  thisReading++) {
  readings[thisReading] = 0;
  }
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {      // loop from the lowest pin to the highest
    digitalWrite(ledPins[thisPin], HIGH);                     // turn the pin on
    delay(timer);                                             // delay for time set bove
    digitalWrite(ledPins[thisPin], LOW);                      // turn the pin off
  }
  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { // loop from the highest pin to the lowest
    digitalWrite(ledPins[thisPin], HIGH);                     // turn the pin on
    delay(timer);                                             // delay for time set above
    digitalWrite(ledPins[thisPin], LOW);                      // turn the pin off
  }
}

void loop() {
  total = total - readings[readIndex];            // subtract the last reading
  readings[readIndex] = analogRead(sensorPin);    // read from the sensor
  total = total + readings[readIndex];            // add the reading to the total
  readIndex = readIndex + 1;                      // advance to the next position in the array
  if (readIndex >= numReadings) {                 // if we're at the end of the array
    readIndex = 0;                                // wrap around to the beginning
  }
  averagingCount = averagingCount + 1;            // increments the count for averaging
  if (averagingCount >= numReadings) {            // caps the averaging count to the array
    averagingCount = numReadings;                           
  }
  average = total / averagingCount;               // calculate the average
  delay(3000);                                    // delay in between readings so the gauge doesn't fluctuate too fast
  average = map(average, 580, 925, 0, ledCount);  // map the result to a range from 0 to the number of LEDs:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {  // loop over the LED array
    if (thisLed == average-1) {                   // if the array element's index is less than ledLevel
      digitalWrite(ledPins[thisLed], HIGH);       // turn the pin for this element on:
    }
    else {
      digitalWrite(ledPins[thisLed], LOW);        // turn off all pins higher than the ledLevel:
    }
  }
  delay(100);
}

Last edited by SXRguyinMA; 10-03-2015 at 09:35 AM.
SXRguyinMA is offline  
Old 10-03-2015, 11:01 AM
  #37  
Rex Kramer-Thrill Seeker
SuperBike
 
CruxGNZ's Avatar
 
Join Date: Jan 2011
Location: Brookfield, WI
Posts: 2,312
CruxGNZ is on a distinguished road
Wow! Good work man. Many of us appreciate what you have done here
CruxGNZ is offline  
Old 10-03-2015, 11:23 AM
  #38  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Originally Posted by CruxGNZ
Wow! Good work man. Many of us appreciate what you have done here
Thanks! I'll try to get a video of the current setup tonight. I'm thinking of integrating the factory low fuel LED in as well and have it also turn on when the last two red LED's are lit on the gauge. I know it's on its own PCB in the cluster and probably relies on 12V but I also know that if you jump the two pins on the gauge side of the level sensor connector the light comes on.

I may be able to exploit that or maybe just use a single LED wired to the board, seeing how it's only a few screws to remove the factory low fuel LED.

All that's left really is to design a PCB and 3D print the enclosure for it.
SXRguyinMA is offline  
Old 10-03-2015, 01:51 PM
  #39  
Member
Squid
Squid
Thread Starter
 
SXRguyinMA's Avatar
 
Join Date: Jun 2015
Location: Leicester MA
Posts: 85
SXRguyinMA is on a distinguished road
Ok so I added a function to turn on an LED (in this case the OEM low fuel LED) when either of the last two bars are lit. I plan on using the OEM LED but removing the PCB that controls it and wiring it directly to my PCB for the gauge.

Here's the final code: ::EDIT:: apparently there's a character limit on these posts - I can't post the entire code as it cuts it off.

And here's a video of it in action. Once it's on the bike it will use the factory yellow LED, not this green one I popped in the breadboard.

SXRguyinMA is offline  
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Patton303
Technical Discussion
12
03-14-2020 05:20 PM
05Titan
Technical Discussion
5
05-15-2011 07:24 PM
Mike996
Everything Else
5
11-18-2009 03:04 PM
tudor
Technical Discussion
3
06-24-2008 06:56 AM
BIG DAVE 03
Technical Discussion
2
05-17-2007 03:41 AM



Quick Reply: Fuel gauge mods



All times are GMT -7. The time now is 06:30 PM.