Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Dsbaha
#25406 I've been searching for a while about a possible voltage divider setup. I'm having trouble calculating the values for the resisters to make it work.

Essentially, I have a sensor mapped to the ADC pin of the ESP8266. The sensor itself uses a range of vdd/2 to vdd (my vdd being 3.34v).

So, essentially I've been trying to calculate the voltage dividers so;
VDD/2 (1.67v) would be 0 and VDD(3.34) would be 1023. I would like it to scale in a linear fashion within the range.

I understand that the ESP8266 ADC can only measure from 0v to 1v.

Currently, I've been using the values without success;
R1 = 4300k (to v3.3) to ADC0 PIN
R2 = 10k (to ADC Source) to ADC0 PIN
R3 = 1k (to GND) to ADC0 PIN

Can anyone point me to an online calculator, or at least the right direction, to find the solution?

Thank You.

EDIT: An example, but can't figure it out for some reason: http://reibot.org/2011/12/26/linear-res ... r-the-adc/
User avatar
By martinayotte
#25410 You scenario is not a simply having voltage divider at the input of ADC since you asked to get an offset of VDD/2 the be the '0' level. In such case, we need to have an OpAmp to do a voltage level subtraction trimmed precisely with a potentiometer. If precision of that subtraction is not mandatory, then maybe 2 diode can do a drop/subtraction of 1.4V (2x 0.7V), but from on diode to another diode, it can change a bit, still 1.4V is not VDD/2.
User avatar
By Barnabybear
#25421 Can you post a link to the sensor please. As the output is Vcc/2 to Vcc it surgests that it can be powered by a dual voltage supply. If powered by +3.3V -3.3V the output would be 0V to 3.3V meaning that a 2.3 : 1 ratio voltage divider would work (2.4k and 1K). The hard work may have already been done for you by the sensor.
User avatar
By kenn
#25443
Dsbaha wrote:Essentially, I have a sensor mapped to the ADC pin of the ESP8266. The sensor itself uses a range of vdd/2 to vdd (my vdd being 3.34v).


As per Martin, this is not simply a linear scaling problem.

I've tackled a similar problem in the analog realm; on our boat I wanted to have good analog metering on the boat battery. From knowing the characteristics of a lead-acid battery, all the useful info is between 10v and 15v, so I wanted the analog meter to have 10v at the extreme left, and 15v at the extreme right. The solution is to 'throw away' the first 10 volts by putting a ~10v zener diode in series with the measured voltage into a voltage divider which now sees 0 to 5v for an input of 10 to 15 v. Add a 0-5v analog voltmeter, re-do the meter scale for 10 to 15 v... done. This is known as an expanded-scale voltmeter.

it might be hard to find a single zener with a voltage of vdd/2, but 3 forward-biased silicon diodes in series is around 1.6 to 1.8v; also the voltage drop across a red LED is in the neighbourhood of 1.8v. Then scale the input to the A/D for 0-vdd/2 -> 0-1v. Accuracy of the whole system could be improved by having some calibration factors poked into the flash.

For more control of the lower voltage, some sort of level-shifter or adjustable reference (opamps) would be necessary. You'd need to prevent the voltage presented to the A/D from ever going negative.