## How to read 4-20mA signal input

jacquesknie
Posts: 2
Joined: Tue Jul 22, 2014 9:06 am

### How to read 4-20mA signal input

Hi,

I'm a total beginner when it comes to electronics. But I'm working on a project where I have to read a 4-20mA Signal with a Raspberry Pi. What's the best way to do that?

Thanks in advance and all the best,
Jacques

mahjongg
Forum Moderator
Posts: 12400
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

### Re: How to read 4-20mA signal input

A question, what do you mean by a "4-20mA signal"? I happen to remember that the old serial protocol (comparable to RS232) used by old telex machines used 20mA current loop signaling. Is that what you are talking about, a binary signal encoded in the presence or absence of a 20mA DC current? Then I would run the current trough the LED-of an opto-isolator, and use the photo transistor with the emitter connected to GND, and the collector pulled up with a 10K resistor to 3V3, and connect the resulting binary coded voltage to the UART input of the PI. If the coding swaps the "marks" and "spaces" then simply swap the transistor and resistor so the collector is connected to 3V3, and the resistor becomes a pull-down resistor.

If you are talking about a (DC) current that varies (analogue) between 4 and 20mA, a different circuit is needed that convert the current to a voltage, and feeds it to a Analog to Digital converter, connected through either an I2C or an SPI bus to the PI.

PiGraham
Posts: 3671
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

### Re: How to read 4-20mA signal input

It will probably be be an analog signal.
Some general info on 4-20mA here:
http://www.dataq.com/blog/faqs/4-20-ma- ... surements/

You will need something to convert current to voltage, convert to digital and output in Pi comatible form (I2C or SPI are good bets).
You need to be careful about grounds.

This might help
http://microcontrollershop.com/product_ ... ts_id=5460

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

### Re: How to read 4-20mA signal input

Is the 4-20mA source self-powered (if so what voltage?) or is it externally powered (if so what is the voltage range you need to supply it?)

Once those questions are answered then it will be possible to select a method of connecting the 4-20mA signal to the pi.
Doug.
Building Management Systems Engineer.

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

### Re: How to read 4-20mA signal input

The current needs to be converted to voltage first. This is done with a resistor. If the common mode voltage coming from the cables is not important you could connect the resistor directly to an A/D-converter. Otherwise use a high common mode differential or instrumentation amplifier. There are also specific circuits called current receivers that can be used to get the best precision.

yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

### Re: How to read 4-20mA signal input

hampi wrote:The current needs to be converted to voltage first. This is done with a resistor. If the common mode voltage coming from the cables is not important you could connect the resistor directly to an A/D-converter. Otherwise use a high common mode differential or instrumentation amplifier. There are also specific circuits called current receivers that can be used to get the best precision.
As hampi pinpoints there is two ways to connect a 4-20mA current loop signal to a A/D converter.

Particularly I should recommend the Resistor & Differential Op-Amp method since almost Op-Amp available in your draw box can offer good results in most cases and provide some isolation between the transmitter circuit and the converter.

If you need more precision, your should get an instrumentation amp or the more specifics IC's such as the current receivers.

BTW, until some years ago, the 4 - 20mA current loop, the 1 to 5Vdc Voltage sources and the 3 to 15 PSI were the most common (if not are the standard) way to send/receive a analog signal in the industrial arena, nowadays those standard are been migrated to industrial Ethernet and HART or Fieldbus devices.
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

### Re: How to read 4-20mA signal input

yv1hx wrote: BTW, until some years ago, the 4 - 20mA current loop, the 1 to 5Vdc Voltage sources and the 3 to 15 PSI were the most common (if not are the standard) way to send/receive a analog signal in the industrial arena, nowadays those standard are been migrated to industrial Ethernet and HART or Fieldbus devices.
0-10Vdc was a very common analogue signal source, much more common in my experience than 1-5V.

0-10V and 4-20mA and resistance based analogue signals are still very common in Building Services applications.
Doug.
Building Management Systems Engineer.

jacquesknie
Posts: 2
Joined: Tue Jul 22, 2014 9:06 am

### Re: How to read 4-20mA signal input

Thank you all so far!
I will have a look at all this and report back.

Best
Jacques

HeiBau
Posts: 1
Joined: Sat Aug 01, 2015 8:31 pm

### Re: How to read 4-20mA signal input

Simple 4-20 mA current loop testers which allow manual setting of the current in the loop.

Regards,

Heinrich.

robin48gx
Posts: 15
Joined: Mon Jul 16, 2012 11:20 am
Location: Brighton

### Re: How to read 4-20mA signal input

I would really like a Pi Hat that has say four 4-20mA inputs and four 4-20mA inputs.

The 4-20mA signalling protocol is used commonly in industry.

I could lay one out in kicad as its very similar to a project I did with the pi last year ( see https://github.com/robin48gx/TH7 ).
I could re-use the ADC SPI stuff and add some DACS to control voltage to current conversion circuitry.
But its prob 3+ days solid work.

Anyone know if there is a multi channel pi 4-20mA hat out there already ?

scotty101
Posts: 3750
Joined: Fri Jun 08, 2012 6:03 pm

### Re: How to read 4-20mA signal input

Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

robin48gx
Posts: 15
Joined: Mon Jul 16, 2012 11:20 am
Location: Brighton

### Re: How to read 4-20mA signal input

Those both seem to be input only devices.
I require outputs as well.

scotty101
Posts: 3750
Joined: Fri Jun 08, 2012 6:03 pm

### Re: How to read 4-20mA signal input

robin48gx wrote:
Thu Feb 07, 2019 10:55 am
Those both seem to be input only devices.
I require outputs as well.
How about you cut out the middle man and do the googling your self
https://ncd.io/raspberry-pi-analog-outp ... ansmitter/
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Avimesa
Posts: 3
Joined: Thu Jun 27, 2019 9:34 pm

### Re: How to read 4-20mA signal input

We have a 7-channel 4-20mA board that's plug and play with our cloud. Can use a Pi or a Systech (LTE or WiFi) as a gateway. They're running at one of the biggest brands in the world (insert name of crisp fruit here) so they're reliable. https://avimesa.com
robin48gx wrote:
Thu Feb 07, 2019 10:18 am
I would really like a Pi Hat that has say four 4-20mA inputs and four 4-20mA inputs.

The 4-20mA signalling protocol is used commonly in industry.

I could lay one out in kicad as its very similar to a project I did with the pi last year ( see https://github.com/robin48gx/TH7 ).
I could re-use the ADC SPI stuff and add some DACS to control voltage to current conversion circuitry.
But its prob 3+ days solid work.

Anyone know if there is a multi channel pi 4-20mA hat out there already ?

JohnsUPS
Posts: 129
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

### Re: How to read 4-20mA signal input

When you say "4-20ma" signal, that is usually referring to serial communication over a current loop, but as was pointed out, could also be an analog signal that is within that range.

If it is current loop communications that you are referring to, the below may be of help......

If you prefer to roll your own 4-20ma current loop transceiver board, these devices were typically used for that purpose where I used to work:
HCPL-4100 current loop transmitter

Pretty straightforward to implement, but as I noticed when looking up the data sheets, they're not cheap.

stixoffire
Posts: 1
Joined: Sat Aug 03, 2019 7:14 am

### Re: How to read 4-20mA signal input

I see many people are stating that the 4-20ma is usually referring to serial communication; Not in the Industrial world, usually a 4-20ma signal is a representation of a measurement; whether that measurement is PSI, Kp, Fahrenheit, Celsius, Meters, whatever. Typically a device will have a range min/max and that range will be represented by 4-20ma perhaps 0 PSI would be 4ma and 200 Psi would be 20ma. The unit of measure does not matter - only the scale must match the device. You will need to know if the loop is powered or not powered - there are devices built for pi that can read these signals.

JohnsUPS wrote:
Mon Jul 01, 2019 1:58 am
When you say "4-20ma" signal, that is usually referring to serial communication over a current loop, but as was pointed out, could also be an analog signal that is within that range.

If it is current loop communications that you are referring to, the below may be of help......

If you prefer to roll your own 4-20ma current loop transceiver board, these devices were typically used for that purpose where I used to work:
HCPL-4100 current loop transmitter

Pretty straightforward to implement, but as I noticed when looking up the data sheets, they're not cheap.

mahjongg
Forum Moderator
Posts: 12400
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

### Re: How to read 4-20mA signal input

Unlike digital current loops, which often involves simple optical isolators, when talking about the Analog industrial control method, the theoretical solution would be to convert the current to a voltage in a range suitable for an ADC chip using a resistor, and adding an external (I2C or SPI (which could be optically isolated) ADC, see picture below) to the PI.

These days often specialised microcontrollers are used that have built in 20mA receivers.

see: https://en.wikipedia.org/wiki/Current_loop

or use a HAT specifically designed for 4-20mA signalling.

note that the absence of current is/was often used to detect that there is a defect in the control mechanism (a broken wire in the current loop).

Also, prior to using electricity the same mechanism was used with other means, for example pneumatic pressure.

rin67630
Posts: 583
Joined: Fri Mar 04, 2016 10:15 am

### Re: How to read 4-20mA signal input

For industrial 4..20mA you need galvanic insulation, since you may have got other instruments in the loop.
If you tie one pole to GND you might shortcut them.

If you really need a poorman's solution, then you may use a capacitor and two inverting reed relays.

The resistor and 3 diodes are just to protect the input against surges.

To read a value, activate the 2relays (might have a common coil control), wait for ~ 100mS, read the value, release the relay.

rin67630
Posts: 583
Joined: Fri Mar 04, 2016 10:15 am

### Re: How to read 4-20mA signal input

robin48gx wrote:
Thu Feb 07, 2019 10:55 am
Those both seem to be input only devices.
I require outputs as well.
The outputs will be a bit tougher, since you need to provide rather high voltages --> 24V, depending on whether your actuator is powered or not.

mahjongg
Forum Moderator
Posts: 12400
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

### Re: How to read 4-20mA signal input

rin67630 wrote:
Tue Aug 06, 2019 11:03 am
For industrial 4..20mA you need galvanic insulation, since you may have got other instruments in the loop.
If you tie one pole to GND you might shortcut them.
Generally I agree that Optical isolation is most often useful, still some implementations will need it, others won't.
if there is just one 4-20mA source on the other end of the loop, which is powered by the loop, then you might not need optical isolation.

Also, the 4-20mA analog loop doesn't have to be where the isolation happens.
In my example the optical isolation is not on the 3-20mA side, but on the digital interface side, using a digital isolator ADuM5401 which also provide enough power over the isolation to power the ADC and analog logic.

But no, I'm not employed in this industry, I only have encountered a 4-20mA loop once in my career, working on a digital sunlight sensor.

For an analog isolator I would prefer to use an IL300 opto isolator that has a LED irradiating two photo transistors, one phototransistor used on the input side as a feedback for the LED current, with both transistors getting the same amount of light, so drawing an equal amount of current. This way you can control the current draw of the isolated phototransistor. Such an opto isolator doesn't cost much, and I think is cheaper than two dual pole reeds plus the vibrator logic etc.

JohnsUPS
Posts: 129
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

### Re: How to read 4-20mA signal input

What can also be used to keep the current loop isolated while still being able to precisely read the voltage across the scaling resistor used in the loop is a switched capacitor building block, like the LT6943:
https://www.analog.com/media/en/technic ... /6943f.pdf
The output can then be fed into an AD.

If better isolation is needed, there are optoisolators optimized for DC, such as the IL300 opto:
https://www.vishay.com/docs/83622/il300.pdf

I was involved with analog power transducers, meters and calibration standards. Most devices were used in electrical substations. The transducers typically had an analog current source output because of the electrically noisy environments. Meters usually had multiple outputs, either RS232 (back in the day) or a 20ma current loop - both for communication in addition to an analog output via current loop. Usually it was 0-1ma into a 0-10k ohm load, but 4-20ma was also common.