i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby Archibald » Tue May 22, 2018 2:29 pm

Deouss wrote:That PH meter - the value changes\steps up every 59.16mV so question is if ESP's analog reading has resolution of reading such voltage value granularity - e.g 59.19mv resolution.
Maybe it is possible to set up the gpio pin to accept a voltage range of PH values (+-0.41212+bias) mapped to pin readout resolution which is 12bits I assume. I know it is possible on more expensive arm systems
Then you would just read values at the end and divide by 59.16-bias
Evidently you are looking at the table of electrode voltage and pH. The change in electrode voltage would not step; it would be continuous. The electronics amplifies the electrode voltage and provides a very high input resistance so, after calibration, referring to the voltage output from the electroncs:
pHValue = 3.5*voltage + Offset.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby Deouss » Tue May 22, 2018 2:37 pm

my question is why you want to amplify that signal if ADC is so sensitive and works with voltages like 1.1V ?

rankit0092
Posts: 16
Joined: Tue Jan 23, 2018 5:31 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby rankit0092 » Wed May 23, 2018 7:54 am

Archibald wrote:With the input of the pH meter circuit board shorted out (or the electrode in a solution with pH=7) the output should be close to +2 volts. It will not be exactly +2V due mainly to the tolerance of resistor values. That's why when setting up your meter you need to put a value for "Offset" into the code. The next step is to adjust the gain of the amplifier using the preset potentiometer (which should not affect the +2 volts). I see in the Arduino code . . . . .

Code: Select all

pHValue = 3.5*voltage+Offset;
. . . . . so evidently you adjust the gain so a change of pH value of 3.5 gives a change of output voltage of 1 volt (it's an inverting amplifier). The maximum possible pH is 14 so, after adjusting the gain, the theoretical maximum output voltage will be +4.0V. The minimum possible pH is 1, so the minimum voltage should be 1/3.5 = +0.286V. Of course your actual minimum and maximum output voltages will depend on the maximum acidity and maximum alkalinity of the solutions you are measuring. The output voltage could also be limited by the output voltage swing available from the operational amplifiers on the circuit board.

The circuit board of the ORP meter is very similar but has a fixed gain close to unity (inverting). Its output should also be close to +2 volts with input shorted (calibrate button pressed).

The Arduino code below acts as a reasonable voltmeter over the range +0.15V to +3.15V and prints the corresponding pH value (currently with Offset=0).

Code: Select all

long sum;
float average, voltage, pHValue, Offset=0;

void setup()
{
  Serial.begin(115200);
}
void loop()
{
  for (int i=0 ; i<100 ; i++)
  {
    sum = sum + analogRead(34);   // Input pin 34, 12 bits
    delay(10);
  }
  average =sum/100;
  sum=0;
  voltage = average*0.000817 + 0.15;
  pHValue = 3.5*voltage + Offset;
  Serial.printf("V= %4.2f   pH= %4.2f \n", voltage, pHValue);
}
I derived the linear equation coefficients 0.000817 and 0.15 by calibrating my ESP32 against a digital voltmeter.

If you are using ESP-IDF code as example here, I understand you can rely instead on coefficients burned into eFuses during factory calibration (at least for recently manufactured ESP32s).

There remains the question as to whether you need a voltage divider. Without a voltage divider, the coefficients for my particular ESP32 would allow reading of values of pH between 0.6 and 11 (with default ADC attenuation); similarly values of ORP between -1150mV to +1850mV (subject to checking). I don't know anything about ORP but I guess those ranges are sufficient. However it is somewhat risky to connect a 5 volt device to an ESP32; if the signal goes much above 3.3V it could destroy the ESP32. If your sensor electronics is powered by a different power supply to your ESP32, you ought to consider the risk of destroying your ESP32 if the sensor electronics is powered up before the ESP32 is powered up. I would be inclined to only insert a resistor in series with the input of the ESP32 to limit the current but I have not been able to find in the datasheet what current the ESP32 would tolerate. A voltage divider would provide similar protection and extend your pH measurement range.

I have been very unimpressed by the variation between successive digital readings (before averaging). Perhaps I ought to earth other ADC inputs, as recommended by Pibbotley. Also there is noticeable non-linearity above about 2.6V.

thank you so much..!!!
as u said the OUTPUT of PH meter is 4VOLT so now I'm using voltage divider using R1=100K AND R2=470K so I'm getting 3.298V for the ESP32 ANALOG PIN.
I'm getting nearer readings. because of variation of meter and eEFUSES.
now can you help me with that IMAGE for stable reading with 0.1micro farad capacitance. and about R3 resistance. please explain that circuit.
can I use nominal value RESISTOR in SERIES with R1??

and for ORP meter voltage is near 4V but I'm not sure. can u help me with that??? now I'm using the same voltage divider.
using proper voltage divide I will get proper readings so I just want to design that circuit with proper component.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby Archibald » Wed May 23, 2018 10:23 am

With those resistor values, the formula for pH in your code should now be . . . .
pHValue = 4.24*voltage+Offset;

My ESP32 ADC functions over the range 0.17V to 3.15V (corresponding to the digital range 0 to 4095). With that voltage divider in place, the range at the input to the voltage divider would be 0.206V to 3.82V. That corresponds to a pH range of 0.7 to 13.3 (ignoring "Offset"). However that range may be reduced by the output swings available from the operational amplifiers on the circuit board.

From looking fairly quickly at the data on the ORP sensor, that seems to have an output range of 0V to 4V corresponding with a "measuring range" from the probe of -2000mV to +2000mV (I would recommend you check to ensure 0V to 4V does not correspond to the reversed range +2000mV to -2000mV). Using the same voltage divider, my ESP32 would give a measuring range of -1795mV to +1820mV. Again the range may be further limited by the output swings available from the operational amplifiers.

I expect the ranges available for both sensors will be adequate for your purposes but I'm not a chemist! Only if you really need to be able to measure ORP down to -2000mV will you will need to use a resistor R3. If you need to measure up to +2000mV, the voltage divider will need to divide the voltage a little more.

As mentioned, my ADC becomes nonlinear above about 2.7V, in fact it's really very bad . . . .
ADCgraph.png
ADCgraph.png (10.94 KiB) Viewed 9636 times

rankit0092
Posts: 16
Joined: Tue Jan 23, 2018 5:31 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby rankit0092 » Thu May 24, 2018 5:41 am

Archibald wrote:With those resistor values, the formula for pH in your code should now be . . . .
pHValue = 4.24*voltage+Offset;

My ESP32 ADC functions over the range 0.17V to 3.15V (corresponding to the digital range 0 to 4095). With that voltage divider in place, the range at the input to the voltage divider would be 0.206V to 3.82V. That corresponds to a pH range of 0.7 to 13.3 (ignoring "Offset"). However that range may be reduced by the output swings available from the operational amplifiers on the circuit board.

From looking fairly quickly at the data on the ORP sensor, that seems to have an output range of 0V to 4V corresponding with a "measuring range" from the probe of -2000mV to +2000mV (I would recommend you check to ensure 0V to 4V does not correspond to the reversed range +2000mV to -2000mV). Using the same voltage divider, my ESP32 would give a measuring range of -1795mV to +1820mV. Again the range may be further limited by the output swings available from the operational amplifiers.

I expect the ranges available for both sensors will be adequate for your purposes but I'm not a chemist! Only if you really need to be able to measure ORP down to -2000mV will you will need to use a resistor R3. If you need to measure up to +2000mV, the voltage divider will need to divide the voltage a little more.

As mentioned, my ADC becomes nonlinear above about 2.7V, in fact it's really very bad . . . .
ADCgraph.png
thank you so much !!
I'm just shocked you're saying everything so confidently. (for each ADC pin I'm using 10-bit resolution and default attenuation 11dB)
for pH with those resistors, I'm getting proper readings. and right now i'm using that

Code: Select all

pHValue = 3.5*voltage+Offset;
but I'm waiting for STANDARD WATER SOLUTIONS. Once I will get that then I will get an idea.
but can you tell me how can u confidently saying about pHValue = 4.24*voltage+Offset; this???

My ESP32 giving a range of -2995mV to +2000mV (without resistors, without "OFFSET" only by uploading code and giving 0v to 5v directly without connecting ORP meter, AND also WITH ORP meter)so according to this for ORP I'm getting 4.3 volts as an OUTPUT that's why I'm using R1=100 K R2=330K this resistor for dividing and I'm getting 3.3v for input. (UNFORTUNATELY, I HAVE TO WAIT FOR SOLUTIONS FOR CHECKING)

and for DO meter output signal is 0 to 3 volt so no resistor required but for accuracy, I have to give 300mv so (3.0 + 0.3 = 3.3V) so esp32 read it properly. but I have no idea about giving bias voltage.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)

Postby Archibald » Thu May 24, 2018 11:30 am

Let's consider having calibrated your pH sensor on its own (including the electronic circuit board). If pH=7, the output voltage from the electronics should be 2.0V (ignoring the 'Offset' which should be small). If pH=0, the output voltage should be 0V and if pH=14, the output voltage should be 4.0V. That's why there is the coefficient of 3.5 in the Arduino code.

Now let's consider it connected to your ESP32 via your voltage divider. If pH=0, the voltage on the ESP32 analogue input pin should be 0V and if pH=7, the voltage should be 2.0 * 470000 / (470000 + 100000) which is 1.65V. I am assuming your ESP32 code is using the eFuse calibration values so you would get more-or-less the correct value of voltage. I have not checked that with my ESP32. Now to get the pH value, you would need to multiply 1.65 by 4.24.

Unlike the Arduino, my ESP32 ADC works over the range 0.17V to 3.15V. Yours may be a little different. This means that we would not be able to measure extremely acid or extremely alkaline solutions but I don't expect that to be a problem.

I have no idea how the probe of the dissolved oxygen sensor works. You have referred to two versions of sensor. I have been looking at the information on the SKU:SEN0165 (here). That says its measuring range is -2000mV to +2000mV which I take to be the voltage from the probe. Anyway in the circuit diagram (here) resistor R3 connected to -5V will provide an offset of +2.0V at the output. As R1 is equal to R2, the gain of the electronics is unity but inverting.

My understanding is therefore that -2000mV from the probe will give an output of +4V and +2000mV from the probe will give an output of 0V.

The Arduino code converting from dissolved oxygen sensor output voltage to ORP value is more daunting than the code for converting from pH sensor output voltage to pH . . . . .

Code: Select all

orpValue=((30*(double)VOLTAGE*1000)-(75*avergearray(orpArray, ArrayLenth)*VOLTAGE*1000/1024))/75-OFFSET;
. . . . . note "VOLTAGE" here is the supply voltage nominally 5V, and note "OFFSET" here is the small calibration offset, not the 2.0V offset.

The first part . . . .

Code: Select all

30*(double)VOLTAGE*1000
. . . . . when divided by 75 becomes 2000 if the VOLTAGE is 5. This is the 2.0V offset caused by R3, in millivolts.

The second part multiples by 75 and then is divided by 75. This corresponds with the unity gain. Note the minus sign. At present I am ignoring "OFFSET".

With 0mV from the probe the sensor output voltage should be 2.0V and, using voltage divider with resistors 100kΩ & 330kΩ, the voltage at the ESP32 input pin should be 2.0 * 330000/(330000+100000) which is 1.535V. With +2000mV from the probe, the ADC input should be 0V and with -2000mV from the probe the ADC input should be 3.07V. You would need to allow for the voltage divider in calculating ORP values as there will not be unity gain from probe to ADC input. I expect your ESP32 will measure up to 3.07V but it will not measure below about 0.17V. This means you would be able to measure ORP only up to about +1780mV. Is that sufficient or do we really need to add resistor R3 to the voltage divider?

EDIT: I'm finding the ADC has good linearity with attenuation set to 6dB. I therefore suggest using 6dB and making appropriate change to voltage divider. With 6dB, I get an input range of 0.14V to 1.88V.

Who is online

Users browsing this forum: Google [Bot], zelenecul and 113 guests