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 pin
adc.INIT_VDD33 gives the system voltage 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.

Using the ADC in NodeMCU
if adc.force_init_mode(adc.INIT_ADC)
 print("ADC Config changed,Restarting the node")
 return -- don't bother continuing, the restart is scheduled

val =

The following shows the result of when the A0 is connected to Ground.




Add a Comment

Your email address will not be published. Required fields are marked *