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 » Thu May 03, 2018 1:00 am

Four people responding to this thread have said that a voltage divider is necessary so the input to the ESP32 never exceeds 3.3V. I have suggested adding an extra resistor to the 3.3V rail in order to avoid the 'dead zone' near zero volts.

If the attenuator within the ESP32 is set to 6dB, the working range of the ADC will be very approximately 0.1V to 2.2V.

The sensor output range of 0V to 5V does not need to be "mapped" to ESP input 0V to 3.3V. The original poster wants 0V to 5V range from a sensor to give the digital range 0 to 1023.

Please explain why you think a FET is necessary.

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 » Thu May 03, 2018 1:16 am

I understood he has problem with 5V because it is too high to read on esp.
Now I honestly am not sure what exactly and how is to be measured

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 03, 2018 5:58 am

Archibald wrote:
Deouss wrote:I would use a simple amplifier with max 5V output or adjusted to scale between 0-5V output.
There's no need for an amplifier. The sensors already have outputs in the range 0V to 5V so the voltage must be a reduced, not amplified, before going into the ESP32.
Deouss wrote:Another way is also to run it again through AD-DA converter with 5V out.
A voltage output is not required. The original post asks for readings as if using the analogue to digital converter of a 5 volt Arduino. In other words digital values 0 to 1023 are wanted (as I understand it).
Deouss wrote:Also you can just connect ADC IC with SPI and read stuff in the code but I think you should just rewrite your code to use 3.3V with higher resolution
The voltage corresponding to maximum digital value will depend on the setting of the attenuator associated with each ESP32 analogue to digital converter; it will not be 3.3V.

THANK YOU @Archibald I'm able to get proper readings.
now as you said how can I measure voltage or get information about that voltage associated with each ESP32 ADC converter, as you said it will not be 3.3.
and another question the sensor is working on 5 volts but output range is 4.5 so I have to use 4.5 to 3.3v converter????
and for some sensor I don't have info about output voltage.. so how can I get max voltage because the sensor has electrode type probe.

https://www.dfrobot.com/wiki/index.php/ ... KU:SEN0237
https://www.dfrobot.com/wiki/index.php/ ... KU:SEN0161

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 » Thu May 03, 2018 11:16 am

It is interesting - I bought PH Tester and soon will use it
here link: aliexpress.com/item/1Set-Liquid-PH-Value-Detection-Regulator-Sensor-Module-Monitoring-Control-Meter-Tester-BNC-PH-Electrode-Probe/32805675619.html
Looks like a similar situation but very easy to use
Check this article
http://scidle.com/how-to-use-a-ph-sensor-with-arduino/

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 03, 2018 2:40 pm

rankit0092 wrote:THANK YOU @Archibald I'm able to get proper readings.
now as you said how can I measure voltage or get information about that voltage associated with each ESP32 ADC converter, as you said it will not be 3.3.
and another question the sensor is working on 5 volts but output range is 4.5 so I have to use 4.5 to 3.3v converter????
and for some sensor I don't have info about output voltage.. so how can I get max voltage because the sensor has electrode type probe.

https://www.dfrobot.com/wiki/index.php/ ... KU:SEN0237
https://www.dfrobot.com/wiki/index.php/ ... KU:SEN0161
In an earlier post you referred to an ORP sensor:
https://www.dfrobot.com/wiki/index.php/ ... U:SEN0165)
That is probably a good sensor to start with (whether or not you are going to use it). It measures the voltage on the electrodes with a range of -2000mV to +2000mV. The electronics on the circuit board of the sensor has unity gain (inverting) but provides an offset of 2V. So the output range is 0V to 4V with 2V corresponding to zero volts from the electrodes. However it will not be exactly 2V due to resistor tolerances principally in the sensor's electronics

If you are using my "Option 2", including the voltage divider circuit, you need to use the serial monitor to display the digital reading from the ADC when zero volts is connected to the input of the voltage divider. Because of the extra resistor connected to 3.3V, that value should not be zero and must not be zero. You also need to get the digital reading from the serial monitor when 5V is connected to the input of the voltage divider circuit (don't connect 5V to the ESP32 !). That digital value must be less than 4095 to ensure it's in the working range of the ADC. Ideally, also use a digital voltmeter to measure the precise voltage of your 5V supply. The difference in the digital values will correspond to a change of input voltage of 5V, so dividing the difference in digital values by 5 will give you the change in digital value per volt. Now connect your ORP sensor to the voltage divider and press its 'Calibrate' button which shorts out the electrodes. Again, read the digital value from the serial monitor. You would then know the digital value that corresponds to zero electrode volts and the sensitivity of the ADC in terms of change of digital value per volt. It's then a simple matter to calculate the electrode volts for any ADC digital reading.
Deouss wrote:It is interesting - I bought PH Tester and soon will use it
here link: aliexpress.com/item/1Set-Liquid-PH-Value-Detection-Regulator-Sensor-Module-Monitoring-Control-Meter-Tester-BNC-PH-Electrode-Probe/32805675619.html
Looks like a similar situation but very easy to use
Check this article
http://scidle.com/how-to-use-a-ph-sensor-with-arduino/
@Deouss . . . . . . . yes, it's simple for a 5 volt Arduino, especially as they provide code. It's not so simple for an ESP32 that cannot tolerate inputs over 3.3V, has an ADC input 'dead zone' near zero volts, and has an input range up to very roughly 2.2V (with attenuator set to 6dB).

Pibbotley
Posts: 45
Joined: Fri Feb 16, 2018 7:06 pm

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

Postby Pibbotley » Thu May 03, 2018 6:30 pm

Having faffed around with The ESP32 ADCs inputs for a while I can reiterate what other posters have said. Use a voltage divider to scale down the sensor output - if using the default 11db attenuation, divide to less than 3.1V as the ADC tops out at around 3.14V. Apply a bias voltage of at least 200mV to avoid the 0V deadzone. Between these voltages the ADC is reasonably linear at 11db. Calibrate each ADC pin by recording the ADC value at min and max sensor output. A 100nf cap makes a huge difference to stability. Use an exponential filter to smooth the ADC readings. Make sure non of the ADC pins are floating as they are very sensitive to EMF.

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 » Thu May 03, 2018 8:17 pm

This device - PH meter - as I see in the output table - goes from 414.12 to -414.12 mV
https://www.dfrobot.com/wiki/index.php/File:Ph-mv.jpg
So knowing a bias value on input which is obviously higher that 0 or even 1V it is super easy to measure the PH just by reading analog value from gpio and converting it based on that voltage/ph table. I'd say no ADC is needed - why?

Also I just looked at the water quality tester which is dissolved oxygen sensor and it has analog output 0-3V which is actually perfect for ESP because adding bias 300mV will get you correct results. (3.0+0.3V => 0.3 to 3.3V out)

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 » Tue May 22, 2018 5:54 am

@Archibald @ Deouss

can u give me a way to find maximum output voltage of my water sensors?

https://www.dfrobot.com/wiki/index.php/ ... KU:SEN0161
https://www.dfrobot.com/wiki/index.php/ ... U:SEN0165)

this sensor gives results with Arduino but until now I'm unable to get proper readings.

these codes are designed for ARDUINO so how can I get readings for my ESP32??
THANKS FOR YOUR SUPPORT

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 1:02 pm

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.

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:10 pm

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
I just read the ADC docs section and see that this meter should be fine with no attenuation (0db) with range 0-1.1V (correct me if Im wrong) So for proper readout some reference voltage(higher of 412.12mV) must be added to input unless ADC can read negative values?
max voltage to be added is 1.1-412.12*2=0.27576= 275.76mV or just increase attenuation with higher voltage
Last edited by Deouss on Tue May 22, 2018 2:35 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 125 guests