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 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.
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
I.M.O.
I wouldn't use a ADC0804.
And this is why,
- Data output is parallel!. You need a lot of GPIO to get data.
- You need to create your own Vref. if you are using the 3.3V from the PI it wont be stable.
- 8 bit only! there are better adc converter on the market.
I will suggest to get something like ADS1015 or ADS1115. Way simpler to interface, Vref is build-in and you will get better resolution.
Also hat extension are available with the software library already made.
To adapt 4..20 ma to and ADC converter the simple solution is to convert the range to 3.3V instead of 5V.
If you are using the ADS1115 I will set the reference to 2.048V (this is the gain setting). then the resistor divider could be 2.048V/20ma = 102.4 Ω => so 100Ω
I wouldn't use a ADC0804.
And this is why,
- Data output is parallel!. You need a lot of GPIO to get data.
- You need to create your own Vref. if you are using the 3.3V from the PI it wont be stable.
- 8 bit only! there are better adc converter on the market.
I will suggest to get something like ADS1015 or ADS1115. Way simpler to interface, Vref is build-in and you will get better resolution.
Also hat extension are available with the software library already made.
To adapt 4..20 ma to and ADC converter the simple solution is to convert the range to 3.3V instead of 5V.
If you are using the ADS1115 I will set the reference to 2.048V (this is the gain setting). then the resistor divider could be 2.048V/20ma = 102.4 Ω => so 100Ω
Re: Using an ADC0804LCN to read an analog sensor
This could match your needs: https://www.mikroe.com/4-20ma-r-click
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
ouahaha! $31 dollars!!!!!This could match your needs: https://www.mikroe.com/4-20ma-r-click
you could buy a $3 ads115shield from aliexpress or a $15 ads1115 shield for Raspberry Pi from amazon.
You will only need a 100ohm resistor and the 24V power supply which you should already have.
B.T.W. you could use th 200mv voltage output since the ADS1115 could have a span of +/- 256mv.
The only problem I see using the voltage is noise. You will need to have the Pi near the sensor. On 4..20 ma noise is shunt by the resistor so it could be far away
Re: Using an ADC0804LCN to read an analog sensor
Thanks, you guys. Seems like the ADS is the way to go. 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?
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?
Re: Using an ADC0804LCN to read an analog sensor
Just in case you use an ADS1115 (I'd recommend it), you can find a base library right here:
https://github.com/Clave-EIDEAnalog/EIDEAnalog
which is fully documented here:
https://github.com/Clave-EIDEAnalog/DOCS
https://github.com/Clave-EIDEAnalog/EIDEAnalog
which is fully documented here:
https://github.com/Clave-EIDEAnalog/DOCS
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
The sensor itself is the current source. It will provide 4..20ma maximum.How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA?
Since you didn't give us the exact specification of the sensor we don't know the minimum operating voltage of the current loop but in the industrial world 24V is the standard.
Like I said replace the 250 ohm with a 100 ohm instead. Use a 47K beteewn the ADC input pin and the 100ohm to prevent overvoltage in case of a faulty connection.
Be sure that the gnd (0V) of the 24V power supply is connected to your raspberry pi gnd.
Re: Using an ADC0804LCN to read an analog sensor
It's a 12 - 36 V operating voltage. I'm using a 24V psu. Does this go for the input of the ADS as well?danjperron wrote: ↑Tue Dec 06, 2022 11:39 amThe sensor itself is the current source. It will provide 4..20ma maximum.How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA?
Since you didn't give us the exact specification of the sensor we don't know the minimum operating voltage of the current loop but in the industrial world 24V is the standard.
Like I said replace the 250 ohm with a 100 ohm instead. Use a 47K beteewn the ADC input pin and the 100ohm to prevent overvoltage in case of a faulty connection.
Be sure that the gnd (0V) of the 24V power supply is connected to your raspberry pi gnd.
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
No! you will damage your Pi and ADC.I'm using a 24V psu. Does this go for the input of the ADS as well?
The 4..20ma loop its a loop like the term it self explain. The loop it from the PSU, to the pressure transducer, to the resistor and finnaly return back to the PSU.
Be sure that you PSU 0V (GND) is connected to the PI GND.
When you will read the ADS1115 the library should return the voltage read at A0. then it is just a small conversion to read the current. and from the current readout you should be able to get the pressure.
A0 Voltage *1000.0 / 100 ohm => current in mA
N.B. if the current is less than 4 ma you have a fail system. something is wrong with your wiring.
Re: Using an ADC0804LCN to read an analog sensor
Thanks for this awesome reply. Is there any particular reason that you grounded A1 to A3?
Re: Using an ADC0804LCN to read an analog sensor
I was considering using this ADC : https://postimg.cc/yWV1nqLG
However the voltage on analog input pins must be less than VCC 0.3V. Should rather use another ADC or just use my sensor in 40-200mV mode instead?
However the voltage on analog input pins must be less than VCC 0.3V. Should rather use another ADC or just use my sensor in 40-200mV mode instead?
Re: Using an ADC0804LCN to read an analog sensor
The only thing that is confusing me here is here is that with the 250 ohm resistor, I know that my voltage range is between 1-5 V, and therefore I can convert that in the python program. However with this circuit I'm not too sure what voltage I'll be feeding into the ADC...danjperron wrote: ↑Tue Dec 06, 2022 9:30 pmNo! you will damage your Pi and ADC.I'm using a 24V psu. Does this go for the input of the ADS as well?
The 4..20ma loop its a loop like the term it self explain. The loop it from the PSU, to the pressure transducer, to the resistor and finnaly return back to the PSU.
Be sure that you PSU 0V (GND) is connected to the PI GND.
When you will read the ADS1115 the library should return the voltage read at A0. then it is just a small conversion to read the current. and from the current readout you should be able to get the pressure.
A0 Voltage *1000.0 / 100 ohm => current in mA
N.B. if the current is less than 4 ma you have a fail system. something is wrong with your wiring.
pressure.jpg
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
Noise issue if you don't use them ground them. Analog input are on very high impedance so any static will feed to them and perturbate conversion.Is there any particular reason that you grounded A1 to A3?
This is simple.The only thing that is confusing me here is here is that with the 250 ohm resistor
4..20ma current using a 250 ohm resistor will convert the current into 1.. 5V
ohm formula. V = R * I
Using a 100 ohm instead change the output voltage from 4..20ma to 400mV to 2V
The ADS1115 could be set to use the 2.048V reference then your are in the best resolution span.
Re: Using an ADC0804LCN to read an analog sensor
Oh its a noise issue. Thanks.
I get this, but there's a 47k ohm resistor as well. Doesn't that affect the voltage?danjperron wrote: ↑Wed Dec 07, 2022 2:52 pmUsing a 100 ohm instead change the output voltage from 4..20ma to 400mV to 2VIs there any particular reason that you grounded A1 to A3?
The ADS1115 could be set to use the 2.048V reference then your are in the best resolution span.
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
The 47K is to protect the ADC. If you have a failed connection and by error you put 24V on the resistor you could fry all your electronics.I get this, but there's a 47k ohm resistor as well. Doesn't that affect the voltage?
Of course that 100 ohm resistor will burned! unless you put resistor with at least
W = V*V/R => (24 * 24) / 100 => 6 Watts
I does affect the voltage but not by a lot.
Typical input impedance with 2.048V reference is around 6M ohm so the error will be (1 - (6M/(47K+6M)) = .7%.
This is less than 1%. Once you calibrate the unit that error won't be visible and good chance that the overall system error will be worse.
Re: Using an ADC0804LCN to read an analog sensor
Ah, Okay! Makes sense. You mentioned that I would have to connect gnd the Pi on the 0 V of my 24V PSU. However the Pi has a few gnd GPIO pins, which one would I need to connect to 0V?
" A0 Voltage *1000.0 / 100 ohm => current in mA " I suppose this formula I should include in my code. to display the current.
" A0 Voltage *1000.0 / 100 ohm => current in mA " I suppose this formula I should include in my code. to display the current.
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
Any ground pin will do!
Or a formula to convert Volt to pressure with calibration parameter.
And then a formula to convert ma to pressure with some calibration parameter." A0 Voltage *1000.0 / 100 ohm => current in mA " I suppose this formula I should include in my code. to display the current
Or a formula to convert Volt to pressure with calibration parameter.
Re: Using an ADC0804LCN to read an analog sensor
It's actually an ethylene sensor. 0 - 10 PPM
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
Sometimes is fun to simulate to visualize
This is a small example using tinkercad.
I emulate your probe using a potentiometer.
You have two meters one for the current and one which read the Voltage at the 100 ohm resistor. This meter will simulate what the ADS115 will read.
I added a push button and a current limit using two transistors. This is just for fun to demonstrate that a simple add-on could be made to limit the current if you put full Voltage be error. The fault could be simulate by pressing the push button.
this is the link https://www.tinkercad.com/things/5LQNyVTJRxK
You don't need to sign up ! just press the simulate button , bottom left and click the start simulation top center and play with the pot or the push button.
This is a small example using tinkercad.
I emulate your probe using a potentiometer.
You have two meters one for the current and one which read the Voltage at the 100 ohm resistor. This meter will simulate what the ADS115 will read.
I added a push button and a current limit using two transistors. This is just for fun to demonstrate that a simple add-on could be made to limit the current if you put full Voltage be error. The fault could be simulate by pressing the push button.
this is the link https://www.tinkercad.com/things/5LQNyVTJRxK
You don't need to sign up ! just press the simulate button , bottom left and click the start simulation top center and play with the pot or the push button.
Re: Using an ADC0804LCN to read an analog sensor
Wow that's really cool! Definitely some food for thought. Thanks so much for taking the time to do that
I think I'm going to keep it simple though and stick to your advice about the 100 ohm and 47k resistor.
If I use a gain of 2 (2.048V), what will be the relationship between the raw voltage value read by the ads and the converted value?

If I use a gain of 2 (2.048V), what will be the relationship between the raw voltage value read by the ads and the converted value?
Re: Using an ADC0804LCN to read an analog sensor
Also, just for interest sake. I've had the experience before where I did not connect two different Gnd together and as a result of that my sensor values were incorrect. What is the reason for having to connect Gnds together?
-
- Posts: 4275
- Joined: Thu Dec 27, 2012 4:05 am
- Location: Québec, Canada
Re: Using an ADC0804LCN to read an analog sensor
Yes but some library will give you the numeric number and some the actual Voltage.If I use a gain of 2 (2.048V), what will be the relationship between the raw voltage value read by the ads and the converted value?
For the one with actual Voltage The formula is simple
Current for 0 PPM. =>. calibMin = 0.004A
Current for 10PPM =>. calibMax = 0.020A
Load Resistance. =>. Rload = 100Ω. (need to check actual value since it could be 1..5% off)
EthylenePPM =. ((ADCVoltage V / Rload) - calibMin) * 10PPM/(calibMax - calibMin)
For the numeric value you will need to convert it in Voltage first to use the formula.
To discharge electron you need to have a close system. To put everything on the same Voltage potential you need to have a commun reference otherwise it won't work well. An ADC use Voltage then very low current is needed. If you don't use a common gnd then the voltage from gnd of the 24V power supply and the gnd of the ADC converter could be different and they will change the value of the reading.Also, just for interest sake. I've had the experience before where I did not connect two different Gnd together and as a result of that my sensor values were incorrect. What is the reason for having to connect Gnds together?
If you look at my tinkercad schematic the power supply gnd is connected to the negative side of the voltmeter which will be the gnd of the ADS1115.
Re: Using an ADC0804LCN to read an analog sensor
Thanks so much for your help, I completed the setup as per your advice and it seems to be working quite nicely...I really appreciate all the help, wouldn't have been possible without your help.danjperron wrote: ↑Fri Dec 09, 2022 1:02 pmYes but some library will give you the numeric number and some the actual Voltage.If I use a gain of 2 (2.048V), what will be the relationship between the raw voltage value read by the ads and the converted value?
For the one with actual Voltage The formula is simple
Current for 0 PPM. =>. calibMin = 0.004A
Current for 10PPM =>. calibMax = 0.020A
Load Resistance. =>. Rload = 100Ω. (need to check actual value since it could be 1..5% off)
EthylenePPM =. ((ADCVoltage V / Rload) - calibMin) * 10PPM/(calibMax - calibMin)
For the numeric value you will need to convert it in Voltage first to use the formula.
To discharge electron you need to have a close system. To put everything on the same Voltage potential you need to have a commun reference otherwise it won't work well. An ADC use Voltage then very low current is needed. If you don't use a common gnd then the voltage from gnd of the 24V power supply and the gnd of the ADC converter could be different and they will change the value of the reading.Also, just for interest sake. I've had the experience before where I did not connect two different Gnd together and as a result of that my sensor values were incorrect. What is the reason for having to connect Gnds together?
If you look at my tinkercad schematic the power supply gnd is connected to the negative side of the voltmeter which will be the gnd of the ADS1115.