Using the ADC in NodeMCU

NodeMCU has on analog channel which is configured to read the System voltage, we can configure it to sample the external pin.

The ADC seems a bit jumping around for constant voltages as well, so it is better to take average of several readings if you are doing something serious with it.

adc.force_init_mode(mode) allows to set the modes.

The modes for the ADC are

adc.INIT_ADC for sampling external pinadc.INIT_VDD33 gives the system voltage

adc.read(0) to sample the external pin, adc.readvdd33() to read the system voltage. You have to set the node in correct mode before you call the corresponding methods. You will get 65535 if the node is not in correct mode.