Learn

NodeMCU pinout: D0 to D8 in GPIO numbers, and the pins to avoid

Beginner

Or see every lesson.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
NodeMCU: fadelive0.000 s 0.00x
Click to open it in the editor
An LED on D1 (GPIO 5) breathing on software PWM, 0 to 1023 at 1 kHz.

The NodeMCU is an ESP8266 on a thirty-pin board with a micro-USB socket, and its pinout has two traps: the D numbers on the silkscreen are not GPIO numbers, and six of the holes are the flash chip the program runs from. This page gives the GPIO number behind every hole, what each one can do, the power pins, both onboard LEDs, the pins that decide whether the board boots, and which pin to use for what.

The circuit above is a NodeMCU in Mokxi, breathing an LED on D1 with the ESP8266’s software PWM. Mokxi models the V1.0 "Amica" board, and the table is held to the same model the simulator runs. Where the simulator does less than the chip, the page says so on the row.

Every pin, with its GPIO number

With the USB socket at the bottom, the left header reads A0, RSV, RSV, SD3, SD2, SD1, CMD, SD0, CLK, GND, 3V3, EN, RST, GND, VIN, and the right one reads D0 to D4, 3V3, GND, D5 to D8, RX, TX, GND, 3V3. The core defines D0 to D8, so digitalWrite(D2, HIGH) means the hole you are looking at. digitalWrite(2, HIGH) is GPIO 2, which is D4.

The board people photograph bridging two breadboards is the wider V3 "LoLin", with a full inch between its rows. Its GPIO numbers are the same, but it puts other things on the two RSV holes, so go by its silkscreen there.

NodeMCU V1.0: the left header top to bottom, then the right, USB at the bottom
PinGPIOWhat it can doWatch out for
A0-The one analog input, 0 to about 3.2 V through the board’s divider. Ten bits.Not a GPIO: it cannot be written.
RSV-Reserved. Two holes.Connected to nothing here; leave them alone.
SD310The flash chip’s data line.Never use: the program runs from it. Not connected in Mokxi.
SD29The flash chip’s data line.Never use: the program runs from it. Not connected in Mokxi.
SD18The flash chip’s data line.Never use: the program runs from it. Not connected in Mokxi.
CMD11The flash chip’s command line.Never use: the program runs from it. Not connected in Mokxi.
SD07The flash chip’s data line.Never use: the program runs from it. Not connected in Mokxi.
CLK6The flash chip’s clock.Never use: the program runs from it. Not connected in Mokxi.
GND-Ground. Four holes.-
3V3-The regulator’s 3.3 V output. Three holes.Not a GPIO.
EN-Chip enable, tied to RST.Not a GPIO.
RST-Reset: low restarts the chip; the RST button does that.Not a GPIO.
VIN-The 5 V rail from USB; put 5 V here to run the board without a cable.Not a GPIO.
D016Digital in and out, software PWM. The board’s own LED, lit when LOW.No interrupt, and a pull-down rather than a pull-up.
D15PWM. I2C SCL (default).A safe all-rounder.
D24PWM. I2C SDA (default).A safe all-rounder.
D30PWM. The FLASH button.Strapping pin: low at boot waits for an upload.
D42PWM. The module’s blue LED, lit when LOW. UART1 TX on the chip.Strapping pin: must be high at boot.
D514PWM. SPI SCK (default).-
D612PWM. SPI MISO (default).-
D713PWM. SPI MOSI (default).-
D815PWM. SPI SS (default).Strapping pin: must be low at boot.
RX3UART0 RX: Serial, and the USB-to-serial chip.Leave free, or uploads and the serial monitor break.
TX1UART0 TX: Serial, and the USB-to-serial chip.Leave free, or uploads and the serial monitor break.

The flash pins: SD0 to SD3, CMD and CLK

Six holes on the left header are GPIO 6 to 11, the wires to the flash chip your program is running from. They are on a real NodeMCU’s header, so they are on Mokxi’s too, and driving any of them on a real board stops the program dead. The two RSV holes next to them do nothing useful either.

In Mokxi those eight holes are connected to nothing: they neither drive nor read. A sketch that seemed to work in a simulator because it used SD1 would stop the flash on a desk, and a simulator should not teach that.

Power: VIN, 3V3 and GND

VIN is the 5 V rail from the USB socket, and the place to put 5 V when there is no cable. 3V3 is the regulator’s output, on three holes, for the ESP8266 and the small sensors around it. The four GND holes are one ground.

Every pin is 3.3 V and none is 5 V tolerant. Espressif’s datasheet gives a pin a maximum drive of 12 mA, so an LED wants a larger resistor than on an Uno, and anything bigger wants a transistor.

Boot pins and both LEDs

The ESP8266 reads three pins as it comes out of reset. GPIO 0 (D3) and GPIO 2 (D4) must be high and GPIO 15 (D8) low for it to run your program, and GPIO 0 low means "wait for an upload", which is what the FLASH button does. A module that pulls D8 high or D3 or D4 low will stop the board starting. Mokxi does not model this and starts whatever is wired there.

Both LEDs are wired from 3.3 V to their pin, so both light when the pin is LOW. The ESP-12 module’s blue LED is on D4 (GPIO 2), which is LED_BUILTIN; the board’s own is on D0 (GPIO 16). digitalWrite(LED_BUILTIN, LOW) turns the module’s LED on, and that surprises nearly everyone once.

A0, D0, PWM, I2C and SPI

A0 is the only analog input. The chip’s own pin reads 0 to 1.0 V, and the NodeMCU puts a 220k and 100k divider in front of it, so the hole reads 0 to about 3.2 V. Ten bits, 0 to 1023, and Mokxi models the divider. D0 is GPIO 16, the RTC’s pin: a pull-down instead of a pull-up, no interrupt, and on a real board the pin you wire to RST for deep-sleep wake, which Mokxi does not model.

There is no PWM hardware on the ESP8266, so analogWrite is software and the range is 0 to 1023, which is why the fade above counts to 1023. Any of D0 to D8 can do it. I2C defaults to D2 for SDA and D1 for SCL; SPI to D5, D6, D7 and D8 for SCK, MISO, MOSI and SS.

Interrupts and a second serial port

attachInterrupt works on D1 to D8, which are GPIO 0 to 15, and not on D0, whose GPIO 16 has no interrupt on this chip. In Mokxi attachInterrupt(D0, ...) does nothing, as on the board, so a sketch that counts pulses on D0 counts none in both places.

The ESP8266 has one full serial port, UART0 on TX and RX, which the USB chip uses. UART1 can only transmit, and only on GPIO 2, which is D4 and the blue LED. Mokxi does not model UART1. For a second port that both sends and receives, SoftwareSerial works on any two pins but D0, as in SoftwareSerial gps(D5, D6);, here and on a real board.

Open this circuit in the editor. NodeMCU: fade, wired as it runs at the top of this page. Change a part or a value and run it again.

Open the circuit

Questions

Which NodeMCU pins are safe to use?

D1, D2, D5, D6 and D7 are safe for almost anything. D3, D4 and D8 are fine once you know their boot rules, and D0 lacks an interrupt and a pull-up. Never use SD0 to SD3, CMD or CLK.

Which pin should I use for a button on a NodeMCU?

D1, D2, D5, D6 or D7, with `INPUT_PULLUP` and the button to ground. The FLASH button on D3 also works as an input once the sketch is running.

Does the NodeMCU have a 5V pin?

VIN is the 5 V rail from USB. On most of the wider V3 boards one of the RSV holes carries USB 5 V as well. The ESP8266’s own pins are 3.3 V only.

What are the NodeMCU I2C pins?

SDA is D2 (GPIO 4) and SCL is D1 (GPIO 5). `Wire.begin()` uses them when you name no pins.

Which NodeMCU pin should I use for an interrupt?

D1, D2, D5, D6 or D7. D0 has no interrupt at all, and D3, D4 and D8 are the boot pins.

Why does digitalWrite(2) light the wrong pin?

Because 2 is a GPIO number, and GPIO 2 is D4. Write `D2` to mean the hole marked D2, which is GPIO 4.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.