i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
-
- Posts: 16
- Joined: Tue Jan 23, 2018 5:31 am
i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
I want to use my esp32 to measure a water quality parameters like pH, ORP etc. by ANALOG PINS
I have codes written for ARDUINO BOARD. so those codes give me output in a 10-bit resolution which is mapped between 0 to 5 volt.
but in an ESP32-WROOM board by default, it gives 12-bit resolution(0 to 4095) and which is mapped between 0 to 3.3 volt.
by using analogReadResolution(10) I'm able to change resolution but it gives me improper readings as the analog pins are mapped on 0 to 3.3 volt.
so how can I get readings like an Arduino analog pin???
when i give 5 volts, I want 1023 ADC reading on pin36 and 0 when I give 0-volt
insert how can I map ADC pins between 0 to 5 volt??
I have codes written for ARDUINO BOARD. so those codes give me output in a 10-bit resolution which is mapped between 0 to 5 volt.
but in an ESP32-WROOM board by default, it gives 12-bit resolution(0 to 4095) and which is mapped between 0 to 3.3 volt.
by using analogReadResolution(10) I'm able to change resolution but it gives me improper readings as the analog pins are mapped on 0 to 3.3 volt.
so how can I get readings like an Arduino analog pin???
when i give 5 volts, I want 1023 ADC reading on pin36 and 0 when I give 0-volt
insert how can I map ADC pins between 0 to 5 volt??
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
A voltage divider is a simple circuit for linearly dividing an input voltage to an output voltage. For example, if you have an input voltage of between 0 and 5V and you want an output voltage of between 0 and 3.3V then you want to divide your input voltage by 5/3.3 or approx 1.515..
for example:
5 / 1.515 = 3.3
If you google on the phrase "voltage divider" you will find a ton of hits. When we say the voltage divider is a circuit ... well ... technically it is ... but it consists of only two resistors. See the following:
https://learn.sparkfun.com/tutorials/voltage-dividers
In fact the example shown at that page is for conversion of 5V to 3.3V.
for example:
5 / 1.515 = 3.3
If you google on the phrase "voltage divider" you will find a ton of hits. When we say the voltage divider is a circuit ... well ... technically it is ... but it consists of only two resistors. See the following:
https://learn.sparkfun.com/tutorials/voltage-dividers
In fact the example shown at that page is for conversion of 5V to 3.3V.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- 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)
Hello, sir kolban,
sorry, sir, I cannot explain my problem properly.
in Arduino, if we read analog pin it gives output between 0 to 1023
means when I'm reading an analog pin and connect this pin to 5 volts I will receive 1023 on the serial monitor, (i'm connecting the analog pin to supply voltage for checking purpose, not with the sensor.)
when i connect this pin to 3.3 volt it gives 660 on serial monitor.
when i connect this pin to 0 volt it give 0 on serial..
I have codes they are designed only for Arduino.
but i want to use this code for esp32. and want same result.
now in ESP 32 I'm using pin 33. this pin is on 10 bit resolution. for esp32 when I'm connecting this pin to 3.3 it gives 1023 perfect but I want same reading as Arduino
so I must have to change this pins reference voltage to 5v same as Arduino. but don't know how to do this.
and I don't want to change those codes.
so I just want that if I'm giving external 5 volts to analog pin then I want 1023, for 3.3 I want 660 something, and for 0 volt 0
so is there any option to achieve this???
or guide me to any other option
sorry, sir, I cannot explain my problem properly.
in Arduino, if we read analog pin it gives output between 0 to 1023
means when I'm reading an analog pin and connect this pin to 5 volts I will receive 1023 on the serial monitor, (i'm connecting the analog pin to supply voltage for checking purpose, not with the sensor.)
when i connect this pin to 3.3 volt it gives 660 on serial monitor.
when i connect this pin to 0 volt it give 0 on serial..
I have codes they are designed only for Arduino.
but i want to use this code for esp32. and want same result.
now in ESP 32 I'm using pin 33. this pin is on 10 bit resolution. for esp32 when I'm connecting this pin to 3.3 it gives 1023 perfect but I want same reading as Arduino
so I must have to change this pins reference voltage to 5v same as Arduino. but don't know how to do this.
and I don't want to change those codes.
so I just want that if I'm giving external 5 volts to analog pin then I want 1023, for 3.3 I want 660 something, and for 0 volt 0
so is there any option to achieve this???
or guide me to any other option
-
- 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)
kolban wrote:A voltage divider is a simple circuit for linearly dividing an input voltage to an output voltage. For example, if you have an input voltage of between 0 and 5V and you want an output voltage of between 0 and 3.3V then you want to divide your input voltage by 5/3.3 or approx 1.515..
for example:
5 / 1.515 = 3.3
If you google on the phrase "voltage divider" you will find a ton of hits. When we say the voltage divider is a circuit ... well ... technically it is ... but it consists of only two resistors. See the following:
https://learn.sparkfun.com/tutorials/voltage-dividers
In fact the example shown at that page is for conversion of 5V to 3.3V.
Hello, sir kolban,
sorry, sir, I cannot explain my problem properly.
in Arduino, if we read analog pin it gives output between 0 to 1023
means when I'm reading an analog pin and connect this pin to 5 volts I will receive 1023 on the serial monitor, (i'm connecting the analog pin to supply voltage for checking purpose, not with the sensor.)
when i connect this pin to 3.3 volt it gives 660 on serial monitor.
when i connect this pin to 0 volt it give 0 on serial..
I have codes they are designed only for Arduino.
but i want to use this code for esp32. and want same result.
now in ESP 32 I'm using pin 33. this pin is on 10 bit resolution. for esp32 when I'm connecting this pin to 3.3 it gives 1023 perfect but I want same reading as Arduino
so I must have to change this pins reference voltage to 5v same as Arduino. but don't know how to do this.
and I don't want to change those codes.
so I just want that if I'm giving external 5 volts to analog pin then I want 1023, for 3.3 I want 660 something, and for 0 volt 0
so is there any option to achieve this???
or guide me to any other option
-
- Posts: 76
- Joined: Tue Sep 12, 2017 11:25 am
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
Hi, I think the simplest way to do it is with a function that makes the rule of three....
For 5v then 1024
Xv then?????
(Xv*1024)/5
Greetings
For 5v then 1024
Xv then?????
(Xv*1024)/5
Greetings
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
What your after is called "Aref" pin. This pin allows the A/D converter to work at different voltage ranges.
The issue here is that the "ARDUINO BOARD" has this pin but the ESP32 (from what I am reading here) does not, and is fixed at +3.3v
So your going to have to accomplish this in hardware via say a resistor divider.
https://www.espressif.com/sites/default ... ual_en.pdf
The issue here is that the "ARDUINO BOARD" has this pin but the ESP32 (from what I am reading here) does not, and is fixed at +3.3v
So your going to have to accomplish this in hardware via say a resistor divider.
https://www.espressif.com/sites/default ... ual_en.pdf
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
The ESP32 works on 3.3V so you will have to use a voltage divider. Applying up to 5 volts to your ESP32 is quite likely to destroy your ESP32.
The circuit diagram below shows a voltage divider R1 and R2. Espressif documentation on the ADC (here) suggests using a 0.1μF capacitor to reduce noise. A higher value of capacitor would further reduce any noise picked up but would slow down measurement of fast changes of input voltage.
The ESP32 ADC does not work right down to zero volts input, as shown by illustrative calibration graph in the same documentation. If you need to be able to measure small voltages, you could add an extra resistor R3 which would be a relatively high value.
You will need to calibrate the ADC as described in the documentation (with the voltage divider circuit in place). With R3 in place, applying zero volts to the circuit input should not give a digital value of zero. Applying 5V to the circuit input should not give maximum 12-bit binary value (4095). You will then need to use these two calibration digital values in your code to convert to a range of 0 to 1023. If you do not use R3, you will need to calibrate with a small voltage that gives a digital reading that is not zero.
The circuit diagram below shows a voltage divider R1 and R2. Espressif documentation on the ADC (here) suggests using a 0.1μF capacitor to reduce noise. A higher value of capacitor would further reduce any noise picked up but would slow down measurement of fast changes of input voltage.
The ESP32 ADC does not work right down to zero volts input, as shown by illustrative calibration graph in the same documentation. If you need to be able to measure small voltages, you could add an extra resistor R3 which would be a relatively high value.
You will need to calibrate the ADC as described in the documentation (with the voltage divider circuit in place). With R3 in place, applying zero volts to the circuit input should not give a digital value of zero. Applying 5V to the circuit input should not give maximum 12-bit binary value (4095). You will then need to use these two calibration digital values in your code to convert to a range of 0 to 1023. If you do not use R3, you will need to calibrate with a small voltage that gives a digital reading that is not zero.
-
- 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)
I have 8 analog sensors for water quality measurement. They all have metering circuit to measure electrode readings.
For example [url]https://www.dfrobot.com/wiki/index ... U:SEN0165)
these sensors and metering circuits are design for an ARDUINO for 5volt and for 10 bit resolution.( 5v AREF that gives 0-1023 range) all the codes are design for Arduino.
So they all are giving me proper output.
But I want send those 8 sensors data over WiFi..and ESP32 has more analog pins..
Using some functions I'm able to change the resolution to 10 bit...
But the problem is, this gives me 10 bit resolution for 3.3 volt(for 0 it goves 0 and for 3.3 it gives 1023) all the codes and output depends on ADC counts
And ESP32 gives 1023 on 3.3v so i will never get proper output for voltage greater then 3.3.
So how can I achieve same result as Arduino..
I want same 5v 10 bit resolution as Arduino.. because changing all the code is time consuming and may be I will not getting proper results..
So how can I achieve this..
Obviously In ESP32 for above 3.3v I get 1023.
So is there anything to change AREF of ESP32 !?
Or
Is there any coding logic to map 5volt 10 bit resolution to 3.3v using map function for ADC count?
Any suggestions are appreciated.
For example [url]https://www.dfrobot.com/wiki/index ... U:SEN0165)
these sensors and metering circuits are design for an ARDUINO for 5volt and for 10 bit resolution.( 5v AREF that gives 0-1023 range) all the codes are design for Arduino.
So they all are giving me proper output.
But I want send those 8 sensors data over WiFi..and ESP32 has more analog pins..
Using some functions I'm able to change the resolution to 10 bit...
But the problem is, this gives me 10 bit resolution for 3.3 volt(for 0 it goves 0 and for 3.3 it gives 1023) all the codes and output depends on ADC counts
And ESP32 gives 1023 on 3.3v so i will never get proper output for voltage greater then 3.3.
So how can I achieve same result as Arduino..
I want same 5v 10 bit resolution as Arduino.. because changing all the code is time consuming and may be I will not getting proper results..
So how can I achieve this..
Obviously In ESP32 for above 3.3v I get 1023.
So is there anything to change AREF of ESP32 !?
Or
Is there any coding logic to map 5volt 10 bit resolution to 3.3v using map function for ADC count?
Any suggestions are appreciated.
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
Archibald, explained what you need to do. You need to add a voltage divider to each of your A/D input pins. There is no software way around this.
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: i want to map analog pins on 5volt between 0 to 1023 (10 bit resolution)
My favorite on that: https://www.youtube.com/watch?v=XxLKfAZrhbMmikemoy wrote:Archibald, explained what you need to do. You need to add a voltage divider to each of your A/D input pins. There is no software way around this.
BTW: I can listen to Afrotechmods all day log. Like to EEVblog
Who is online
Users browsing this forum: No registered users and 95 guests