- The D labels on the board are not GPIO numbers: D1 = GPIO5, D2 = GPIO4, D4 = GPIO2. Write
D1in Arduino code and you get the right pin; write1and you get the TX pin. - The pins you can use without a second thought are D1, D2, D5, D6 and D7. D3, D4 and D8 pick the boot mode, and D0 has no interrupt or PWM.
- Default I2C: SDA D2 (GPIO4), SCL D1 (GPIO5). Default SPI: SCK D5, MISO D6, MOSI D7, CS D8.
- The only analog pin is A0. NodeMCU has a voltage divider on it, so it reads 0-3.3 V as 0-1023.
- The pins are 3.3 V. Don’t feed them a 5 V signal; power the board with 5 V through Vin.
- V2 (Amica) uses a CP2102, V3 (LoLin) a CH340. V3 is wider and swaps two reserved pins for VU (USB 5 V) and GND. The GPIO map is identical.
NodeMCU is the board that put the ESP8266 on a breadboard with USB and a regulator. It is ten years old and the ESP32 has long since arrived, but it is still the board most people pick for their first Wi-Fi project, mostly because it is cheap and almost every tutorial and library already supports it.
And almost everyone trips over the same thing first: the D1 printed on the board and GPIO5 in the code are the same pin. This guide starts with the pinout diagram, then covers that mapping, which pins are safe, I2C, SPI and A0, the power pins, V2 vs V3, and the wiring that keeps the board from booting. If you haven’t set the board up in the Arduino IDE yet, start with our NodeMCU ESP8266 setup guide.
NodeMCU ESP8266 Pinout Diagram
This is probably what you came for, so here it is first:

The diagram shows the component side, antenna up and USB down. The right-hand row is where the work happens:
| Label | GPIO | Default role | Notes |
|---|---|---|---|
| D0 | GPIO16 | Wake from deep sleep | No interrupt, PWM or I2C. HIGH at boot |
| D1 | GPIO5 | I2C SCL | Free, safest pin |
| D2 | GPIO4 | I2C SDA | Free, safest pin |
| D3 | GPIO0 | FLASH button | LOW at boot puts the chip in upload mode |
| D4 | GPIO2 | Blue LED (ESP-12) | Must be HIGH at boot, also TX1 |
| D5 | GPIO14 | SPI SCK | Free |
| D6 | GPIO12 | SPI MISO | Free |
| D7 | GPIO13 | SPI MOSI | Free |
| D8 | GPIO15 | SPI CS | Must be LOW at boot, pulled down on the board |
| RX | GPIO3 | UART0 RX | USB serial line |
| TX | GPIO1 | UART0 TX | USB serial line, prints the boot log |
| A0 | ADC0 | Analog input | 0-3.3 V |
The SD0-SD3, CMD and CLK pins on the left (GPIO6-11) are wired to the board’s flash chip. The arduino-esp8266 docs are blunt about it: try to use them as I/O and your program will likely crash. Leave them alone. That leaves you 11 usable GPIO out of the ESP8266’s 17, plus A0.
If you want to compare against ESP32 boards, our ESP32 pinout tool lets you click through the DevKit, S3 and C3 pins.
D1 or GPIO5? Pin Numbers in Code
Select NodeMCU 1.0 (ESP-12E Module) in the Arduino IDE and the D0-D8 constants are defined for you. Both of these drive the same pin:
digitalWrite(D1, HIGH); // D1 on the board
digitalWrite(5, HIGH); // same pin, GPIO5
The trap is the third option: digitalWrite(1, HIGH) drives GPIO1, the TX pin, not D1. The Serial Monitor turns to garbage and the LED stays off. Porting an Arduino Uno sketch and forgetting to add the D prefix is the single most common mistake on this board.
Which NodeMCU Pins Are Safe to Use?
Short answer: D1, D2, D5, D6 and D7. They have no boot role, work as input or output, and support PWM and interrupts.
For relays, D1 and D2 are even better. Most other pins briefly change level during boot, which is why a relay clicks once every time the board powers up. GPIO4 and GPIO5 don’t.
The ones that need care:
- D3 (GPIO0): Tied to the FLASH button. If it reads LOW at boot, the ESP8266 enters upload mode instead of running your code. A button here is fine; a module that holds it LOW at power-up is not.
- D4 (GPIO2): The blue LED on the ESP-12 module, active low:
LOWturns it on. It must be HIGH at boot, and it is also the TX line of the second UART. - D8 (GPIO15): Must be LOW at boot, and a resistor on the board already pulls it down. Add an external pull-up and the board won’t boot.
- D0 (GPIO16): No
attachInterrupt, no PWM, and instead ofINPUT_PULLUPit only offersINPUT_PULLDOWN_16. It is the deep sleep wake pin, so it is usually reserved for that. Some NodeMCU boards also put a second LED here. - RX and TX: The USB serial line. Use them and you lose the Serial Monitor and uploads.
Per the datasheet, each pin can source at most 12 mA. Enough for an LED, not for a relay coil or a motor; drive those through a transistor or a ready-made relay module.
I2C and SPI Pins: OLED Example
The ESP8266 has no hardware I2C peripheral; I2C runs in software. That means any two pins will do, but the library default is SDA = D2 (GPIO4), SCL = D1 (GPIO5), and Wire.begin() uses those.
SPI is hardware and fixed: SCK D5, MISO D6, MOSI D7, CS D8.
The most common add-on is a 0.96 inch SSD1306 OLED. On the default pins it is this short:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
Wire.begin(D2, D1); // SDA, SCL
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 20);
display.println("NodeMCU");
display.display();
}
void loop() {}
More on the display in our Arduino OLED SSD1306 guide. For an I2C 16x2 LCD, the I2C LCD code generator writes the sketch once you enter the address and SDA/SCL pins.
A0 and Analog Input
NodeMCU has one analog input: A0. The bare ESP8266 chip can only read 0-1 V; the NodeMCU board puts a voltage divider in front of A0, so the pin reads 0-3.3 V. The result is 10-bit, 0-1023.
void setup() {
Serial.begin(115200);
}
void loop() {
int raw = analogRead(A0); // 0..1023
float volts = raw * 3.3 / 1023.0;
Serial.printf("raw %d, %.2f V\n", raw, volts);
delay(500);
}
A bare ESP-12 module or a different ESP8266 board may not have that divider, in which case the pin must never see more than 1 V. To measure anything higher, size your resistors with the voltage divider calculator.
With a single analog pin, projects that read several sensors either add an I2C ADC such as the ADS1115 or move to a board with plenty of ADC channels like the ESP32 DevKit.
PWM
PWM works on every GPIO except D0 and is generated in software. The default frequency is 1 kHz. Watch the version difference: before arduino-esp8266 3.0, the analogWrite range was 0-1023; since 3.0 it is 0-255, matching Arduino. An old sketch’s analogWrite(D5, 512) used to mean 50%; on a current core it is above 255 and runs at full brightness. Setting the range explicitly avoids the guesswork:
analogWriteRange(1023);
analogWriteFreq(1000);
analogWrite(D5, 512); // 50%
Power Pins: 3V3, Vin and 5V
| Pin | What it does |
|---|---|
| 3V3 | 3.3 V output of the on-board regulator. Power sensors from here |
| Vin | External supply input. Feed 5 V here when USB isn’t connected |
| VU (V3 only) | 5 V straight from USB, for modules that need 5 V |
| GND | Common ground |
| EN / RST | Chip enable and reset |
The ESP8266 datasheet caps the I/O pins at 3.6 V, so officially they are not 5 V tolerant. Don’t connect the signal line of a 5 V sensor such as the HC-SR04 directly; use a level shifter or a two-resistor divider.
Where the “5V pin” is depends on your board. V2 has no dedicated 5 V output; with USB plugged in, Vin sits slightly below the USB voltage. V3 has the VU pin for exactly this.
NodeMCU V2 vs V3

“V3” isn’t an official NodeMCU revision; it is LoLin’s name for its own board. Both are sold under these names anyway:
| V2 (Amica) | V3 (LoLin) | |
|---|---|---|
| USB-serial chip | CP2102 | CH340G |
| Width | Narrow, leaves a free row on each side of a breadboard | Wide, covers the whole breadboard |
| Two pins in the left row | RSV, RSV (unused) | GND, VU |
| GPIO map | Same | Same |
| Arduino board | NodeMCU 1.0 (ESP-12E Module) | NodeMCU 1.0 (ESP-12E Module) |
For code, the two boards are identical and every table here applies to both. There are two practical differences. Drivers: V2 needs the Silicon Labs CP210x driver, V3 the WCH CH340 driver (Windows 11 usually installs the CH340 one by itself). And breadboards: a V3 on a single breadboard leaves no holes to plug wires into, so you end up putting two breadboards side by side.
Deep Sleep: Wiring D0 to RST
The ESP8266 can’t wake itself from deep sleep. Waking works by D0 (GPIO16) pulsing LOW when the timer runs out, and for that pulse to act as a reset you have to wire D0 to the RST pin:
void setup() {
Serial.begin(115200);
Serial.println("Awake, taking a reading");
// ... read the sensor, send it over Wi-Fi ...
ESP.deepSleep(10 * 60 * 1000000ULL); // sleep 10 minutes
}
void loop() {}
Remove that wire while uploading; on some boards it breaks the upload. Since waking is a reset, the code starts from setup() every time. The chip itself draws microamps in deep sleep, but the NodeMCU board as a whole draws far more because of the USB-serial chip and the regulator. For something that should run on batteries for months, look at a bare ESP-12 module or a board with a low-quiescent regulator instead.
Common Problems
| Symptom | Cause and fix |
|---|---|
| No COM port | Charge-only cable or missing driver. Swap the cable; install CP210x for V2, CH340 for V3 |
Timed out waiting for packet header | The board didn’t enter upload mode. Hold FLASH as the upload starts |
| Garbage characters at boot | The ESP8266 prints its boot log at 74880 baud. That’s normal, your output follows |
| Board won’t boot or keeps resetting | Something on D3, D4 or D8 is breaking the boot levels. Disconnect it and retry |
| Relay clicks every time it powers up | Move the relay to D1 or D2 |
digitalWrite(1, ...) doesn’t light the LED | 1 is TX. Use D1 |
Soft WDT reset inside a loop | A long loop is starving the Wi-Fi stack. Add yield() or delay(0) |
| Built-in LED works backwards | The D4 LED is active low, LOW turns it on |
NodeMCU or ESP32?
| Board | When |
|---|---|
| NodeMCU ESP8266 | Wi-Fi projects that read one sensor and send it, switch a relay or run a simple web server. Or when one is already in the drawer |
| ESP32 DevKit | When you need Bluetooth, several analog inputs, touch pins, two cores or more memory |
| ESP32-C3 SuperMini | When you want something as cheap and small as an ESP8266 board, but with Bluetooth and a current chip |
Starting a new project from scratch, the price gap is now tiny and the ESP32 family opens more doors. But if there is a NodeMCU on your desk, it is more than enough for a Wi-Fi sensor node or a smart plug.
FAQ
What GPIO is D1 on NodeMCU? D1 is GPIO5. The other labels don’t match their GPIO numbers either: D2 is GPIO4, D3 GPIO0, D4 GPIO2, D5 GPIO14, D6 GPIO12, D7 GPIO13, D8 GPIO15, and D0 is GPIO16.
Which pins are SDA and SCL on NodeMCU? The defaults are SDA on D2 (GPIO4) and SCL on D1 (GPIO5). Because I2C runs in software on the ESP8266, Wire.begin(sda, scl) can move it to other pins.
Which NodeMCU pins are safe to use? D1, D2, D5, D6 and D7. D3, D4 and D8 decide the boot mode, so nothing that changes their level at power-up should be connected; D0 has no interrupt or PWM.
Are NodeMCU pins 5V tolerant? Officially no. The ESP8266 datasheet allows at most 3.6 V on the pins. Use a level shifter or a voltage divider for 5 V sensors, and feed 5 V power through the Vin pin.
What is the difference between NodeMCU V2 and V3? V2 (Amica) is narrow with a CP2102 USB chip; V3 (LoLin) is wider with a CH340. On V3 two unused pins become GND and VU, a 5 V USB output. The GPIO map and the Arduino settings are the same on both.
