-->
Page 1 of 3

NodeMCU ADC (A0) correct operation

PostPosted: Thu Oct 19, 2017 10:58 am
by songa
I'm using a NodeMCU in the Arduino IDE.
After a lot of research on google, I came up with the following code to measure the power supply through the ADC (A0 pin).

Code: Select allADC_MODE(ADC_VCC); // 3.3v voltage sensor
int vcc;

void setup() {
  Serial.begin(115200);
}

void loop() {
  vcc = ESP.getVcc();
  double dvcc = (float)vcc / 1024;
  Serial.println("Voltage: " + String(dvcc, 3) + "V");
  delay(500);
}

The result is extremely stable, however, the presenting value should be close to 3.3v
Below is the sequence of some values read:

Voltage: 2.881V
Voltage: 2.883V
Voltage: 2.881V
Voltage: 2.883V
Voltage: 2.883V
Voltage: 2.883V
Voltage: 2.881V
Voltage: 2.882V
Voltage: 2.882V
Voltage: 2.883V
Voltage: 2.882V
Voltage: 2.882V

Once I saw this result, I immediately checked the 3.3v power supply of the kit and to my surprise, it was correct with the exact 3.3v

Dear friends of bench, what is missing or is wrong, and it's causing this wrong value?!?

Re: NodeMCU ADC (A0) correct operation

PostPosted: Tue Oct 24, 2017 7:28 am
by QuickFix
As far as I can remember, the A0-pin on a NodeMCU is connected to "Something" (resistor, capacitor, ...) and it needs to be floating in order to be able to use ADC_MODE(ADC_VCC) :idea:

Re: NodeMCU ADC (A0) correct operation

PostPosted: Tue Oct 24, 2017 7:53 am
by rudy
That's right. A0 needs to be free, not connected to anything in order for the internal measurement to work properly.

Re: NodeMCU ADC (A0) correct operation

PostPosted: Tue Oct 24, 2017 3:34 pm
by songa
QuickFix wrote:As far as I can remember, the A0-pin on a NodeMCU is connected to "Something" (resistor, capacitor, ...) and it needs to be floating in order to be able to use ADC_MODE(ADC_VCC) :idea:

rudy wrote:That's right. A0 needs to be free, not connected to anything in order for the internal measurement to work properly.


Both are correct...
And it was exactly in this way that I mounted the circuit being analyzed here.

More suggestions?