DC Voltage divider

From Let's Control It
Jump to: navigation, search

WIP.gif

This article only applies to DC voltages.

The ESP8266 has an on board 10 bit analog to digital converter (ADC) and is therefore capable to make a digital representation of an analog tension.
The analog input is not always connected to a module pin, but the ESP-12 does have it.
The ADC has a full range limit of 1 volt, so it requires a device to measure voltages above that value. This device is called a voltage divider and it its most simpl form, it consists of a resistor network with only two resistors.
Somtimes more advanced circuits are required, but that is outside the scope of this article.
Hereunder a schematic representation of a two resistor voltage divider
Voltage-divider.gif
The NodeMCU and the Wemos D1 mini have this network already in place, but for a bare ESP-12, you have to make it yourself.
On the NodeMCU and the Wemos, R2 is 100kOhm (100.000 Ohms) and R1 equals to 220kOhm. Furthermore, the Vout port of the network is connected to the ADC pin of the ESP-12 module and Vin is connected to the A0 pin on the NodeMCU or Wemos board.
According to the formula under the schematic, a tension Vin will result in a Vout that is R2/(R1+R2) times smaller. In this case that will be 100/320 = 0,3125 and that means that a Vin of 3,2 volts results in a Vout of 1 volts.
If you want to measure larger voltages, you simple enlarge R1. R1 can be calculated by slightly reworking the formula to R1=Vin*R2/Vout - R2.
Example: suppose you want to measure 5 volts, with an R2 of 100kOhm, you will need an R2=5*100k/1 - 100k =>400k.

In case of a NodeMCU or Wemos D1 mini, with the network already on board, you can simply add a resistor of 400k-R1=180k in series between A0 and the tension to be measured.