Using Analog Inputs: NodeMCU Beginners’ Guide
This lesson will teach you to read analog inputs using the NodeMCU’s ADC (Analog-to-Digital Converter). This is essential for interfacing sensors like temperature, light, or potentiometers with the NodeMCU.
Understanding ADC (Analog-to-Digital Converter)
The NodeMCU has a single ADC channel that can be accessed using the A0 pin. This pin reads voltages between 0V and 3.3V and converts the analog signal into a digital value ranging from 0 to 1023 (10-bit resolution).
- 0 corresponds to 0V.
- 1023 corresponds to 3.3V.
Important: Supplying more than 3.3V to the A0 pin can damage your NodeMCU.
Reading Analog Values (Using a Potentiometer)
To demonstrate how to read analog values, we will use a potentiometer, which is a variable resistor that provides a voltage divider output.
Components Required:
- NodeMCU
- Potentiometer (10k ohm)
- Breadboard and Jumper Wires(How to use)
Circuit Setup:
- Connect the middle pin (wiper) of the potentiometer to A0 (Analog input pin) of NodeMCU.
- Connect one of the side pins of the potentiometer to 3.3V (VCC).
- Connect the other side pin to GND.

Coding Example
Here’s a simple code to read the analog value from the potentiometer and display it on the Serial Monitor.
void setup() {
Serial.begin(115200); // Start serial communication at a baud rate of 115200
}
void loop() {
int analogValue = analogRead(A0); // Read the analog value from pin A0
float voltage = analogValue * (3.3 / 1023.0); // Convert to voltage
Serial.print("Analog Value: ");
Serial.print(analogValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println(" V");
delay(500); // Delay for better readability of serial output
}
Explanation of Code
Serial.begin(115200);
– Initializes the serial communication at a baud rate of 115200.analogRead(A0);
– Reads the analog value from the A0 pin.float voltage = analogValue * (3.3 / 1023.0);
– Converts the reading to voltage.- The results are printed to the Serial Monitor for easy observation.
Displaying Data on Serial Monitor
To view the readings:
- Upload the code to NodeMCU.
- Open the Serial Monitor from the Arduino IDE (Tools > Serial Monitor).
- Ensure the baud rate is set to 115200.
You should see the analog value and corresponding voltage displayed every 500 milliseconds.
In the next lesson, we will explore connecting NodeMCU to Wi-Fi and sending data to the cloud. Stay tuned!