How to drive 12v gauge from 5v MCU

Discussion in 'General Electronics Chat' started by NomadAU, Jan 7, 2013.

  1. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Hi,

    I've searched through the existing posts, and while there are a handful that are vaguely related to this question, I haven't found any that address it directly...so here goes.

    I am trying to control a 12volt analogue fuel gauge using an ATMEGA328p microprocessor (an Arduino variant). Using PWM, the chip is capable of generating an apparent voltage range between 0 and 5 volts on an output digital pin - the range can be divided into 255 increments between 0 and 5v.

    Now, the analogue gauge runs at 12 volts and if it was being controlled by a normal fuel (or similar) sensor, then the sensor would provide a variable resistance from around 30 Ω through to 240 Ω. So the gauge is really responding to the amount of current flowing through it in order to position the needle.

    And for the question....

    How do I simulate the sensor using a circuit driven by the 0-5v output from the MCU?

    For the record, I have tried driving the sensor input directly from the MCU but this provides only a limited movement of the needle (from just below half up to about 3/4). I've also tried to 'amplify' the voltage using an NPN to switch the 12v based on the 0-5v at the base, but this gave even worse results with the needle sitting below empty and barely moving.

    BTW, I have a test program loaded on the MCU which simply oscillates the voltage from 0 to 5 and back down again, in a continuous loop, slow enough to register on the gauge. Ideally, I'd like the full range of the gauge to correspond to the full voltage range emitted by the MCU.

    Ideas?
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Since it doesn't seem the gauge is still inside a vehicle...

    I'd put the micro aside until you understand what the gauge needs to respond. From your description you should be able to get the gauge to respond with just a 12V supply and 30 Ω and 240 Ω resistors (or something close): that should let you see it go from empty to full.

    I haven't used such a gauge but looking on the web many of the units have 3 connections, not 2 connections as I think you are describing. Can you check that? Remember there may be a ground connection that is just a lug on the metal of the case.

    This is typical of what I found for wiring:

    [​IMG]
     
  3. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Thanks for the reply ErnieM.

    Perhaps I should have included a bit more information regarding what I have already done. I am quite comfortable with driving the gauge using 12v...I had already set up a simple potentiometer connected between +12v and the sensor pin of the gauge and it shows that the needle ranges from E(mpty) @ 30 Ohms to F(ull) @ 240 Ohms. As you suggested, the gauge does indeed have 3 main pins (Vcc, Gnd, and sensor) as well as a 4th for a light.

    So what I need for this solution is a way of varying the current to the S(ensor) pin in relationship to the voltage from the MCU pin.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    OK, that sounds great. You're on the right track with this. Can you take a voltmeter and read what voltage is on the sensor pin when you see the E(mpty) @ 30 Ohms and F(ull) @ 240 Ohms?

    I agree "the gauge is really responding to the amount of current flowing through it in order to position the needle" but I doubt the voltage there is 12 volts... if it was the gauge is taking 50 mA (@ 240 Ohms) to 400 mA (@ 30 Ohms) just to move the very tiny needle.

    If you get those measurements we could figure out how much current we should be sinking... then make some sort of current sink the micro can control. This sink may be as simple as a transistor and a resistor but it's going to depend on what voltage can be across it.
     
  5. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Here are the details you asked for ErnieM

    Empty - 270Ohm, 8.12V
    Full - 36 Ohm, 2.97V

    So those are the pot readings when gauge showed E and F, and the respective voltages as measured at the Sensor input pin of the gauge.
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,777
    4,804
    Before you said that 30Ω resulted in an E and 240Ω resulted in an F. Now you are saying it is the other way around. Could you confirm which is which?

    Assuming your power is 12V, that means that at your two endpoints you have

    (12V-8.12V)/270Ω = 14.37mA
    (12V-2.97V)/36Ω = 251mA

    I'm having a hard time picturing what is inside the guage that is resulting in a higher voltage on the sensor input as you connect a higher valued resistor between it an +12V.

    Are you sure you don't have these backwards? If I swap them I get

    (12V-2.97V)/270Ω = 33.4mA
    (12V-8.12V)/36Ω = 107.8mA

    If this were a simple voltage divider, then the first reading would correspond to a lower resistor value of 89Ω while th second would correspond to 75Ω.

    If your supply voltage were actually 11.1V instead of 12V,then both readings would be consistent with a lower resistance of 99Ω.

    So, my guess (based on very little actual information at this point) is that your guage's sensor input may be just a 100Ω resistor (or a meter movement circuit with an effective input resistance of 100Ω).
     
  7. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Sorry about the confusion WBahn. I was writing the previous post from memory...and clearly my memory is not so good!

    Just re-ran the measurements and can definitely confirm the following readings. Set up is as follows.
    12V power to the gauge G and I terminals (-ve and +ve respectively).
    Power to the S(ensor) terminal is +12v via a potentiometer which I vary to discover the resistance values (and the voltage at S). So think of this as being akin to a sensor device provides an earth via a variable resistor activated by a float arm or similar.

    So, figures are...

    Full - 54 Ω, 3.3V
    Empty - 247 Ω, 7.91V

    The actual spec sheet for the gauge suggests 33 Ω and 240 Ω which is in the ball park - once I know how the overall design for 'translating' my MCU voltage output into gauge current flow, I'm sure I'lll be able to fine tune the circuit.
     
  8. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Just for completeness, I have also now measured the current flow.

    Empty - 34mA
    Full - 90mA
     
  9. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    As guessed by WBahn, the internal resistance of the gauge is indeed 100Ω
    I measured the resistance across the +ve (I) terminal and the S(ensor) terminal and it read 103.5Ω.

    Hopefully this little bit of info will help with understanding how the gauge is driven and therefore, how I might simulate the sensor with my MCU.
     
  10. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Problem solved!!!

    So all I did was connect an NPN transistor with Base wired to my MCU output, Collector wired to the gauge sensor pin and Emitter wired to ground. I realised that when I tried this earlier, I had wired the gauge on the 'wrong' side of the transistor, i.e. on the Emitter side. All works just fine now, and I have now got the gauge to show its full range from E to F by driving the bias of the transistor using the 0-5 volts from the MCU. Just a bit of fine tuning required now.

    Thanks to all who contributed to this.
     
  11. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Just for completeness, and in case anyone else is interested in doing the same thing, here are the finer details of the solution.

    The NPN transistor I used was a standard BC549.
    The MCU (Arduino) provides current limiting logic internally, so there was no need for any current limiting resistor when connecting the pin to the transistor Base.

    The actual voltages required to position the needle at E and F were 1.596V and 4.08V respectively. In 'Arduino speak', this equates to analogWrite() values of 80 and 205 respectively.

    Finally, the gauge I used was a Teleflex Morse fuel gauge, P/N 84150FE.
     
Loading...