Go Down

### Topic: Reading a voltage across resistance to measure constant current - Please advise! (Read 515 times)previous topic - next topic

#### RDabs ##### Jul 18, 2019, 09:02 am
I am finding that analog input pins on my Mega 2560 do not behave as I expect. T
To read the current signals from two constant current sensors (oxygen Electrodes) at intervals, I am reading the voltage across a resistance for each one. They operate on 24V and provide a fixed current in the range of 5-20 mA to indicate the oxygen level.

I have used the book "Arduino circuits and projects guide" by Gunter Spanner to set up a voltage divider, so that I have a 550 Ohm resistor in parallel with the divider (R1 = 100 and R2 = 380 Ohms) between the signal input terminal and ground. For protection, I also have a Schottky diode parallel to R1 between the ground and the line to the Analog pin; and another from this pin to 5V. I am referencing the analog pins to the 1.1V reference voltage.
As these are nominal resistance values, I have measured each one before connection, so as to calculate the total resistance for the Voltage drop and the voltage divider ratio. The calculated total resistance is 250 and the measured total (between the sensor input terminals) is 258.

My code for one sensor is attached below. For both sensors I get a current that does not match the current I measure with a meter before connecting the sensors. The two sensors meter measurements are similar, yet the Arduino values also differ for the two sensors. The Arduino values are fairly constant over time. Further, when the sensors are disconnected, I still get a (smaller) reading from the analog pins!
Can you advise what is happening here, and how I can correct it?
Thank you in advance!  Rob

Code: [Select]
`// Measuring two constant current sensors at intervalsunsigned long nowTime;unsigned long prevTime; //time of last recordingconst unsigned long oneMin = 60000;int nowSecs = 0;int printNo;//constant current sensor definitionsconst float voltDividera = 98.8/(98.8 + 377);const float vRef =1.10;const int analogPina = A10;int readingA = 0;const float calA = vRef/1023 * 0.94/voltDividera;float voltageSa = 0;float currenta_mA = 0;void setup() {    //Dissolved oxygen sensor code    Serial.println("Measuring current from sensors with resistors");    analogReference(INTERNAL1V1);    prevTime = 0;    printNo = 1;    Serial.println("Data: printno, secs from start, ReadingA, VoltageA, CurrentA, ");}void loop() {  nowTime = millis();   if (nowTime - prevTime >= oneMin) { //set time when sensors recoreded    prevTime = nowTime;    nowSecs = int(nowTime / 1000);    readingA = analogRead(analogPina);    delay(5);    voltageSa = readingA * calA;    currenta_mA = (1000 * voltageSa / 258);    Serial.print(printNo); Serial.print(", "); Serial.print(nowSecs); Serial.print(", ");        Serial.print(readingA); Serial.print(", ");     Serial.print(voltageSa); Serial.print(", "); Serial.println(currenta_mA);     readingA = 0;    printNo++;  }        }`

#### Grumpy_Mike #1
##### Jul 18, 2019, 09:57 amLast Edit: Jul 18, 2019, 10:05 am by Grumpy_Mike
Quote
a fixed current in the range of 5-20 mA to indicate the oxygen level.
It is not fixed because it changes.
This is known as a current loop interface and is normally 4-20mA.

Why are you adding a diode that will make any reading none linear.

Please post a schematic of your circuit with real component values and part numbers on them. Hand drawn is preferable. Fritzing in not acceptable.

When using float variables all your constants must be float types as well, so
Code: [Select]
`currenta_mA = (1000 * voltageSa / 258);`

Should be
Code: [Select]
`currenta_mA = (1000.0 * voltageSa / 258.0);`

Quote
The calculated total resistance is 250 and the measured total (between the sensor input terminals) is 258.
Did you measure this disconnected from the Arduino? Otherwise a meter resistance measurement with an Arduino connected powered or not is meaningless.

#### RDabs #2
##### Jul 18, 2019, 02:04 pm
Thank you Mike! fast reply.
Yes I did measure the total resistance with the soldered set of resistors etc disconnected from the Arduino.
Thanks for the point about making the numbers floating.

Apologies, by constant I meant that the sensor outputs a constant current (at each level of oxygen), irrespective of resistance between the signal wire and ground (I imagine within reasonable limits). I do not understand how this is done, but the sensor is an Oxyguard Model 420 2-wire Dissolved oxygen probe. The manual recommends a 250 ohm resistance between the signal wire (+) and -ve of the current recorder.

I have attached a schematic of the circuit with the (separately( measured resistances. I don't have part numbers but these are 1W resistors etc. this is a .jpeg - I have just googled Fritzing to see what you meant.
It sounds from your comment that I should remove the diodes?
Rob

#### amdkt7 #3
##### Jul 18, 2019, 04:20 pm
The diodes will have no effect unless the voltages go above or below VCC. They are there for input protection for the Arduino.

I'm still a bit confused and don't have time to read the whole post again, but it looks like your voltage divider resistors are far too small. I would use something in the 10k to 100K range, but same ratio. That's the values for R1 and R2. Simply multiply each by about 100 to get values that will not load down the circuit.

#### raschemmel #4
##### Jul 18, 2019, 04:37 pm
Where's the vendor link for the datasheet for the sensor ?

I don't think you are supposed to add a voltage divider. All constant current circuits of the 4-20mA variety have 250 ohm resistor (sometimes added by user). There are two terminals , the output and GND. The
resistor is in series with the output before the terminal (or after). The constant current is the loop between the two terminals. Adding a voltage divider messes everything up.
Post the datasheet or a link to vendor you bought it from. Your setup sounds totally bogus. We need to verify your setup using the datasheet , which you have yet to post.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### amdkt7 #5
##### Jul 18, 2019, 04:53 pm
Raschemmel, if 20 ma flows through the 526 ohm resistor it will have 10.5 volts across it. That's double what the Arduino input can handle, so it makes sense that you would need a voltage divider. However the values used in that voltage divider will divert too much of the current flow, so they need to be scaled up.

Using this voltage divider calculator :http://www.ohmslawcalculator.com/voltage-divider-calculator

I calculate 100K over 89K for R1 and R2

#### Grumpy_Mike #6
##### Jul 18, 2019, 05:04 pm
Yes but why not just use a resistor that gives you 5V at 20mA?
Then there is no need for a voltage divider and you can throw those diodes away.

The diodes are there for voltage protection on the input get the resistor right and you don't need them.

#### raschemmel #7
##### Jul 18, 2019, 05:15 pmLast Edit: Jul 18, 2019, 05:21 pm by raschemmel
Quote
Raschemmel, if 20 ma flows through the 526 ohm resistor it will have 10.5 volts across it.
Quote
You can't use a voltage divider across a current loop resistor for obvious reasons.

Reducing 10.5V to 5V WITHOUT loading the resistor is done using an OP AMP.

It's called a Voltage Subtractor. (you can't use a Non-inverting output because the output is always greater than one and you need VOUT/VIN =5V/10.5V= 0.4762 which is >1.
Therefore you have to use a Differential Amplifier as a SUBTRACTOR.

The op amp inputs have an input impedance around 100 Mohms so they won't load the resistor and change
the reading.

Quote
Yes but why not just use a resistor that gives you 5V at 20mA?
Quote
And then there's that ....
(525 ohm , FYI)
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### amdkt7 #8
##### Jul 18, 2019, 05:27 pm
Yes but why not just use a resistor that gives you 5V at 20mA?
Then there is no need for a voltage divider and you can throw those diodes away.

The diodes are there for voltage protection on the input get the resistor right and you don't need them.
I don't know if that resistor can be changed, because we are not sure what exactly he his connecting to. It may require 562 ohms. I assumed that it needed to be that.

There is no need to add an op-amp to this circuit. A high impedance voltage divider will do the trick. It will draw some additional current, but scaled properly it is negligible.

The diodes are optional. It depends on how certain that you are that over voltage situations will not occur. Using a high impedance voltage divider such as the 100k over 89K will provide enough current limiting so that the Arduino diodes will not be abused.

#### JCA34F #9
##### Jul 18, 2019, 05:31 pmLast Edit: Jul 18, 2019, 05:45 pm by JCA34F
I see a total R of 249.8 Ohms for the parallel branches, 9.5mA for the R3 branch and 10.5 for the R1, R2 branch and 10.5mA * 98.8 Ohms = 1.0374V for R1, but you still need a 27k in series with analog in pin to protect from 24V in event divider net fails, also a 10 nF ceramic cap from in pin to GND for noise bypass.
A 51R in parallel with 2.7k would give you 50.054 Ohms * 20mA = 1.001V.

#### raschemmel #10
##### Jul 18, 2019, 05:36 pmLast Edit: Jul 18, 2019, 05:38 pm by raschemmel
Why are you using such low values for the voltage divider ? (all those resistors should be >50k)

Pick some higher values
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### JCA34F #11
##### Jul 18, 2019, 06:07 pm
Robbie, 20mA thru 50k would be 1000V!

#### JCA34F #12
##### Jul 18, 2019, 06:26 pm
How does the voltage across R1 compare to Serial prints? You should see 1mA per 50mV across R1.

#### raschemmel #13
##### Jul 18, 2019, 06:27 pmLast Edit: Jul 18, 2019, 06:49 pm by raschemmel
Quote
Robbie, 20mA thru 50k would be 1000V!
Read my post. Do you see anything in my post about a constant-current (limiting) resistor ?
Look at your post: Is that not a voltage divider (with resistors much too small) across the current limiting resistor ?

Quote
Why are you using such low values for the voltage divider ? (all those resistors should be >50k)
R3 is the constant current resistor:
Quote
MATLAB
>> 10.5/526

ans =

0.0200

Is that not 20mA ?

Therefore, R1 & R2  were added by YOU and are not part of the sensor.
The values you chose for that voltage divider are what are messing up you reading.
REMOVE that voltage divider and put your current meter across the sensor and you will read 20mA.

Change the voltage divider resisors to >50k and you will see little change in the current.
You can even double that and go >100k

ALSO, your component designators are wrong.

R1 should be R2 and vice versa , as shown here

Change R2 (the resistor that connects to GND) to 90909.091 (91k) and change R1 to 100k.

The current through the voltage divider will then be 55uA
Quote
MATLAB
10.5/(191000)

ans =

5.4974e-05(A) = 0.000054974A => 55uA

>> ans*1000

ans =

0.0550
The current through the voltage divider with YOUR values is 22.1 mA.

0.0221A/5.4974e-05 = 402 times larger

Your bleeder current through your voltage divider is >the 20mA of your current loop.
Can't you see now why the value you read is double what it should be ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### JCA34F #14
##### Jul 18, 2019, 06:33 pmLast Edit: Jul 18, 2019, 06:40 pm by JCA34F
Not a current limiting resistor, current sensing resistor, to read 20mA current loop. R3 is shunting the R1, R2 branch

Go Up