Nodemcu pinout

nodemcu

In ESP8266 firmware on Arduino IDE pin numbers are defined as follows:

NodeMCU Function Pin No on Arduino IDE Alias Name
D0 GPIO16 16 D0
D1 GPIO5 5 D1
D2 GPIO4 4 D2
D3 GPIO0 0 D3
D4 GPIO2 2 D4
D5 GPIO14 14 D5
D6 GPIO12 12 D6
D7 GPIO13 13 D7
D8 GPIO15 15 D8
A0 ADC0 A0 analog_ip
Tx GPIO1 1 D9
Rx GPIO3 3 D10

Pin Functions

Pin numbers in the Arduino IDE correspond directly to the ESP8266 GPIO pin numbers. pinMode, digitalRead, and digitalWrite functions work as usual, so to read GPIO2, call digitalRead(2) or by using its alias name digitalRead(D10).

At startup, pins are configured as INPUT. Digital pins 0-15 can be INPUT, OUTPUT, or INPUT_PULLUP.
Pin 16 can be INPUT, OUTPUT or INPUT_PULLDOWN_16 and is connected to the build-in LED. It can be addressed with digitalRead(D0), digitalRead(16) or digitalRead(LED_BUILDIN).

Pins may also serve other functions, such as Serial, I2C or SPI. These functions are normally activated using specific corresponding library. The diagram above shows the pin mapping for the popular ESP8266 NodeMCU module.
Pin interrupts are supported through attachInterrupt functions. Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt types are supported: CHANGE, RISING and FALLING.

Reserved Pins

GPIO pins 6-11 are not shown on this diagram because they are used to connect flash memory chip on most modules. Trying to use these pins as IOs will likely cause the program to crash.

Note that some boards and modules (ESP-12ED, NodeMCU 1.0) also break out pins 9 and 11. These may be used as IO if flash chip works in DIO mode (as opposed to QIO, which is the default one).

Power Pins

Vin is the NodeMCU’s voltage input that is connected to its internal voltage regulator allowing an input voltage range of 4.75V to 10V. It will be regulated to 3.3V. Alternatively an external voltage source of 3.3V can be directly connected to the NodeMcu’s 3V3 pins. The 3V3 pin can be also a voltage source to other components such as LEDs. GND is the common ground of the board.

Analog Input

ESP8266 has a single ADC channel available to users. It may be used either to read voltage at ADC pin, or to read module supply voltage (VCC).

To read external voltage applied to ADC pin, use analogRead(A0). Input voltage range is 0 — 1.0V.

To read VCC voltage, use ESP.getVcc() while the ADC pin must be kept unconnected. Additionally, the following line has to be added to the sketch:

This line has to appear outside of any functions, for instance right after the #include lines of your sketch.

Analog Output

analogWrite(pin,value) enables software PWM on the given pin. PWM may be used on pins 0 to 16. Call analogWrite(pin,0) to disable PWM on the pin. value may be in range from 0 to PWMRANGE, which is equal to 1023 by default. A value of 0, 512 and 1023 sets the PWM duty cycle to 0%, 50% and 100% respectively. Optionally, the PWM range may be changed by calling analogWriteRange(new_range).

PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency. The unit representation is in [Hz]. Example:


Источник: iotblog.jfdesignnet.com