1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Arduino based Low Fuel Light / Fuel Gauge Smoothing

Discussion in 'Modding' started by GreatOldOne, 3 Sep 2010.

  1. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Now that I've been driving Vikki (The Gooster) for a while, it's apparent that my carefully researched and constructed low fuel circuit is complete bobbins. :)

    It would appear that because the fuel sloshes around in the tank at the slightest provocation, the circuit never gets enough time to realise that it's low and turn the lamp on. Oh, that and the fact that the voltages measured in operation bare no resembalance to those on the bench :duh:

    Anyway, I've decicded to have another stab at this, and whilst I'm at it, smooth out the gauge as well - it's quite alarming seeing the needle dance all over the place whilst you're just driving along.

    As I mentioned in this well timed article thread, I'm thinking of using an Arduino to read the voltages from the sender and then use a moving average to update the gauge. As it's all software based, and can be reprogrammed via a USB cable, if it isn't right first time it can be easily tweaked without having to change the H/W

    The plan is to hook the sender feed to one of the analog input lines on the arduino (it's just a potentiometer), do the processing and then update the level on the dial every 90 seconds or so on one of the PWM outputs. I'll also check to see if the level has reached a set point, and then send another digital outout high and use it to turn on the lamp via a power transistor.

    Any advice would be appreciated - I've been reading up:

    http://arduino.cc/en/Main/Software
    http://arduino.cc/en/Tutorial/AnalogInput
    http://arduino.cc/en/Tutorial/Smoothing
    http://arduino.cc/en/Tutorial/PWM
    http://arduino.cc/en/Tutorial/Fading

    And it sounds like it's dooable - and I have the programing IDE already (Wow! hobbyist software, on a Mac! :lol:) .

    What I'd like some advice on is which arduino would be best suited to this. I had in mind a Nano, as it's small and easily packaged behind the dash...

    And also if I'll be OK running the sender voltage direct to the arduino (according to my in car readings, it'll max out at 3.2v when the tank is empty, and drop to .59v when brimmed)

    And if PWM to my gauge will be OK - I've seen some websited where people have done this to show PC stats on dials:

    http://www.uchobby.com/index.php/2008/02/12/arduino-analog-gauge/

    My gauge has a very low resistance - would that cause any issues in my planned approach?

    Ta muchly in advance, and any one coming to my aid will of course be showered in rep. ;)

    GOO
     
  2. Moriquendi

    Moriquendi Bit Tech Biker

    Joined:
    3 Nov 2005
    Posts:
    1,691
    Likes Received:
    58
    I would suggest that before you spend the cash on an arduino you try a simple low pass filter which should solve the sloshing fuel problem. Basically you want to allow any low frequency signal through (the genuine change in fuel level in the tank) while blocking high frequency changes caused by the fuel sloshing around. If you aim for a corner frequency of 1/60 Hz you should be alright. You would put the filter in line between the sensor and your gauge/ low fuel circuit. The advantage of this route is that it's passive and doesn't require any power supply, however, because of the way the filter works it doesn't have a sharp corner frequency, what you get is increasing attenuation of frequencies above the corner frequency.

    If you find that doesn't work there is another option before you need to go down the arduino route using an integrator, what this does is integrate the incoming signal giving you only the steady change due to fuel use, like a low pass filter with a very sharp corner frequency. This circuit would require a (regulated) power supply and another op-amp after it to bring the signal back to the right polarity.

    If you do use an arduino you can use a low pass filter to turn the PWM signal back into an analogue voltage that the gauge will understand.

    Moriquendi
     
  3. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    If you do go down the microcontroller route you can use the free pins for further expansion later on (trip computer/ECU status displays/etc). You could also account for the non-uniform profile of the tank to convert the value to a truly linear scale.

    You'd want to initialise an array and periodically take a sample until the array is full. Sort it, then discard the top and bottom 25% of values. Then take a mean of the remaining. Or do it as a rolling average - when you take a sample it replaces the oldest value in the array and the array is averaged to find the rolling average.

    Depending on your gauge you might be able to get the PWM signal with a high enough frequency that you can run the gauge directly from the PWM signal.
     
  4. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Well, I bought an Arduino Nano of eBay on Friday, and it arrived today.

    It's (to someone who hasn't played with these things before) amazing - in the short time I've been playing with it, I've managed to get the foundation of my smoothing code sorted and loaded on to the thing, and i've been simulating the fuel sender with a pot hooked up to an analog input, with the 'duino writing the values back to the console and the inbuilt LED lighting when a predefined "fuel level" is reached.

    [​IMG]

    I need to hook it up to the gauge via some sort of driving circuitry, but I don't think that it's going to be too difficult.

    :)
     
    Last edited: 6 Sep 2010
  5. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Some progress - I now have the arduino driving the Gooster's fuel gauge, after a few false starts and an schoolboy error. :)

    It's running off one the PWM lines, via a current limiting resistor to the base of an NPN transistor. The transistor collector is hooked up to the the sender terminal, and the gauge is given 12V. The emitter is connected to ground.

    Cycling though the different PWM duty cycles gives different readings, and I've currently got a little 6-7 line program cycling through displaying zero, 1/2 and full. :D

    What was the school boy error? Well for the longest time I couldn't get it to do anything. I had assigned digital I/O pin 3 as my PWM source, and hooked everything up and nothing. That's when I realised that I was hooked up to analog In pin 3, not digital pin 3.... :doh: :)

    I need to prototype the sender side of the circuit next, which should be fairly straight forward.

    Then I just have to get the processing right. But that should be the easy bit, as if it's wrong, I just upload new code.

    I'll post some pics up tonight of what it all looks like
     
  6. Prometheus

    Prometheus Minimodder

    Joined:
    26 Jun 2004
    Posts:
    362
    Likes Received:
    9
    Good work GOO:thumb:

    I need to do the exact same thing after replacing the fuel tank in my 306 for one from a later 306. On mine the gauge damping was originally done by the sender as well as the low fuel light but on the newer ones the gauge does all the damping as well as the warning light so now i'm mostly guessing how much fuel is left.

    So far i've managed to not completely run out but it's been close a couple of times!

    So if you get this working I'll have to have a go myself as it'll be easier than swapping the fuel tank again:wallbash:
     
  7. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Oh bollocks. Just fried my arduino nano! :waah:

    Everything was working - the only thing I had to add to the circuit was a couple of diodes across the gauge. I did this, and obviously got something wrong as it then worked for a second or so, and then stopped completely.

    I checked all the surrounding components, and they seem all ok. Then I turned to the 'duino. Nothing. No outputs. The power light came on, and on trying to talk to it over the USB only the RX light would come on.

    Loading a program won't work, and I get I/O errors. So I think it's dead.

    Really peeved. :miffed:
     
  8. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    Can you upload a sketch when you disconnect everything from the board (excluding the USB cable, of course)?

    Does the virtual COM port still show up in device manager?

    If you plug it into a breadboard with an LED connected across digital Pin 13 and ground (anode to pin 13), does it briefly flash when you apply power?
     
  9. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    No

    No - I'm on a Mac. :) If the nano is unplugged, I do not get the options for USB programming on the Tools > Serial Port menu. If I plug it in, I do (dev/tty & dev/cu)

    No. The only flashing LEDs I get is when I connect the USB lead, and the TX / RX indicators flicker a few times and then go off. Connecting an LED as you suggested just stays off, when connected to a power source.

    On attempting to load a sketch, I get the following message:

    avrdude: stk500_recv(): programmer is not responding
     
  10. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    Yeah, sounds like it's definitely toast, I'm afraid.
     
  11. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Well, I've got a new one - just bought another nano on eBay. There goes another £20... :rolleyes:

    Here's the circuit I've been working on:

    [​IMG]

    Everything was working, up till the point where I'd noticed that I'd forgotten to put the diodes on (D3 & D4) - that's where it all went ass over tit.
     
  12. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    Did you have problems running the Arduino from a 5v supply? The 10v supply seems kinda... unnecessary. As does L1/D1. How dirty is your car's power supply? :eek: Those LM2940s are good up to 26v.

    Q2/D3/D4 is... odd. That circuit won't work for a start - D3 and D4 are reverse biased in that schematic so no current will flow through OK1's photodetector or through Q2.

    I can't think how you managed to FUBAR your Arduino board, though. Especially with a 12v supply and those optocouplers. Weird...

    Edit: were you trying to generate a PWM signal to switch Q1 in order to short-circuit CON-3 low? Because you should be tying it straight into OK1, but with a large pull-down resistor. And for future reference, transistors should have a resistor on their base RB=(VCC * hFE) / (5 * IC) Where IC is the load current. Also, if you are driving an inductive load (such as an analogue gauge), you need a large diode in reverse parallel with the load. This could kill a microcontroller, but you have loads of protection in place as it is...

     
    Last edited: 2 Oct 2010
  13. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Dunno - that's why they're there. I'll hold my hand up and say that I'm not an electronics man, and much of this has been cobbled together from other circuits I've found online and in the Arduino forums. The optocouplers where my mate Rob's idea (ex Electronics Engineer), as where D3 / D4 to stop any issues with the gauge coils.

    Ah - just saw your edit. Earlier drafts of the circuit did have a resistor into the base of the transistor, but Rob redrew the diagram removing them saying it wasn't neccessary as it would work as a darlington... I took this at face value. ;)

    I am PWM'ing OK1 to drive the gauge through the Transisitor Q2. The gauge is supplied with 12V from the car and then the sender terminal (T) is connected to con 3.

    http://www.etbinstruments.com/ETB_Gauge_Wiring_PDF/52wire3.pdf
     
  14. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    Well I can understand adding D4 - that's the protection diode, and if everything was working fine before you added the diodes, I'd get rid of D3 and double check all the wiring before you plug in your new Arduino.

    Did you test that circuit as is, just without D3/D4? Not in a drastically different state?

    Obviously I've not seen what signals you're working with here, so I'm just giving my crazy opinions on your work so don't feel bad, especially if it works! I can't see any fundamental flaws that would burn out anything plugged into it, though. Which is bad, I suppose because it means there's some other reason it killed your Arduino board. (This is the main problem in using a £20 development board in your projects, rather than a £4 MCU and 75p of support components)

    Oh, and you haven't got a darlington pair there - you've got the optocoupler's base floating - there's no gain. So your only gain comes from Q2. If you did have trouble with a low signal (which you shouldn't have with a nice PWM output from the Arduino) you could have tied OK1's base to its emitter (there should be an example in the datasheet) instead of adding a transistor. Adding the transistor is a better idea if those optocouplers can't handle much current, though.
     
  15. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Everything was in place as per the diagram bar d3 & d4... I cam only assume I must have placed the diodes wrong on the bread board some how. I'll leave them out before hooking up the new duino
     
  16. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    I've redrawn the diagram, removing the diodes D3 & D4, and reconfigured the transistor as per earlier experiments where the transistor was linked to the arduino direct, without the optocoupler.

    I'm guessing I need a protection diode(s) across the gauge, but I'm not sure how many or where to place them. I'm also unsure as to what value R6 should be - 2K2 was fine without the OC, but I'm guessing I need to recalculate taking into account the transistor in the OC, right?

    [​IMG]

    http://www.greatoldone.co.uk/Misc/ArduinoFuel5.sch
     
  17. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    I've just spotted that .pdf you linked to earlier. It doesn't look like you actually need any snubbing diodes (you would if you were driving an analogue volt-meter with a custom scale printed on it for example) as it's handled by the gauge itself.

    R6 doesn't need to be changed.

    If you're supposed to be pulling A3 to ground, that would explain why your first circuit wouldn't work. This one is much better.
     
    GreatOldOne likes this.
  18. GreatOldOne

    GreatOldOne Wannabe Martian

    Joined:
    29 Jan 2002
    Posts:
    12,092
    Likes Received:
    112
    Thanks. :thumb:
     

Share This Page