Using a 20mA current loop or 40-200mV signal with a Raspberry Pi and ADC0804

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
Beginner here. Kind of in a new, slightly intimidating unknown territory.

I need to connect a transmitter which outputs a 4-20mA signal to a Raspberry Pi 4. I’m using an ADC0804 since the Pi cannot read analog inputs. The transmitter has two modes. Here is the 4-20mA mode: https://postimg.cc/mh1MJf7k. It can also be operated with a voltage 40-200 mV output: https://postimg.cc/4Ys9YYqH. How do I go about wiring the sensor to the ADC and then the Pi? Also, what would the code look like to read this value?

Which of these two modes would be easier/simpler?

Thank you very much.
 

Ya’akov

Joined Jan 27, 2019
6,855
Beginner here. Kind of in a new, slightly intimidating unknown territory.

I need to connect a transmitter which outputs a 4-20mA signal to a Raspberry Pi 4. I’m using an ADC0804 since the Pi cannot read analog inputs. The transmitter has two modes. Here is the 4-20mA mode: https://postimg.cc/mh1MJf7k. It can also be operated with a voltage 40-200 mV output: https://postimg.cc/4Ys9YYqH. How do I go about wiring the sensor to the ADC and then the Pi? Also, what would the code look like to read this value?

Which of these two modes would be easier/simpler?

Thank you very much.
Welcome to AAC.

I edited the title of your thread to make it more informative. Please try to use titles that indicate what is in your message.

Have you considered a module that provides an interface the RPi can use directly like I²C or serial? This is an example (just for reference). It will save you a lot of time and trouble compared to rolling your own.
 

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
Welcome to AAC.

I edited the title of your thread to make it more informative. Please try to use titles that indicate what is in your message.

Have you considered a module that provides an interface the RPi can use directly like I²C or serial? This is an example (just for reference). It will save you a lot of time and trouble compared to rolling your own.
Thanks, I'll definitely consider that. I also wanted to ask, in this diagram https://postimg.cc/mh1MJf7k , they use 250 ohm resistor with a 24V psu. How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA

Also, if the current signal and voltage share the same wire, how would I connect this to the ADS which has a max of 5V?
 

Ya’akov

Joined Jan 27, 2019
6,855
Thanks, I'll definitely consider that. I also wanted to ask, in this diagram https://postimg.cc/mh1MJf7k , they use 250 ohm resistor with a 24V psu. How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA

Also, if the current signal and voltage share the same wire, how would I connect this to the ADS which has a max of 5V?
The sensor's current draw is proportional to its signal.

The voltage across that sense resistor will vary with the current. If the sensor draws 4mA, the voltage across the sense resistor will be 1V (\( 0.004A \times 250Ω = 1V \)) while 20mA will be 5V (\(9 0.02A \times 250Ω = 5V \)), and all intermediate values will scale between the two.

Measuring voltage drop across a sense resistor is how current is measured.
 

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
I see, that makes sense. How would I then feed that current signal to the ADS module? In order to measure current I need to break the line, i.e. put the meter in series with the circuit otherwise I wouldn't get the correct reading if I measure in parallel as with voltage.

Therefore I'm a bit confused as how to go about wiring the sensor to the ADS module.
 

Ya’akov

Joined Jan 27, 2019
6,855
I see, that makes sense. How would I then feed that current signal to the ADS module? In order to measure current I need to break the line, i.e. put the meter in series with the circuit otherwise I wouldn't get the correct reading if I measure in parallel as with voltage.

Therefore I'm a bit confused as how to go about wiring the sensor to the ADS module.
If you measure the voltage drop across a known value resistor, you can calculate the current since \( E = I \times R \). So, for example a 1Ω resistor will have a 1V drop for each ampere passing through it. In this case, a 250Ω resistor scales the drop across from 1V to 5V when 4mA to 20mA pass through.

When you measure the voltage parallel to the resistor it will be proportional to the current, and because you know the resistor’s value, and you know the voltage you measure you can use \( I = {E \over R} \) to calculate the current.
 

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
If you measure the voltage drop across a known value resistor, you can calculate the current since \( E = I \times R \). So, for example a 1Ω resistor will have a 1V drop for each ampere passing through it. In this case, a 250Ω resistor scales the drop across from 1V to 5V when 4mA to 20mA pass through.

When you measure the voltage parallel to the resistor it will be proportional to the current, and because you know the resistor’s value, and you know the voltage you measure you can use \( I = {E \over R} \) to calculate the current.
Yes true, I understand this. But I still don't know how I would connect this sensor to the ADS module that converts the current signal to I²C.

For instance, it's easy with a three-wire pressure/level/flow sensor etc. Since two of the wires are used to power the sensor (+, -), and the third wire will carry the 4-20 mA signal. So then I would just connect the third wire (4 - 20 mA signal wire) to the ADS module as a current input. Straight forward. However, that is not possible here.

So, I guess what I'm asking basically is how would physically connect this sensor to the analog current input of the ADS module?
 

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
Yes true, I understand this. But I still don't know how I would connect this sensor to the ADS module that converts the current signal to I²C.

For instance, it's easy with a three-wire pressure/level/flow sensor etc. Since two of the wires are used to power the sensor (+, -), and the third wire will carry the 4-20 mA signal. So then I would just connect the third wire (4 - 20 mA signal wire) to the ADS module as a current input. Straight forward. However, that is not possible here.

So, I guess what I'm asking basically is how would physically connect this sensor to the analog current input of the ADS module?
Would I perhaps need a voltage to current converter or something along those lines?
 

Ya’akov

Joined Jan 27, 2019
6,855
The measurement across the sense resistor is just a voltage directly proportional to current. Your ADC can only measure voltage in any case. In the example of the 250Ω sense resistor, the current values are in a range from 1V to 5V. So, you jus have to scale those numbers in your program. If you see 1V on the ADC, you have 4mA of current, if you see 5V you have 20mA and so:

Loop CurrentVoltage DropLoop CurrentVoltage DropLoop CurrentVoltage DropLoop CurrentVoltage Drop
4mA1.00V8mA2.00V12mA3.00V16mA4.00V
5mA1.25V9mA2.25V13mA3.25V17mA4.25V
6mA1.50V10mA2.50V14mA3.50V18mA4.50V
7mA1.75V11mA2.75V15mA3.75V19mA4.75V
20mA5.00V

You just have to map the 4-20mA range onto the 1-5V range using whatever map function the language you are using has..
 

BobTPH

Joined Jun 5, 2013
6,074
Ya’akov has been trying to tell you, but you don’t seem to be getting it.

Connect a 250Ω resistor from the 4-20 mA signal to ground. Connect the junction of the signal and resistor to the ADC input. You will now measure 1-5 volts in the ADC.

The resistor IS the current to voltage converter.
 

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
Ya’akov has been trying to tell you, but you don’t seem to be getting it.

Connect a 250Ω resistor from the 4-20 mA signal to ground. Connect the junction of the signal and resistor to the ADC input. You will now measure 1-5 volts in the ADC.

The resistor IS the current to voltage converter.
Thank you so much guys for bearing with me, I really appreciate your awesome responses. My understanding is a lot clearer now. This was the answer I was looking for as well - how to physically connect the sensor to the A0-A3 pins of the ADC. From the " junction of the signal and resistor to the ADC input ".

Also, on this specific "gravity" ADC module pictured above, the voltage on analog input pins must be less than VCC 0.3V.

Should I rather use another ADC or just use the 40 - 200 mV voltage mode of my sensor instead?
 

Ya’akov

Joined Jan 27, 2019
6,855
Thank you so much guys for bearing with me, I really appreciate your awesome responses. My understanding is a lot clearer now. This was the answer I was looking for as well - how to physically connect the sensor to the A0-A3 pins of the ADC. From the " junction of the signal and resistor to the ADC input ".

Also, on this specific "gravity" ADC module pictured above, the voltage on analog input pins must be less than VCC 0.3V.

Should I rather use another ADC or just use the 40 - 200 mV voltage mode of my sensor instead?
You can scale it as you would like but the smaller the signal the more likely you will have problems with noise. I will leave it to others to suggest an ADC one way or the other. I know there are some folks here with much more experience in ADCs than I have.
 

BobTPH

Joined Jun 5, 2013
6,074
Also, on this specific "gravity" ADC module pictured above, the voltage on analog input pins must be less than VCC 0.3V.
Not sure what that means, did you mean Vcc+0.3V which is likely the absolute max input voltage?

I found this in the specs:
  • Supply Voltage (VCC): 3.3~5.0V
  • Analog Signal Detection Range: 0~VCC
So, if you power it with 5V it can convert inputs up to 5V. Thus a 250Ω resistor gives you the desired range.
 

Reloadron

Joined Jan 15, 2015
7,075
Also, on this specific "gravity" ADC module pictured above, the voltage on analog input pins must be less than VCC 0.3V.
OK I get where you are going with this and the 0.3 volts. Most of these modules use the ADS1115 Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs With Internal Reference, Oscillator, and Programmable Comparator. Now if we read the linked data sheet Analog input voltage VDD + 0.3 volt. This is not a problem. Another consideration is while we read 16 bit the reality is one bit is used for the sign. So you have 0 through 32767 bits. These are the boards (modules) I like using. Nice feature is Pgain (Programmable Gain) which in your case is not important. If powered with 5.0 volts you can't exceed 5.3 volts on an analog input. You also have four single ended analog inputs or you can code for two differential analog inputs. The default gain if not called out in your code is 2/3 gain:
Code:
ads.setGain(GAIN_TWOTHIRDS);  +/- 6.144V  1 bit = 0.1875mV (default)
So you have a 1 to 5 volt input which will be your 2 to 20 mA. Now in your code just Map it for whatever engineering units your current loop represents. Make sense?

Ron
 
Last edited:

Thread Starter

Tanjiro

Joined Dec 5, 2022
8
OK I get where you are going with this and the 0.3 volts. Most of these modules use the ADS1115 Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs With Internal Reference, Oscillator, and Programmable Comparator. Now if we read the linked data sheet Analog input voltage VDD + 0.3 volt. This is not a problem. Another consideration is while we read 16 bit the reality is one bit is used for the sign. So you have 0 through 32767 bits. These are the boards (modules) I like using. Nice feature is Pgain (Programmable Gain) which in your case is not important. If powered with 5.0 volts you can't exceed 5.3 volts on an analog input. You also have four single ended analog inputs or you can code for two differential analog inputs. The default gain if not called out in your code is 2/3 gain:
Code:
ads.setGain(GAIN_TWOTHIRDS);  +/- 6.144V  1 bit = 0.1875mV (default)
So you have a 1 to 5 volt input which will be your 2 to 20 mA. Now in your code just Map it for whatever engineering units your current loop represents. Make sense?

Ron
Exactly! Ok that makes sense. Although the raspberry pi's GPIO pins can only tolerate 3.3 V. Meaning that I will have to supply the ADS1115 with 3.3 V, because they have pull-up resistors to Vdd. Meaning the signal voltage on the i2c bus will be the same as the supply voltage of the ADS1115.

That's why I'm now thinking of using a 165ohm resistor to keep the analog input voltage at a maximum of 3.3V, because I can't supply the analog input pins with more voltage than Vdd.

I could even use a 100 ohm resistor which will give me a range of 400mV to 2V, and use a gain of 2.048V.

How does that sound?
 

Reloadron

Joined Jan 15, 2015
7,075
Before I forget something yet again which as get older I tend to do, while the ADS1115 is a pretty cool chip it does have one drawback. It's not very fast. Not slow but not super fast. When I use it I normally allow a 1.0 second delay between readings in my code. Yes, what you have in mind should work just fine. Try to get your resistor value as close as possible. I normally use 250 or 500 ohm 1% precision resistors but yes, for a lower voltage just lower the resistance. I forgot about the 3.3 volts with the RPi. Something else you mentioned is why 24 volt supply for the loop? The transmitter consumes 7 to 15 VDC of loop voltage, depending on model, to power itself. So while it depends on the sensor (Transmitter) and then the burden resistor the general accepted standard is 24 volts.

Pretty sure a Google of "ADS1115 Raspberry Pi" will get you where you want to go. :)

Ron
 
Top