# 4-20mA controlling

hammy: You can take the output from the Arduino and switch a transistor connected to a 10v supply with series resistor . The Arduino is PWM output so you then have a PWM 10v signal - if you drive a smoothing circuit with that then you should get a smooth 0-10v signal .

But, consider that there is the issue of ripple vs responsiveness. The more you reduce ripple, the more sluggish it will be when changing voltage.

One way to increase this ratio is to use a higher PWM frequency. Another is to use a buffer. And yet another is to use an active filter.

This is textbook stuff.

Circuit enclosed.

Allan

420sink.pdf (19.4 KB)

allanhurst: This is textbook stuff.

Circuit enclosed.

Allan

That's good for 0-20mA. But the OP requested 4-20mA. But, you could get away with that by not using the full DAC range [I'm including the PWM technique under that DAC umbrella]. But, if you want the full precision available:

The above is more concepuized-- basically two current sinks, one at a constant 4mA, and the other a Voltage to Current translator [0-5V to 0-16mA]. The combination creates a 4 to 20mA transmitter, with a linear voltage to current transfer. This one is shown with a simple PWM low-pass filter.

And, this one is a more practical diagram. The Op-Amps can be any common mode to ground, single supply device that can handle whatever voltage is in use, such as the LM324 or the LM358. I forgot to show the supply lines on the op-amps. Tie V- to ground, and V+ to 30V or whatever voltage is the VHigh supply you choose.

The transistors can be 2N3904, or one with a higher max CE voltage, like: MPS06

Typically, a 4-20mA transmitter has a fairly large voltage range going as high as 36V, with 12 to 30V typical. Basically, this voltage needs to be high enough to allow 20mA to flow in the loop--a level that is determined by the total expected maximum resistance in the current loop. BUT, check to see if the device you intend to drive has a max voltage rating, and, at least, comply with that.

For greater precision and probably better response, I suggest using a serial DAC, like the following:

The same page has links to Arduino sample code.

The 10k + 10k voltage divider that follows the DAC is there to reduce the top voltage so there is a greater voltage span in the current loop. Also, it keeps the input voltage within the input range.

And, you will need to incorporate some variable resistors in there, to calibrate the thing to exactly 4mA at 0V in and 20mA at 2.5V in.

Also wise to use stable resistors [e.g. 1% metal film]. And quality trim pots. And, maybe some sort of protection circuitry on the 4-20mA output.

And, if this will be driving some sort of expensive or hard to replace device, then do this at your own risk!

But, good luck getting it to work.

Why use two opamps and two drive transistors. A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R). Leo..

Wawa: Why use two opamps and two drive transistors. A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R). Leo..

Probably. Analog is not my strong suit-- but I don't see any other valid offerings, so I stepped in ;)

Allan's circuit. Change R1 to 37.5k, and add 150k between 5volt and opamp +input. Leo..

Or just drive it with 1-5v to get 4-20mA.

ie use map() to get numbers between 51 and 255 for the analogWrite value. That'll give you a resolution of about 0.5% as against 0.4% using the full range. A bit worse, but simple. If this isn't good enough you'll have to use a suitable external DAC.

And ( my mistake) the NPN shown should be eg a BC337 etc, NOT a BC327 which is PNP.

Allan

ps In any case the PWM resolution error is swamped by others :

unless you spend out for super accurate resistors it'll need calibrating.

With typical 1% ones you can get up to 3% error.

And if driven from the arduino's +5 that'll have an error of a couple of percent as well - much worse if using USB power. That's the arduino error - not my circuit, which doesn't care.

Leo's mod DOES make it sensitive to the +5 error, as do ReverseEMF's suggestions.

The opamp's errors are much smaller.

So I recommend calibration . eg make the 100 ohm 75R with a 47R adjustable preset in series.

I haven't bothered with temperature coefficients here - that's another ballgame! How accurate do you need to be?

Allan

allanhurst: Leo's mod DOES make it sensitive to the +5 error, as do ReverseEMF's suggestions.

Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM. Both using the same Arduino VCC. Please explain. Leo..

Wawa: Why use two opamps and two drive transistors. A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R).

OK, I played around with this, using 1 OpAmp and resistors as you suggested... Have you tried the math on that?!? Horrendous--unless I'm missing something. And calibration is a nightmare, because adjusting one side, moves the other side. In other words, adjust it to 4mA when the input is at 0V, then change the input to 5V and adjust for 20mA, and the current goes to 5mA when the input is at 0V, etc. I even tried anticipatory overshoot, and it was still difficult! I suppose if I finished the math. I reached this, and gave up:

I would call that impractical!

In fact, one of my first jobs [back in the late 80's] was at the Jensen Filtration Plant in Sylmar, CA. And most of the sensors were 4-20mA. Occasionally lightening would knock one or more of them out, and recalibrating them after repairing them was a b***h, for this very reason!

My two OpAmp circuit can be easily calibrated, because there is no interaction when adjusting the extremes.

Wawa: Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM. Both using the same Arduino VCC. Please explain.

My circuit is vulnerable to tolerance variations in the Arduino 5V regulator (in other words, each Arduino will have a slightly different "5V" actual value. e.g. one might be 5.04V, another 4.98V, etc). Also, like allenhurst said, resistor tolerance is also a source of error. That's why I suggested calibration.

The Arduino regulator is fairly stable if driven by the Raw Power input, but if more precision is needed, then use the external DAC, and run it with a precision regulator--one that can be adjusted to exactly 5.00...V [limited by error modes in the DAC] and a regulator that will hold that voltage over a temperature range expected in "the field".

Allenhurst described how to add calibration trimmers. But, I wouldn't do that on the emitter resistor -- it will heat up, slightly, which may skew the resistance, and thus, the output current. Also, thermal expansion and contraction could nudge the wiper on the trimmer, knocking it out of calibration.

Instead, I would place calibration trimmers on the 10k resistors that go to ground: 9k + a 2k trimmer, or something like that.

Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM. Both using the same Arduino VCC. Please explain. Leo..

No - just saying that the simple opamp circuit does not contribute to this error.

edit - because of the high PSRR of the opamp /edit

And we still don't know what error is tolerable in the OP's application - any suggestions ,Wosche?

Allan

So sorry to the late response.

First of all, thanks to you all for the discussion and the tips :) Hoping to be able to contribute the same to others in the forum :)

I don't supply the Arduino via USB, just because i would have to adjust the output voltage to minimize the error it would make.

The idea with the simple circuit and adjusting my output to 1-5V seems to be the easiest way of getting what I want. As far as I have seen the error would be up to 3% right? I have the opportunity to geht the restistors with quite an accurat value, although I think i would try to calibrate it

Hi Wosche..

yeah -that's the way I'd go. Simple and probably good enough. Cal for better accuracy.

If you decide to calibrate you don't need to buy more accurate resistors - the cal process deals with this.

ReverseEMF:

Allenhurst described how to add calibration trimmers. But, I wouldn't do that on the emitter resistor -- it will heat up, slightly, which may skew the resistance, and thus, the output current. Also, thermal expansion and contraction could nudge the wiper on the trimmer, knocking it out of calibration.

Maybe. Even at 20mA, the resistor only dissipates 40mW total and the pot at 25 ohms setting 10mW - not much. But adjusting the input divider is also perfectly viable. There's a hundred ways to skin this cat.

Allan

If I do the 4-20mA conversion, I will share it here. It would be quite a helpful thread, because I didn't find anything similar helpful here in the forum :)

Thank to all :)

You're not the first to have problems here - but it's not that hard.

The other end - the 'receiver' is a bit more complex, but not too bad.

This stuff has been around since the 70's( or before?) and is a standard throughout many industries.

Allan

allanhurst: If you decide to calibrate you don't need to buy more accurate resistors - the cal process deals with this.

...but, be sure to use stable resistors -- for both the fixed and variable. I.e. ones whose resistance will vary little with temperature (i.e low enough Temperature Coefficient). Also, pay attention to Minimum and Maximum Operating Temperature, if that will make a difference in your application.

allanhurst: Maybe. Even at 20mA, the resistor only dissipates 40mW total and the pot at 25 ohms setting 10mW - not much. But adjusting the input divider is also perfectly viable. There's a hundred ways to skin this cat.

True, it's not much power, and my concern is informed by my experience with thermistors. Even small current through a thermistor can heat it and skew the reading. But, maybe I'm overreacting ;) Still, better safe than sorry, and since the job can be done on the lower current side, doesn't that make more sense?

Whatever.

A typical metal film resistor has a tempco of <100 ppm/C .A cermet preset a bit worse. A typical NTC thermistor has 3-4%/C. Different ballgame.

If the OP's happy with 0.5% resolution it's not significant. Either way would do.

Just don't put a thermistor in by mistake!

Allan.

Sorry to resurrect an old post, but I have too have been using an AD694 for the 4-20mA output and an Adafruit MCP4725 DAC with a 0-5V output. The AD694 datasheet is a bit vague around using input spans other than the standard 0-2 and 0-10V. I've been scratching my head for a while but I think I can answer the OP's initial question.

Basically its as simple as treating the buffer amp as a non-inverting amp - in the 0-10V span mode pins 1 (FB) and 2 (sig-) are connected therefore the buffer amp is a simple voltage follower. If you wish to use a different input span connect a resistor between pins 1 & 2, and a resistor between pin 2 and ground. The ratio between the resistors governs the gain. A gain of 2 will enable 0-5V input to equate to 4-20mA output.

My first post on here so I hope this helps

I wouldn't worry about the resistors, if the OP needs something more stable then they should look at the PWM output voltage. Without going through a lot of numbers I believe it is the largest source of error in this implementation.