Output 0-20mA from an Arduino

Hi! I am using a Arduino Duemilanove for my project.

I need an input of 0-20mA into a speed indicator. I know that the Ardunio pins have a current output of 0-40 mA and was wondering if I could use one of the pics to input 0-20mA into the speed indicator. I know that directly connecting the pin will give me 0-5V so I need some external hardware. Right? However, I have no clue how to do this. Can someone please help ? The current has to be variable from 0mA (or close to 0) to 20mA.

You want an analog current output? One approach is to use a low-pass-filter on a PWM output pin. However the simple RC-filter approach gives a voltage output rather than current.

Can you provide more information on the spec of this speed-indicator?

Without a datasheet for your speed indicator it's hard to progress. The +5vdc may not be enough voltage to force a 0-20ma signal into the indicator. However you accomplish the task you are going to have to generate a analog output voltage, convert it to a constant current (wire a current feedback signal so the arduino can 'measure' the current?) and adjust the output voltage up or down to maintain the desired output current signal. This is not a trivial task and without specific electrical interface information on the speed indicator, not worth proceeding with.

Lefty

On the basis that you can generate the 0-5volt signal you simply need a load resistance of 250ohms to give you a 0-20ma output. You need to measure the input resistance of the speed indicator. On the basis that it is a 20ma input unit it WILL have a measurable resistance, let's call it Rx. So, in series with this you need to provide a further resistance Rl, the value of which is Rl = 250 - Rx

However, a further complication will be the RC filter you use to convert the PWM output signal to a 0-5 volts. This will have a series resistance Rf and your 20ma load will decrease the filter output since drawing current through Rf will reduce the 5volt PWM level to something less than 5 volts. This being so, the loop resistance will have to be reduced from the original 250ohms - which will further load your RC filter !!

Also the RC filter is a non-linear conversion of PWM duty cycle to smooth analogue output so you may need to build in some linearisation algorithm into your programme.

Are you sure the input is 0-20ma and not 4-20ma (which is an industry standard for analogue current devices).

So, what at first seemed like a fairly simple task will require a degree of bench work to produce an effective system.

I need an input of 0-20mA into a speed indicator

I am thinking more of a car speed indicator. Analog type. Work like an old VOM. A needle meter. Need a current from x to y to move the needle. So you want a circuit from PWM or digital convert into current value ? I am correct ?

Techone:

I need an input of 0-20mA into a speed indicator

I am thinking more of a car speed indicator. Analog type. Work like an old VOM. A needle meter. Need a current from x to y to move the needle. So you want a circuit from PWM or digital convert into current value ? I am correct ?

Basically yes, but one needs to know the resistance of the indicator device to calculate the required total series resistance. And if the indicator's resistance is higher then 250 ohms then it will not be possible to drive it with a +5vdc max output signal. Again it's foolish to claim possible solutions without knowing specifics about the speed indicator device. Otherwise proposed solutions must be couched with assumptions and caveats.

Lefty

Are you trying to Drive a Analog meter via. AVR?

@retrolefty

Ok, I get it. You need to know more details about the OP speed meter, like current, ohms, voltage max, etc. But you agree with me the OP stil need a circuit to drive properly that speed meter from the Arduino. Right ?

Techone:
@retrolefty

Ok, I get it. You need to know more details about the OP speed meter, like current, ohms, voltage max, etc. But you agree with me the OP stil need a circuit to drive properly that speed meter from the Arduino. Right ?

Certainly. The circuit might be a PWM output pin driving a low pass filter and then buffered with an op-amp capable of driving a 20ma output current via a possible series resistor wired to the indicator. The questions then revolves around what the input resistance of the indicator is, as that dictates what source driving voltage will be required. If the OP could just take a resistance reading of the speed indicator that could help point to the actual circuit details required. +5vdc may not be sufficient, again depending on the actual input resistance of the indicator is.

Heck it's even possible to drive the indicator straight from the PWM output pin, with no filter and no opamp as again it's all about what the indicators resistance is, it's all about ohm's law. But if the indicator was designed for automotive use it might very well have been designed for 12vdc to be able to generate the 20ma top of scale value.

Lefty

But if the indicator was designed for automotive use it might very well have been designed for 12vdc to be able to generate the 20ma top of scale value.

I was thinking about just that.

Thanx everyone for your responses! I didn't realise how complicated this is till I read through all of this!

The issue is there is no ONE speed indicator but three to four types which this current input should run (Part of project :frowning: ). So, I guess this will be problematic seeing that the calculations will depend on the specifications for the speed indicators.
Yes, an input of 4-20mA is fine.
Does having a separate higher voltage source solve the issue of the possibility of the ATMega not being able to push enough current through? (Not connecting it to the Arduino at all.)
Thanx again!

Jewel:
Thanx everyone for your responses! I didn't realise how complicated this is till I read through all of this!

The issue is there is no ONE speed indicator but three to four types which this current input should run (Part of project :frowning: ). So, I guess this will be problematic seeing that the calculations will depend on the specifications for the speed indicators.
Yes, an input of 4-20mA is fine.
Does having a separate higher voltage source solve the issue of the possibility of the ATMega not being able to push enough current through? (Not connecting it to the Arduino at all.)
Thanx again!

Well still nothing specific about the indicators? No datasheet? No manfacture link?

The person who has the data sheets isn't here for the next few days. :frowning:

And what about a simple try ?

An Arduino can output 20 mA, at 5V you need a 250 Ohm resistor for this current.
Any normal resistor can easily burn (5V*20mA =100 mW) without overloading.
Now add your device in series and see ( measure voltage across your device ) what happens.

"Probably" even reducing the resistor to 0 Ohm won't show full output (20 mA @ 5V), however.

Then you'd need a higher ( 12V ?) power source and some amplifying transistor circuit, minimally.
Probably your needle device effectively does the low pass filter itself, you might simply switch the 12v by your PWM output.

Linearisation is your next issue :~

michael_x :
My initial idea was to use a rheostat and what you say does sound similar to that. Might as well give it a shot will I can get specs for the indicators.
Meanwhile, I found this.

Any Comments about this tranconductance circuit ?
Really appreciate the help!

That will work. But you need a voltage , with the Ardiuno, you will need Digital to Analog circuit or PWM to voltage circuit. Than that will work. And for op-amps, you need dual power supply to make it work more reliable

Jewel:
michael_x :
My initial idea was to use a rheostat and what you say does sound similar to that. Might as well give it a shot will I can get specs for the indicators.
Meanwhile, I found this.
http://www.allaboutcircuits.com/vol_3/chpt_8/7.html
Any Comments about this tranconductance circuit ?
Really appreciate the help!

It does not matter what resistance value Rload is, or how much wire resistance is present in that large loop, so long as the op-amp has a high enough power supply voltage to output the voltage necessary to get 20 mA flowing through Rload.

Same requirement. Rload of that circuit is equivalent to the internal resistance value of the speed indicator. If Rload is unknown then the minimum value for the op-amp power supply is also unknown. Have you considered taking a ohm meter and just read the speed indicator's resistance?

Lefty

Any Comments about this

I'd rather feed the op-amp with a flattened PWM signal.

My brute approach to apply a PWM signal to your current sink just strong enough that 255 (= constant 5V) result in full scale and see what happens if you turn down the PWM dimmer, has the only advantage that you don't invest in hardware just to find out it does not work or is not required.

A mentality question, rather :wink:

I did come across PWM to analog in a comunication book. In TV circuts, they have these circuits. They call Integrator. I did a small simulation using Circuit Wizard, I use Virtual Pulse generator ( set the duty cycle ) and a virtual scope. The circuit I was testing was a Integrator. A RC circuit. I simply adjust the right R and the right C for a nice low ripple voltage. I test with 5 V @ 1 K Hz. The RC is 100 k - 0.1 uF. At 10 %, I measure about 1.5 V and at 90 %, I measured about 4.5 V. With the help of a op-amp use as a buffer, you got a crude "digital - Analog". Since the frequency of a PWM is 490 Hz, I guess a RC of 100 K - 0.1 uF will work. At low %, you got a low voltage out, a high %, you got a higher voltage out.

As to help the OP, the output of that circuit going to a op-amp wired as Voltage - Current converter config, and you are in the game. Just experiments and see what happen.

But, as retrolefty point out, the resistance of the "meter" has to be know. You have to do some reversed engineering - testing / measurements to find that out. Just use V = R X I. That is a start.

The circuit is :

PWM in ---- Resitor ----- Vout
|
|
Cap
|
|
GND