If you've wired an LED to the pin labelled D1 on a NodeMCU, written pinMode(1, OUTPUT), and then watched nothing happen, you've met this board's biggest quirk. Almost every NodeMCU user runs into it once.
The reason: the numbers printed on your NodeMCU board (D0, D1, D2...) are not the actual GPIO numbers the chip uses internally. They're two completely different numbering systems living on the same 30 pins, and depending on which library or which line of code you're looking at, you might be dealing with either one. Once you see why this happened and memorize the mapping, it stops being confusing — but until then, it's the single most common source of "why doesn't my code work" bugs on this board.
Why Two Numbering Systems Exist in the First Place
The ESP8266 is a bare chip. Espressif designed it with GPIO pins numbered GPIO0 through GPIO16 (with a few gaps — more on that later). That's the chip's native numbering, and it's what the actual silicon datasheet refers to.
NodeMCU, the dev board, wraps that chip in a breadboard-friendly package and labels the pins D0 through D8. Those labels come from the pin numbering of the original NodeMCU Lua firmware and follow the board's physical pin order, not the chip's GPIO numbers. D0 is GPIO16. D1 is GPIO5. D2 is GPIO4. There's no pattern you can guess your way through.
Then the Arduino core for ESP8266 added a translation layer: constants like D0, D1, D2 are #defined to map automatically to the correct GPIO number. So pinMode(D1, OUTPUT) correctly toggles GPIO5. But pinMode(5, OUTPUT) also compiles fine — except now you're addressing GPIO5 directly, which happens to also be D1, so in that one case it accidentally works. Try pinMode(1, OUTPUT) though, thinking you're targeting D1, and you've actually just grabbed GPIO1 — which is your board's TX pin, shared with the USB serial monitor. That's the trap.
The fix: always use the D constants (D0, D1, D2...) in your code, never the bare number. It removes the ambiguity entirely.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
30 of 30 pins match
Hover or tap any pin on the board
RIGHT header · pin 2
D1
Safe to use
Default I2C SCL. A safe general-purpose pin.
Nothing else on the board depends on this pin. A good first choice for sensors, LEDs and buttons.
Can be used as
- I2C
- PWM out
- External interrupt
Signals on this pad
- GPIO5
- D1
- SCL
Full Pinout Table
Here's the complete mapping between the board labels and the chip's GPIO numbers.
| Silkscreen Label | GPIO Number | Notes |
|---|---|---|
| D0 | GPIO16 | No interrupts, no I2C, no INPUT_PULLUP (it has a pull-down option instead). Wakes the chip from deep sleep. Goes HIGH briefly at boot. |
| D1 | GPIO5 | Default I2C SCL. General purpose, safe to use. |
| D2 | GPIO4 | Default I2C SDA. General purpose, safe to use. |
| D3 | GPIO0 | Boot mode pin. Must be HIGH at boot. Has an onboard pull-up. |
| D4 | GPIO2 | Boot mode pin. Must be HIGH at boot. Also drives the onboard blue LED (active LOW) and is the TX pin of Serial1. |
| D5 | GPIO14 | Hardware SPI (SCLK). General purpose otherwise. |
| D6 | GPIO12 | Hardware SPI (MISO). General purpose otherwise. |
| D7 | GPIO13 | Hardware SPI (MOSI). Becomes Serial RX after Serial.swap(). General purpose otherwise. |
| D8 | GPIO15 | Boot mode pin. Must be LOW at boot. Hardware SPI (CS). Becomes Serial TX after Serial.swap(). |
| A0 | ADC0 | Single analog input, 0–3.3V on most NodeMCU boards via onboard divider. |
| RX | GPIO3 | Hardware UART RX. Shared with USB serial monitor. |
| TX | GPIO1 | Hardware UART TX. Shared with USB serial monitor. |
| SD3, SD2, SD1, CMD, SD0, CLK | GPIO10, 9, 8, 11, 7, 6 | Wired to the SPI flash chip. Broken out on the NodeMCU's header, but using them usually crashes the board. |
That last row explains why the NodeMCU gives you only 9 general-purpose GPIOs (D0–D8) out of the ESP8266's 17: six are permanently busy talking to the flash chip, and RX/TX belong to USB serial. The six flash pins do appear on the left-hand header (SD3, SD2, SD1, CMD, SD0, CLK), which tempts people to use them. Don't. GPIO9 and GPIO10 can sometimes be freed by flashing in DIO mode, but on most boards driving them freezes or resets the chip.
Which NodeMCU Board Do You Have?
Three different boards are sold as "NodeMCU". The D-pin labels and GPIO mapping are the same on all of them; the differences are the USB chip, the width and two spare pins:
| Board | USB chip | Width | What's different |
|---|---|---|---|
| NodeMCU v1.0 (often sold as Amica) | CP2102 | Narrow: leaves a free row of holes on each side of a breadboard | Two RSV pins that aren't connected |
| LoLin NodeMCU V3 | CH340G | Wide: leaves no free holes on one side of a standard breadboard | The RSV pins become VU (USB 5V) and GND |
| NodeMCU v0.9 | CH340G | Very wide, older ESP-12 module | Rarely sold now |
If your computer doesn't see the board, the USB chip decides which driver you need. The ESP8266 Arduino IDE setup guide covers the drivers and board settings.
What's Actually on the Board
A NodeMCU v1.0 is a carrier for the ESP-12E module: the ESP8266EX chip, its SPI flash and a PCB antenna under one shield. The carrier adds a 3.3 V regulator fed from USB or VIN, a USB-to-UART bridge for uploads and the Serial Monitor, a blue LED on D4 (GPIO2), and two buttons: RST resets the chip and FLASH holds GPIO0 LOW so the chip starts in upload mode.
Power Pins
| Pin | Description |
|---|---|
| VIN | 5V input (via USB or external supply) |
| 3V3 | Regulated 3.3V output/rail — this is the chip's native operating voltage |
| GND | Ground (multiple pins, all connected) |
| RST | Pull LOW to reset the chip (the RST button does the same) |
| EN | Chip enable. Held HIGH on the board; pulling it LOW switches the chip off |
| VU (LoLin V3 only) | 5V straight from the USB connector |
The critical thing to remember here, especially if you're coming from Arduino Uno or Mega like most people are: the ESP8266 is a 3.3V device, and its datasheet doesn't rate any GPIO for 5V. Inputs are specified up to 3.6V. On an Uno you can get away with a 5V sensor output going into a digital pin most of the time. Do that here and you risk quietly cooking the pin, or the whole chip, over time. If you're feeding it a signal from a 5V sensor (plenty of cheap IR sensors and ultrasonic modules are 5V), put a voltage divider or a proper logic level shifter in between. Don't skip this step because "it worked once on the breadboard."
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
Digital I/O — Which Pins You Can Actually Use Freely
Out of the 9 broken-out GPIOs, only five are what I'd call genuinely "use it for anything" pins: D1, D2, D5, D6, D7. The rest all come with an asterisk.
pinMode(D1, OUTPUT);
digitalWrite(D1, HIGH);Each GPIO can source or sink about 12 mA (Espressif's datasheet figure), roughly half of what an Uno pin is rated for. Drive LEDs through a resistor, and switch relay coils, motors and buzzers through a transistor or a driver module.
D0 (GPIO16) is the odd one out. It sits in the chip's real-time clock block rather than with the other GPIOs, so it can't trigger interrupts, can't act as an I2C line (it has no open-drain mode) and has no internal pull-up, only INPUT_PULLDOWN_16. It still handles digitalWrite(), digitalRead() and, with current versions of the Arduino core, PWM. Its one special talent is waking the chip from deep sleep, which makes it genuinely useful for battery-powered projects, just not as a general-purpose pin.
D3, D4, and D8 are the ones that will bite you if you don't know about them upfront. They get their own section below.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
Usable, but nothing may pull them the wrong way at power-up
No interrupts, I2C or INPUT_PULLUP
Never use
Interrupts Need IRAM_ATTR
Any pin except D0 can trigger an interrupt with attachInterrupt(). On the ESP8266 the handler must be marked IRAM_ATTR so it lives in RAM rather than flash. Leave it off and the board resets with an ISR not in IRAM! error as soon as the interrupt is attached.
volatile uint32_t pulses = 0;
void IRAM_ATTR onPulse() {
pulses++;
}
void setup() {
pinMode(D5, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(D5), onPulse, FALLING);
}Boot Mode Pins — Read This Before You Wire Anything to D3, D4, or D8
When the ESP8266 powers on or resets, it briefly checks the logic level on three specific pins to decide how to boot — whether to run your uploaded program normally, or drop into flashing mode. Those three pins are:
- D3 (GPIO0) — must read HIGH at boot to run normally. Pull it LOW at boot and the chip enters flash/programming mode instead of running your code.
- D4 (GPIO2) — must also read HIGH at boot.
- D8 (GPIO15) — must read LOW at boot. This one's the opposite of the other two, and it's the one people forget most often.
Here's where it actually causes problems in real projects: say you wire a relay module or an LED driver to D8, and that module's default state happens to pull the pin HIGH when the board is unpowered (a lot of relay boards do this through their pull-up resistors). Power on the NodeMCU, and it fails to boot at all — no blink, no serial output, nothing. It's not a bricked board, it's just stuck refusing to start because D8 wasn't LOW at the moment of boot. Swap that connection to D1, D2, D5, D6, or D7 instead, and the exact same relay module works perfectly.
Same logic in reverse for D3 and D4 — if something is actively pulling either of those LOW during boot (a button wired without a proper pull-up resistor is the classic culprit), the board boots into flash mode and just sits there looking dead.
Practical rule: treat D3, D4, and D8 as pins you use last, only for things that don't interfere with their power-on state — buttons with proper pull-ups, or outputs that default to the right level. For anything else, reach for D1, D2, D5, D6, or D7 first.
One more quirk worth knowing: D4 doubles as the onboard blue LED, and it's wired active-LOW, meaning digitalWrite(D4, LOW) turns the LED on. If you're using D4 for something else and you see the onboard LED flickering along with your signal, that's expected — it's the same physical pin.
A few pins also change state for a moment at power-up, even when the boot levels are right: D0 and RX go HIGH, D4's LED flickers, and TX prints the ESP8266's boot log at 74880 baud (the burst of garbage you see in the Serial Monitor right after a reset). A relay on one of those pins can click once at every boot, so relays and motor drivers belong on D1, D2, D5, D6 or D7.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
PWM Pins
Every usable GPIO on the ESP8266 can do PWM, D0 included with current versions of the Arduino core. That's more flexible than the Uno in terms of pin coverage, but there's a catch: it's software PWM, generated by the core toggling the pin rapidly rather than dedicated PWM hardware like the ATmega chips have. The default frequency is around 1 kHz, and if you're driving multiple PWM pins at once while also doing WiFi work, you can occasionally see slight jitter.
analogWriteRange(1023); // optional: set the range explicitly
analogWriteFreq(1000); // optional: PWM frequency in Hz
analogWrite(D5, 512); // 50% duty with a 0–1023 rangeWatch the range. Since version 3.0 of the ESP8266 Arduino core, analogWrite() defaults to 0–255, the same as an Uno. Core 2.x defaulted to 0–1023, and many older ESP8266 tutorials and sketches assume that, so a value of 512 that meant "half brightness" there now means "fully on". Calling analogWriteRange() in setup() makes a sketch behave the same on either version.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
Analog Input (A0)
You get exactly one analog input pin, and that's a real step down if you're used to the Mega's sixteen. The raw ESP8266 chip's ADC only accepts 0–1.0V, which would be useless for most sensors — so NodeMCU boards add an onboard resistor divider that extends the usable range to roughly 0–3.3V. That's why A0 behaves fine with a 3.3V-referenced sensor but you should still never feed it a raw 5V signal.
int raw = analogRead(A0);
float voltage = raw * (3.3 / 1023.0);The NodeMCU's divider (220kΩ and 100kΩ) puts full scale at about 3.2V rather than exactly 3.3V, so treat the result as approximate and calibrate against a multimeter if accuracy matters. Also avoid calling analogRead() in a tight loop with no delay: on the ESP8266, very frequent ADC reads can disturb Wi-Fi.
Because there's only one analog pin, any project reading multiple analog sensors (soil moisture and an LDR at the same time, say) needs either an analog multiplexer chip or a switch to a board with more ADC channels. This is one of the more common walls people hit moving from Uno to NodeMCU — plan for it before you start wiring.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
I2C — D1 and D2 by Convention, Not by Hardware
The ESP8266 doesn't have a dedicated I2C hardware peripheral. What you're using is a bit-banged (software-driven) I2C implementation in the Arduino core. By default, Wire.begin() uses D1 as SCL and D2 as SDA, but unlike a chip with genuine hardware I2C, you can actually reassign these to almost any other usable GPIO:
#include <Wire.h>
Wire.begin(D2, D1); // SDA, SCL — note the order
Wire.begin(D6, D5); // or remap to any other free pinsNotice the argument order is SDA first, then SCL — reversed from what you'd expect if you're used to seeing SCL listed first on a datasheet. Getting this backwards is a quiet, annoying bug: the bus just doesn't respond, and there's no error message telling you why.
As always with I2C, you need pull-up resistors on both lines (4.7kΩ is the standard). Most breakout boards — OLEDs, BME280s, RTC modules — already include them, so you usually don't need to add your own.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
SPI — Hardware, on D5 Through D8
Unlike I2C, SPI on the ESP8266 is real hardware, and it lives on a fixed set of pins:
| Pin | Function |
|---|---|
| D5 (GPIO14) | SCLK (Clock) |
| D6 (GPIO12) | MISO (Master In, Slave Out) |
| D7 (GPIO13) | MOSI (Master Out, Slave In) |
| D8 (GPIO15) | CS / SS (Chip Select) |
#include <SPI.h>
SPI.begin();This is exactly why D8 is both your SPI chip-select pin and one of the boot-mode pins mentioned earlier — if you're driving an SD card or a display over hardware SPI, keep in mind that whatever's connected to D8 needs to allow the pin to sit LOW at power-on, or your board simply won't start.
Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
UART (Serial)
The ESP8266 has one full hardware UART, Serial, on RX (GPIO3) and TX (GPIO1). These are the same pins the USB-to-serial chip uses for uploading code and for the Serial Monitor. There is also a second, transmit-only UART, Serial1, with its TX on D4 (GPIO2). Its receive pin is taken by the flash chip, so it can't receive anything.
That gives you two useful tricks:
- Debug output on Serial1. Connect D4 to the RX of a USB-serial adapter and print logs with
Serial1.println(), leavingSerialfree for another device. Serial.swap(). MovesSerialfrom GPIO1/GPIO3 to D8 (GPIO15, TX) and D7 (GPIO13, RX), so a GPS module or another microcontroller can use the hardware UART without fighting the USB chip. CallSerial.swap()again to move it back. D8 is a boot pin, so whatever you connect must let it sit LOW at power-up.
If you need two full serial devices plus USB debugging, SoftwareSerial (bundled with the ESP8266 core) adds more ports on spare pins. It's less reliable at higher baud rates and Wi-Fi activity can disturb its timing, so keep it at 9600 or 38400 baud where you can.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(D6, D7); // RX, TX
mySerial.begin(9600);Highlighted on the SolderHub Simulator NodeMCU v1.0. Explore every pin on the NodeMCU v1.0 board page.
Common Mistakes and How to Avoid Them
Wiring something to D8 without checking its default state. This is, by a wide margin, the number one cause of "my NodeMCU won't even turn on" posts. If the board doesn't boot, disconnect whatever's on D8 first before assuming the hardware is dead.
Assuming 5V tolerance because you're used to Arduino. The ESP8266 is not the Uno. Every GPIO expects 3.3V logic. A 5V signal on a data pin, even briefly, is bad news — always level-shift.
Using pinMode(5, ...) instead of pinMode(D1, ...). They happen to point at the same physical pin, which makes this bug sneaky — until you try the same trick with a pin number that doesn't line up, and suddenly nothing works and you don't know why.
Expecting full hardware UARTs like on the Mega. There's one full UART plus a transmit-only Serial1. Try Serial.swap() or logging on Serial1 before reaching for SoftwareSerial.
Forgetting D0 can't do interrupts or I2C. It's easy to grab D0 out of habit for a general-purpose task, since it's first in the list, and then wonder why attachInterrupt() never fires.
Copying PWM values from an older ESP8266 sketch. Core 3.x defaults to a 0–255 range, core 2.x to 0–1023. Set analogWriteRange() explicitly and the sketch works on both.
NodeMCU ESP8266 vs Arduino Uno vs Mega — At a Glance
| Feature | Uno | Mega 2560 | NodeMCU ESP8266 |
|---|---|---|---|
| Logic Level | 5V | 5V | 3.3V (not 5V tolerant) |
| Usable Digital I/O | 14 | 54 | 9 |
| Analog Inputs | 6 | 16 | 1 |
| Hardware UARTs | 1 | 4 | 1, plus TX-only Serial1 |
| PWM Type | Hardware | Hardware | Software |
| Built-in WiFi | No | No | Yes |
| Boot-sensitive pins | None | None | 3 (D3, D4, D8) |
The trade-off is obvious once you see it laid out: you're giving up a lot of pins and losing 5V tolerance, but you're gaining WiFi built directly into the chip, which is the entire reason this board exists. For anything that needs to talk to the internet, send data to Home Assistant, or run without a wired connection, those nine pins go a lot further than they look like they should.
Keep the mapping table handy and use the D constants in code, and the D-pin vs GPIO confusion stops being a recurring bug. If you outgrow the nine pins or the single ADC, the ESP32 pinout guide covers the step up.
Test your pin plan before you solder. The SolderHub Simulator has the same NodeMCU ESP8266 you see in these figures, so you can check boot pins and wiring first.
Quick Answers to Common NodeMCU Pin Questions
Why does D1 in my code not match GPIO1 on the datasheet? Because they're two different numbering systems for the same physical pins. D1 is GPIO5, not GPIO1 — the D-pin labels printed on the board don't follow the chip's own GPIO numbers in order, so they have to be looked up rather than guessed.
Can I use any GPIO for anything? No — D3, D4, D8, and D0 all carry boot-time or hardware restrictions. Stick to D1, D2, D5, D6, and D7 for general-purpose sensors, buttons, and outputs with no strings attached.
Is the onboard LED active-high or active-low? Active-low on most boards — LOW turns it on, HIGH turns it off, the opposite of what most people expect from a first LED-blink sketch. The blue LED on the ESP-12 module is on D4 (GPIO2), and that's what LED_BUILTIN points to. Many NodeMCU v1.0 boards add a second, red LED near the USB socket on D0 (GPIO16), also active-low.
Why is the Serial Monitor full of garbage right after a reset? That's the ESP8266's boot log, printed at 74880 baud. Set the Serial Monitor to 74880 to read it, or ignore it; your own output starts once Serial.begin() runs.
Does the NodeMCU have more than one analog pin? No — A0 is the only ADC input. If a project needs to read more than one analog signal, that means an external ADC or a multiplexer.
Why won't my board wake up from deep sleep? D0 needs to be wired directly to RST for the chip to wake itself back up. Without that one connection, deep sleep mode puts the board to sleep permanently.
Where to Go From Here
Once the D-pin-to-GPIO mapping and the D3/D4/D8 boot restrictions stop causing surprises, wiring D0 to RST for deep sleep is the next thing worth trying on any battery-powered project — it's the one physical connection that unlocks the board's biggest power-saving feature. From there, the same pin logic and boot-mode rules carry over directly to a Wemos D1 Mini, so moving between the two boards for space or pin-count reasons doesn't mean relearning anything. The Wemos D1 Mini pinout guide maps the same pins on the smaller board, and once a sketch works, OTA updates let you reflash it without a USB cable.




