Post topics, source code that relate to the Arduino Platform

User avatar
By songa
#70980 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?!?
User avatar
By QuickFix
#71171 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:
User avatar
By songa
#71179
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?