Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Using an ADC0804LCN to read an analog sensor

Mon Dec 05, 2022 7:26 am

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.

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Mon Dec 05, 2022 1:13 pm

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Ω

ghp
Posts: 3038
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Using an ADC0804LCN to read an analog sensor

Mon Dec 05, 2022 1:52 pm

This could match your needs: https://www.mikroe.com/4-20ma-r-click

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Mon Dec 05, 2022 4:46 pm

This could match your needs: https://www.mikroe.com/4-20ma-r-click
ouahaha! $31 dollars!!!!!

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

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Tue Dec 06, 2022 5:53 am

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?

vffgaston
Posts: 89
Joined: Wed May 13, 2020 3:33 pm

Re: Using an ADC0804LCN to read an analog sensor

Tue Dec 06, 2022 9:33 am

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

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Tue Dec 06, 2022 11:39 am

How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA?
The sensor itself is the current source. It will provide 4..20ma maximum.

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.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Tue Dec 06, 2022 12:47 pm

danjperron wrote:
Tue Dec 06, 2022 11:39 am
How are they then getting a current of 4-20 mA and a voltage of 1-5V? 24/250 = 0.096 mA?
The sensor itself is the current source. It will provide 4..20ma maximum.

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.
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
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Tue Dec 06, 2022 9:30 pm

I'm using a 24V psu. Does this go for the input of the ADS as well?
No! you will damage your Pi and ADC.


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
pressure.jpg (35.84 KiB) Viewed 589 times

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 5:55 am

Thanks for this awesome reply. Is there any particular reason that you grounded A1 to A3?

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 6:37 am

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?

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 9:48 am

danjperron wrote:
Tue Dec 06, 2022 9:30 pm
I'm using a 24V psu. Does this go for the input of the ADS as well?
No! you will damage your Pi and ADC.


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
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
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 2:52 pm

Is there any particular reason that you grounded A1 to A3?
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.
The only thing that is confusing me here is here is that with the 250 ohm resistor
This is simple.

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.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 3:02 pm

Oh its a noise issue. Thanks.
danjperron wrote:
Wed Dec 07, 2022 2:52 pm
Is there any particular reason that you grounded A1 to A3?
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.
I get this, but there's a 47k ohm resistor as well. Doesn't that affect the voltage?

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Wed Dec 07, 2022 5:13 pm

I get this, but there's a 47k ohm resistor as well. Doesn't that affect the voltage?
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.
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.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Thu Dec 08, 2022 6:01 am

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.

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Thu Dec 08, 2022 11:35 am

Any ground pin will do!
" A0 Voltage *1000.0 / 100 ohm => current in mA " I suppose this formula I should include in my code. to display the current
And then a formula to convert ma to pressure with some calibration parameter.

Or a formula to convert Volt to pressure with calibration parameter.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Thu Dec 08, 2022 12:10 pm

It's actually an ethylene sensor. 0 - 10 PPM

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Thu Dec 08, 2022 6:27 pm

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.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Fri Dec 09, 2022 5:30 am

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?

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Fri Dec 09, 2022 9:39 am

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?

danjperron
Posts: 4275
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using an ADC0804LCN to read an analog sensor

Fri Dec 09, 2022 1:02 pm

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?
Yes but some library will give you the numeric number and some the actual Voltage.

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.
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?
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.

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.

Tanjiro
Posts: 17
Joined: Mon Dec 05, 2022 6:46 am

Re: Using an ADC0804LCN to read an analog sensor

Thu Dec 22, 2022 7:48 am

danjperron wrote:
Fri Dec 09, 2022 1:02 pm
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?
Yes but some library will give you the numeric number and some the actual Voltage.

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.
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?
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.

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.
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.

Return to “Beginners”