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
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 Pin | Connects To |
|---|---|
| D4 (GPIO2) | LED anode (long leg) |
| GND | 220 Ohm resistor -> LED cathode (short leg) |
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.
- Open Arduino IDE
- Go to File -> Preferences
- Find Additional Boards Manager URLs and click the button on the right
- Paste this URL and click OK:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Go to Tools -> Board: -> Boards Manager…
- Search for esp8266
- Find “ESP8266 by ESP8266 Community” and click Install
- Wait until it shows INSTALLED, then click Close
- 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.
LED Blink Code
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
| Problem | Cause | Fix |
|---|---|---|
| Upload failed with error | Wrong COM port selected | Check Device Manager to find the correct port |
| Board unresponsive | USB cable can’t deliver enough current | Use a quality USB cable or connect 9V adapter to Vin |
| LED never lights | LED polarity reversed | Swap LED anode and cathode |
| espcomm_open failed | Wrong board type selected | Verify 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
จ้างทำโปรเจคเลย