## Electrical Resistance Calculation Help

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

drgeoff, thank you for your response in helping me integrate a resistor. I am now attempting to add in a resistor on channel one (but not channel 8 - will read voltage supplied without resistor). Actually 10k ohm resistor, not 1k.

Here is what I added to my calculation function.

Code: Select all

``````def calc(v,vd,mA,e=0.67,r=10000):
if (v-vd > 0 and mA > 0): cur = (v-vd)/mA   # current with supplied V and measured V
else: cur = 0                               # poss 0's
if (cur>0 and vd>0): ohms = vd/cur      # ohms with supplied V and current
else: ohms = 0                              # poss 0's
if (cur>0 and vd>0): us = cur/vd            # siemens with current and supplied V
else: us = 0                                # poss 0's
ec = ohms*1000                              # EC (more calcs to come with volume of container
# temperature consideration eventually
tds = ec*e                                  # TDS conversion using e
return v, vd, cur, ohms,  us, ec, tds

``````
v = volts supplied
vd = volts measured through water
e = TDS conversion for water solutioin
r = resistor value

The results don't match though. I've tried using your formula (1000 x Vw/(3.3 - Vw) = Rw) in my code's ohm calculation like so:

Code: Select all

``````    ohms = r * (vd/(v-vd))
ohms = vd/cur ``````
Rw = ohms
ohms = 10,000 * (0.415128 / (3.296314 - 0.415128))
ohms = 10,000 * (0.415128 / 2.881186)
ohms = 10,000 * 0.144082332761578
ohms = 1,440.082332761578

But I don't think the ohms are 1,440~... I am getting an ohm reading of 0.072041 ohms when EC/TDS results get close to matching with the first code above.

The difference in supplied volts is (no ohms, pins touching):
with 10k resistor: 2.055872v
without resistor: 3.313611v

boyoh
Posts: 1706
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

### Re: Electrical Resistance Calculation Help

To many excuses for not sticking to controlled test , and meter calibration . And in some cases
trying to manipulate Ohms Law to suite the test results.

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

drgeoff, can you verify the formula I am using? I don't think I have it right. I ran some tests using the formula (r*Vw)/(3.29-Vw)

Code: Select all

``````medium		EC	volts	Vw	formula		ohms
Drinking water	18	3.29	1.31	1310 / 1.98	661.6
Tap water	488	3.29	1.87	1870 / 1.42	1316.9
Salty water	1956	3.29	2.06	2060 / 1.23	1674.8
``````
The EC/TDS is increasing going from drinking water to tap water to salty water but the ohms is going up as well. Shouldn't ohms drop as the water gets saltier?

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

I think I need the difference between the supplied voltage (Vs - 3.3) and the voltage drop (Vw). By adding the Vd the ohms begin to move down as salinity increases.

Vd = Vs - Vw
1000 x Vd/(3.3 - Vd) = Rw

CosmoNerd
Posts: 3
Joined: Thu May 03, 2018 12:09 pm

### Re: Electrical Resistance Calculation Help

First an apology, my calculation was not quite correct. However, the good news is here is some corrected code:

Code: Select all

``````print("Conductance calculation demo")

# Voltage values should be provided in volts, feed resistance value in kOhms
def conductance(V_measured, cal_factor = 1.0, V_supply = 3.3, R_feed = 1.0):
return cal_factor / (V_supply / V_measured - R_feed)

# This value can be used to apply a constant factor to convert conductance to conductivity
Calibration = 100.0

# Output example conversion of sample readings
Typical output for me looks like this:

Code: Select all

``````%run "C:/Users/George.Dishman/Python/Rasp_Conductance_Form.py"
Conductance calculation demo
('Measured voltage =  3.227', ', conductance =   4428.4.')
('Measured voltage =  1.050', ', conductance =     46.7.')
('Measured voltage =  1.915', ', conductance =    138.3.')``````
I think your circuit is not quite as described, you said:
I have a 3.3V pin connected to a 1,000 Ohm resistor, which then goes to two wires about 0.25" apart. With pins touching, the voltage reading is: 3.227126v
If the resistor was connected to 3.3V, shorting the pins would drop the voltage to zero so I think you have the resistor to ground and 3.3V to one of the wires.

vvarrior wrote:
One question, where did you get the initial Rfeed value (1.0)?
Note that I wrote:
The current is I = V/R so working in Volts, kOhms and mA we get ..
You previously said:
I have a 3.3V pin connected to a 1,000 Ohm resistor
and "1,000 Ohm" is 1.0kOhm, the "k" pefix means 1000.
Is this the mA supplied by the GPIO BCM pin? I read somewhere the pins shouldn't be supplying more than 50mA
No, the current is noted in my post as 2.227 mA for one test. The maximum you will draw with the probes shorted will be

3.3V / 1.0 kOhms = 3.3mA so your design is entirely safe.

P.S. Here in the UK we use "." for the decimal indicator and "," to separate thousands, in Europe it is often the other way round in case anyone is confused.

P.P.S. I don't have access to a Pi at the moment, the Python has been written in another package so may need some syntax adjustment.

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

Cosmonerd, Thanks for the correction. I'm in US and we use same decimal and comma. I made a bunch of progress yesterday on all of the code and results. I'm waiting on my new multimeter to compare pi results with actual results. Once I iron out a couple of things, I'll post a picture of completed circuit and code used.

My circuit goes gpio pin 6 (so I can manually turn off probe and not polarize the water) to jumper on breadboard, then to 1,000 ohm resistor, then to another jumper wire to positive probe, then water, then negative probe back to jumper wire to breadboard, then to channel one on ADCPi plus board. I also have a secondary jumper to channel two on ADCPi immediately before the positive probe that goes in the water to get voltage drop for comparison. Unfortunately each jumper to ADCPi channel causes a voltage change in the circuit as well and I need to calculate for that. Hopefully I'm finished with this part today.

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

vvarrior wrote:
Sat May 05, 2018 4:02 pm
My circuit goes gpio pin 6 (so I can manually turn off probe and not polarize the water) to jumper on breadboard, then to 1,000 ohm resistor, then to another jumper wire to positive probe, then water, then negative probe back to jumper wire to breadboard, then to channel one on ADCPi plus board. I also have a secondary jumper to channel two on ADCPi immediately before the positive probe that goes in the water to get voltage drop for comparison. Unfortunately each jumper to ADCPi channel causes a voltage change in the circuit as well and I need to calculate for that. Hopefully I'm finished with this part today.
That does not sound correct. I would expect the negative probe back to breadboard and back to RPi GND. One channel of the ADC connected to the positive probe, the other channel to the junction of GPIO and resistor. GND of ADC to GND of RPi (and negative probe).
Quis custodiet ipsos custodes?

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

Here is an image of my current testing environment to have a place to start... ohm testing.jpg (119.27 KiB) Viewed 2785 times
When I am testing for water resistance, I replace R2 (1k resistor) with a two prong probe that is submerged. I am running a script to test each channel on the ADC for volts. I've placed the numbers in a spreadsheet and remove a pin one at a time.

Code: Select all

``````channels	ch1		ch2		ch3
1,2,3		3.31114		2.7181		1.702519
1,2		3.313611	2.918251	0
1,3		3.316082	0		1.912554
2,3		0		2.723042	1.707461``````
Note: When I attach the negative end of R2 to GND on breadboard, voltage reads 0 at ch3.

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

Remove the connection to ch3. Connect the south end of R2 (probe) to 0V. then repeat your mesurements. Removing one connection to the ADC should not affect the reading of the other, unless the ADC design (or your wiring) is deficient.
You will need to gather new data for your water samples, and re-calculate the results.
Location: 345th cell on the right of the 210th row of L2 cache

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

Changed circuit like so ohm testing 2kohm.jpg (114.99 KiB) Viewed 2763 times
Readings [R1 = 1000 ohm, R2 = 1000 ohm]:
channel 1: 3.266662
channel 2: 1.578969

Readings [R1 = 1000 ohm, R2 = 2200 ohm]
channel 1: 3.283959
channel 2: 2.159654

I will switch R2 with the probe that is submerged once I figure out the formula.

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

That looks better. Now try the resistance calculation.

V2=IR2
(V1-V2)=IR1
So:
R2=V2*R1/(V1-V2)

Be careful about the order of calculation! This will work with values in volts(V), milliAmps(mA), and kilOhms (kΩ).

The conductance is the inverse of resistance. Conductivity (σ) will require an extra constant (K) related only to the geometry of the cell, which can be found by calibration with samples of known conductivity.
Note K cannot be calculated from your the components and measurements of your circuit.

σ = K(V1-V2)/V2/R1

Hope I've got that right. If not, someone will correct me!
Location: 345th cell on the right of the 210th row of L2 cache

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

Those results are heading in the right direction. If the two resistors have exactly the same resistance, one voltage should be exactly half of the other one. If the resistors are exactly 1000 and 2200 the lower voltage should be 5/16 of the higher one.

Repeat the measurements but do this:

1. For the 1000 and 1000 case, swap the two resistors over.

2. For the 1000 and 2200 case, swap them over. Make sure you use the same 1000 resistor that you used with the 2200 for the result in your last previous post.
Quis custodiet ipsos custodes?

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

This is pretty close, within about 5% when resistors aren't terribly different. adc final.jpg (115.25 KiB) Viewed 2686 times
Formula I am using is this:
(v2*r1)/(v2-v1)

Some final results:

Code: Select all

``````v1		r1	v2		vd		v2*r1		r2 calculated	r2	Accuracy
3.236392	39	3.274693	0.038301	127.713027	3334.456724	3300	101.04%
3.202416	39	3.259249	0.056833	127.110711	2236.565217	2200	101.66%
3.086897	39	3.20674		0.119843	125.06286	1043.555819	1000	104.36%``````
I tested with only known resistors and I also soldered v1 and v2 to ADC board. This has been quite the learning experience. Thanks all for your input and direction.

Note: The ADCPi Plus has a voltage drop on each channel and each channel is a different drop. Channel 1 and 2 seemed to have the lowest but the formula doesn't account for that.

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

1. I've had a look at the schematic for the ADC Pi Plus. The channels have a much lower input resistance than a typical digital multimeter. Each channel presents a load of no more than 16,800 ohms. This is in parallel with the probes or test resistor and lowers the apparent value.

For two resistors in parallel, Rx and Ry, the effective resistance is RxRy/(Rx+Ry).

The effect of 16,800 ohms is that a 1,000 ohm resistor becomes 943.8 and a 2200 ohm one appears to be 1945.3.

You can see the effect of and measure the ADC input resistance by omitting R2. If the ADC channel was infinite resistance then v1 and v2 would be equal. Use a 10,000 ohm for R1, leave out R2 and I would expect v2 to be about 2 volts.

The error will become more significant for higher values of water or test resistance.

You can use the parallel formula to "undo" the effect, ie to correct the resistance value you calculate from the ADC voltage reading.

2. I would suggest using a value of R1 higher than 39 ohms. A low R1 means you are dividing by the difference of two almost equal readings which magnifies the result of inaccuracies in them. Also, with R1 less than 200 ohms there is a risk in theory of damaging the GPIO if the probes touch.
Quis custodiet ipsos custodes?

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

I changed the value of r1 to 330 ohms. Because I am using 2 channels (4 and 5 now because after much testing, those two channels read all voltages identical through many different scenarios), won't that mean there is 33,200 ohms added to r2 and r1?
The results got closer with this formula:
r2 = (v2*((16800*r1)/(16800+r1)))/(v1-v2)

Do I also need to correct the r2 result?
r2 = (r2*16800)/r2-16800

Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

### Re: Electrical Resistance Calculation Help

Hi vvarior,

Use a programmable current source circuit/ic like LT3092. Google for application notes.
Measure the voltage accross your sample and divide it with by the current of the current source.
You may set a current by using a dac.
You will find on google many examples. You may start a current from a few nA to ...Amps.
Ferdinand

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

I'm getting myself thoroughly confused in trying to work out which measurements need correction and which don't. So please don't accept what follows without some careful checking.

V1 does not need correction because the source impedance of the 3V3 supply is low.
I think my conclusion is that V2 does not need correction, but in calculating R2 the input resistance of the the V2 channel (call it Rk) must be taken into account.
So, measure Rk using R1=15K, as @drgeoff wrote.
Then calculate R2m as before, (m denotes measured value, c denotes corrected):

R2m=V2*R1/(V1-V2) (Calculate and retain this intermediate value)
R2c=R2mRk/(R2m-Rk) (This is of interest for debugging and validation)

σ=K/R2c
=K(R2m-Rk)/R2m/Rk

Make sure your final value of R1 is mid-range of the R2m values for different samples.
One other thought: I don't know what that board uses as a reference voltage. It must be at least as stable as the 3V3 supply, but independent of it (If not independent, then V1 will give an absolutely unchanging reading).

@ferdinand: A programmable current source is OTT. The combination of (measured) 3V3 supply and (fixed) R1 provides a suitable current source. The difficulty is with the limitation of the ADC, which has a comparatively low input resistance. This will remain a problem even with a more sophisticated current source. If different hardware is to be considered, then a better (high input resistance) ADC is the way to go (or a FET op-amp buffer between the R1R2 junction and the ADC input).
Location: 345th cell on the right of the 210th row of L2 cache

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

davidcoton wrote:
Mon May 07, 2018 12:15 pm
V1 does not need correction because the source impedance of the 3V3 supply is low.
I think my conclusion is that V2 does not need correction, but in calculating R2 the input resistance of the the V2 channel (call it Rk) must be taken into account.
Agreed. Neither voltage needs correction. But the initial calculation using them gives the resistance of the parallel combination of R2 and the ADC, not the wanted R2. A measurement without R2 allows calculation of the resistance of the ADC channel. Knowing that constant value then allows the calculation of R2 or the water.
Quis custodiet ipsos custodes?

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

drgeoff wrote:
Mon May 07, 2018 12:43 pm
davidcoton wrote:
Mon May 07, 2018 12:15 pm
V1 does not need correction because the source impedance of the 3V3 supply is low.
I think my conclusion is that V2 does not need correction, but in calculating R2 the input resistance of the the V2 channel (call it Rk) must be taken into account.
Agreed. Neither voltage needs correction. But the initial calculation using them gives the resistance of the parallel combination of R2 and the ADC, not the wanted R2. A measurement without R2 allows calculation of the resistance of the ADC channel. Knowing that constant value then allows the calculation of R2 or the water.
Yes! Location: 345th cell on the right of the 210th row of L2 cache

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

davidcoton wrote:
Mon May 07, 2018 12:15 pm
.
One other thought: I don't know what that board uses as a reference voltage. It must be at least as stable as the 3V3 supply, but independent of it (If not independent, then V1 will give an absolutely unchanging reading)
Only the very short term stability of the reference is important, ie over the time between reading V1 and V2. The measurement method is that of ratio between a known resistance and an unknown one. The real accuracy of the ADC's voltage reference does not matter as long as it is the same when measuring V1 and V2.
Quis custodiet ipsos custodes?

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

drgeoff wrote:
Mon May 07, 2018 1:23 pm
Only the very short term stability of the reference is important, ie over the time between reading V1 and V2. The measurement method is that of ratio between a known resistance and an unknown one. The real accuracy of the ADC's voltage reference does not matter as long as it is the same when measuring V1 and V2.
True, but accuracy and stability are closely related.
Location: 345th cell on the right of the 210th row of L2 cache

drgeoff
Posts: 12900
Joined: Wed Jan 25, 2012 6:39 pm

### Re: Electrical Resistance Calculation Help

davidcoton wrote:
Mon May 07, 2018 5:00 pm
drgeoff wrote:
Mon May 07, 2018 1:23 pm
Only the very short term stability of the reference is important, ie over the time between reading V1 and V2. The measurement method is that of ratio between a known resistance and an unknown one. The real accuracy of the ADC's voltage reference does not matter as long as it is the same when measuring V1 and V2.
True, but accuracy and stability are closely related.
I think not.

High accuracy requires high stability but high stability is not sufficient for high accuracy.

For example, a voltage source that is always within 10 ppm of 1 volt might be considered highly stable but if it is supposed to be within 100 ppm of 1.1 volts then it is highly inaccurate.

Perhaps you are thinking of repeatability and stability.
Quis custodiet ipsos custodes?

davidcoton
Posts: 6747
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Electrical Resistance Calculation Help

drgeoff wrote:
Mon May 07, 2018 7:12 pm
davidcoton wrote:
Mon May 07, 2018 5:00 pm
[...]
True, but accuracy and stability are closely related.
I think not.

High accuracy requires high stability but high stability is not sufficient for high accuracy.

For example, a voltage source that is always within 10 ppm of 1 volt might be considered highly stable but if it is supposed to be within 100 ppm of 1.1 volts then it is highly inaccurate.

Perhaps you are thinking of repeatability and stability.
It may be a directional relationship, it is close (in that direction) nonetheless.
Location: 345th cell on the right of the 210th row of L2 cache

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

I have run a number of tests and here are some of the results...

Code: Select all

``````v1		v2		r1	r2	r2(cal)		r1(16.8k fix)	r2(16.8k fix)	vd		v2*r1fix
2.154712	3.264191	1000	2200	2776.807387	943.8202247	2382.940343	1.109479	3080.809483
2.401812	3.271604	1000	3300	3550.051073	943.8202247	2930.747338	0.869792	3087.806022
0.785778	3.222184	1000	330	1248.216606	943.8202247	1161.889811	2.436406	3041.162427
1.574027	3.246894	1000	1000	1831.875591	943.8202247	1651.766607	1.672867	3064.484225
2.386986	3.219713	330	1000	1251.35454	323.642732	1164.608241	0.832727	1042.036712
2.782346	3.254307	330	2200	2231.609833	323.642732	1969.935572	0.471961	1053.232808
2.918251	3.266662	330	3300	3034.43753	323.642732	2570.203991	0.348411	1057.231414
3.195003	3.291372	330	33,000	11053.64408	323.642732	6667.035021	0.096369	1065.228626``````
I am estimating drinking water being no more than 33,000 ohms and very salty water (ppm = 2500) being 300 ohms. Here are the following formulas:

vd = v1-v2
r2(calc) = (v2*r1fix)/vd
r1(fix) = (16800*r1)/(16800+r1)
r2(fix) = (16800*(v2*r1fix/vd)/(16800+(v2*r1fix/vd)))

Using the higher 1000 r1 resistor throws everything off. The 330 r1 resistor gets results close until r2 starts moving past 3,300 ohms.

vvarrior
Posts: 97
Joined: Fri Jan 02, 2015 3:03 am

### Re: Electrical Resistance Calculation Help

According to https://www.khanacademy.org/science/ele ... ge-divider I should be using this formula to find r2:
r2 = (-v1*r1)/(v1-v2)

I used the numbers on their site and made some modifications to my spreadsheet and things look like they are closer even with larger ohm resistors, although results are still lower than they should be. I'm assuming there is a current being drawn that isn't being accounted for and I don't think I will find it.

To correct for the error, I believe I am going to have to take a constant and add it to one of the equations. Is the constant I want to add K? for instance, 1.59 or 2.4? Basically for calibration?