Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?
/* Conductivity (using a voltage divider):
======================================
pin 6 => Probe central electrode
pin 7 => 100 KOhm resistor
connected to node with:
=> Probe perimeter electrode
=> Analog pin 0 (A0)
=> 100 KOhm resitor connected to Arduino GND
DEFINITIONS
------------*/
//Pinout
#define CONDUCTIVITY_WAVE_OUT 6
#define CONDUCTIVITY_POWER_OUT 7
#define CONDUCTIVITY_READ A0
The in the set-up I call the function
void conductivitySetup(){
pinMode(CONDUCTIVITY_POWER_OUT, OUTPUT);
pinMode(CONDUCTIVITY_WAVE_OUT, OUTPUT);
pinMode(CONDUCTIVITY_READ, INPUT);
}
And to get raw readings I use:
int getRawConductivity(){
int n=sampleNumber(COND);// This justget the number of samples to get
int stackC[n];
getConductivitySignal(stackC,n);
// The amplitude of the signal is
int amp=stackC[3*n/4]-stackC[n/4];
// Now is important to define some concepts
// resistivity = especific resistivity of the material, an intrinsic material property
// resistance = the resistance to current flow of a given piece of material in a given geometry, it depend on the geometry and the resistivity of the material
// conductivity = 1/resistivity
// conductance = 1/resistance
// The amplitude amp is related to resistance of the water by
// Rw = R * (V-amp)/(2*amp)
// Where R is the value of the resistor in the conductivity voltage divider
// and V is the max voltage in the same units than amp, so in this case V=1023
// Now the conductance of the water will be
// cw= 2*amp/(R*(V.amp))
// Assuming there is a linear relationship between conductance and conductivity (which should be the case and with a zero linear constant)
// we can say that the conductivity of the water is given by
// Cw = cw * F + K = (2*amp/(R*(V.amp))) * F + K
// Where F (and K) are constants dependent of the probe
// Given this is not a linear relationship, in order to get more accurate results using linear interpolation we can define the relative amplitude A:
// A = amp/(V-amp);
// therefore:
// Cw = (2/R) * A * F + K;
// In fact we can take any arbitrary value for R (in 2015 design R=100 kOhm), as any difference with the real value will be absorbed by F on the calibration. Wirg R=2 we get
// Cw = A * F + K;
// Which is a linear relation, and should lead to more accurate interpolation/extrapolation results using linear interpolation/extrapolation
// In the range 0-120 uS amp will be WELL below amp=993, that correspond to A=32.767 therefore we can store A in the int range multiplying it by 1000
// We return then A*1000 limiting it to a max value of 32767, which is the maximum value of a 2 bites integer
// This 1000 factor would lead to a change in A*1000 of one or more for a any change of one in amplitudes of 13 or more, which is well below the range of expected amp
// therefore there is no loss of accuracy
return int(min(1000.0*amp/(1023.0-amp),32767.0));
}
Which make use of
void getConductivitySignal(int *stackC,int n){
int sdelay=samplingDelay(COND);
analogWrite(CONDUCTIVITY_POWER_OUT, 255);
analogWrite(CONDUCTIVITY_WAVE_OUT, 128);
delay(sdelay);
readAnalogPin(CONDUCTIVITY_READ, n, 0, stackC);
analogWrite(CONDUCTIVITY_POWER_OUT, 0);
analogWrite(CONDUCTIVITY_WAVE_OUT, 0);
}
That also uses
void readAnalogPin(int pin, int n, int sdelay, int *stack){
for(int i=0; i<n;i++){
stack[i]=analogRead(pin);
delay(sdelay);
}
sort(stack, n, 0);
}
And you will need a sort function, here is the one I'm using
void sort(int *ar, int n, int *idx){
// Sort function using the quicksort arlorithm
// It will sort the elements in ar
// If idx>0 it will arragnge the elements in idx in the same way that they are in ar
// As sorting a two colum table based on the elements of one colum
if (n < 2)
return;
// We choose a pivote p at the middle of the array
int p = ar[n / 2];
int *l = ar; // Left pointer, to the start of the array
int *r = ar + n - 1; // Right pointer, to the end of the array
// We move all the elements smaller than p to the left and the ones grater than p to the right
// Therefore the value p ends up in it final position of the sorted array
while (l <= r) {
if (*l < p) {
l++;
}else if (*r > p) {
r--;
}else {
int t = *l;
*l = *r;
*r = t;
if(idx>0){
t=*(idx+(l-ar));
*(idx+(l-ar))=*(idx+(r-ar));
*(idx+(r-ar))=t;
}
l++;
r--;
}
}
// Iteration stops when l is to de right of r
// Now from the start to r we have all elements smaller or equal than p
// And from l to the end we have all elements greater or equal than p
// Now we operate recursively doing the same process in the two sub arrays:
// start to r
// l to end
sort(ar, r - ar + 1,idx);
if(idx>0){
sort(l, ar + n - l,idx+(l-ar));
}else{
sort(l, ar + n - l,0);
}
}
Re: Inductive charging set as inductive conductivity sensor?
Re: Inductive charging set as inductive conductivity sensor?