กลับหน้าหลัก
views
Getting Started with ESP8266 NodeMCU and Arduino IDE
Last updated on

Getting Started with ESP8266 NodeMCU and Arduino IDE


Getting Started with ESP8266 NodeMCU and Arduino IDE

ESP8266 NodeMCU is a popular choice for IoT beginners because it’s inexpensive, has built-in Wi-Fi, and works with the Arduino IDE out of the box. No new toolchain required. This guide walks you through IDE setup, basic LED wiring, and uploading your first blink sketch.

What You Need

Before starting, gather these components:

  • ESP8266 NodeMCU board (Wemos D1 R2 & mini or ESP-WROOM-02)
  • MB-102 breadboard, 830 tie points
  • Micro USB Type-B to USB 2.0 Type-A cable, 1 meter
  • 5mm red LED, 1 piece
  • 220 Ohm 1/4W resistor, 1 piece
  • Male-to-male and male-to-female jumper wires, 20cm, about 5-10 pieces
Photo showing all components laid out on a table: ESP8266 NodeMCU board, MB-102 breadboard, Micro USB cable, 5mm LED, 220 Ohm resistor, and jumper wires

Wiring the LED Circuit

The first circuit is a single LED to see clear output from the code. We use GPIO2 (D4 on Wemos D1) as the output pin.

ESP8266 PinConnects To
D4 (GPIO2)LED anode (long leg)
GND220 Ohm resistor -> LED cathode (short leg)
Breadboard diagram showing wire connections from D4 to the LED anode and GND through the 220 Ohm resistor to the LED cathode, clearly labeled

Important note: LED polarity matters. If you connect it backwards, the LED won’t light up. The anode (long leg) is the positive side. The resistor has no polarity, so it doesn’t matter which way you orient it.

Installing Arduino Core for ESP8266

The default Arduino IDE installation doesn’t recognize ESP boards. You need to add the board definition first.

  1. Open Arduino IDE
  2. Go to File -> Preferences
  3. Find Additional Boards Manager URLs and click the button on the right
  4. Paste this URL and click OK:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Arduino IDE Preferences window showing the Additional Boards Manager URLs field with the ESP8266 board package URL entered
  1. Go to Tools -> Board: -> Boards Manager…
  2. Search for esp8266
  3. Find “ESP8266 by ESP8266 Community” and click Install
  4. Wait until it shows INSTALLED, then click Close
  5. Close and reopen Arduino IDE so the board definition loads properly

Selecting Board and Port

After installation, configure these settings:

  • Tools -> Board: Select LOLIN(WEMOS) D1 R2 & mini (if using a different NodeMCU variant, select the matching model)
  • Tools -> Port: Select the COM port where the board is connected

Not sure which COM port is correct? Open Device Manager on Windows, look under Ports (COM & LPT), then unplug the USB cable. The port that disappears is the one you need.

Now for the basic blink sketch that toggles the LED on and off. This code works with ESP boards using the Arduino Core.

// Blink LED using GPIO2 (D4 on Wemos D1)
const int LED_PIN = 2;  // D4 on Wemos D1 R2 & mini

void setup() {
  // Set LED_PIN as output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // Turn LED on
  delay(1000);                  // Wait 1 second
  digitalWrite(LED_PIN, LOW);   // Turn LED off
  delay(1000);                  // Wait 1 second
}

Press Ctrl+U to upload to the board. If this is a new unsaved sketch, Arduino will ask you to save it first—just click OK to proceed.

Wait a moment. When upload finishes, you should see Done uploading at the bottom of the Arduino IDE window. If the LED blinks on and off every 1 second, everything is configured correctly.

[image: ESP8266 Wemos D1 board with LED connected and blinking, along with Arduino IDE window showing the Done uploading message]

Key Things to Know

Why a resistor is needed: LED draws current and burns out if current is too high. The 220 Ohm resistor limits current to a safe level. This value works for standard 5mm LEDs.

GPIO on ESP8266: ESP8266 GPIO pins operate at 3.3V, not 5V like Arduino UNO. If you connect 5V devices, use a level shifter circuit.

Serial Monitor: Press Ctrl+Shift+M to open Serial Monitor and view debug messages from the board. Set baud rate to 115200.

// Add Serial output to the code to verify board operation
void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("ESP8266 LED Blink Ready");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED ON");
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  Serial.println("LED OFF");
  delay(1000);
}

Common Errors and Fixes

ProblemCauseFix
Upload failed with errorWrong COM port selectedCheck Device Manager to find the correct port
Board unresponsiveUSB cable can’t deliver enough currentUse a quality USB cable or connect 9V adapter to Vin
LED never lightsLED polarity reversedSwap LED anode and cathode
espcomm_open failedWrong board type selectedVerify LOLIN(WEMOS) D1 R2 & mini is selected

Next Steps

If the LED blink works, experiment by changing delay values to see faster or slower blinking. Then expand to multiple LEDs in a sequential circuit, or try using different GPIO pins like D7 (GPIO13) or D8 (GPIO15).

When you’re ready, try writing code to control the LED over Wi-Fi or read sensor values and send data to a server—that’s the real foundation of IoT projects.

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

Project estimate

Want something like this? Open the estimate page.

The long form is now on a separate estimate page, so this article stays clean.

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...