Setting Up First Project (Blink LED): NodeMCU Beginners’ Guide
In this lesson, we will walk you through setting up your NodeMCU board from scratch, installing the required software, and running a simple LED blink test to confirm everything works properly.
Install Drivers
Depending on your NodeMCU board model, you may need to install drivers for your computer to recognize the board.
- CH340/CH341 Drivers: If your board uses the CH340 or CH341 USB-to-Serial chip, download and install drivers from the Gogo:Tronics or WCH websites.
- CP2102 Drivers: For boards with CP2102 chips, download drivers from the Silicon Labs website.
After installation, plug in your NodeMCU via the micro-USB cable and check if it appears as a COM port (Windows) or a /dev/tty device (Mac/Linux).
Setting Up Arduino IDE with NodeMCU
You can program NodeMCU using the Arduino IDE. You can download it from the Arduino official website.
To program the NodeMCU board, add the ESP8266 board package to the Arduino IDE.
- Open Arduino IDE.
- Go to File > Preferences.
- In the Additional Boards Manager URLs field, add:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Click OK.
- Go to Tools > Board > Boards Manager.
- Search for ESP8266 and click Install.
- Once installed, select NodeMCU 1.0 (ESP-12 Module) from the Tools > Board menu.
Testing Basic Code (Blink LED Example)
Let’s upload a simple program to blink the built-in LED (usually connected to GPIO2).
Code Example:
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED pin as an output
}
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (LOW is the voltage level)
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off
delay(1000); // Wait for a second
}
Steps to Upload Code:
- Connect your NodeMCU to your computer via USB cable.
- Select the correct COM Port from Tools > Port.
- Click the Upload button.
- Wait for the message “Done uploading.”
If successful, the built-in LED should blink every second.
Troubleshooting Common Errors
- Port Not Detected: Install the correct drivers and ensure the USB cable works properly.
- Upload Errors: Check if the correct board and port are selected in the Tools menu.
- Compilation Errors: Reinstall the ESP8266 board package if errors persist.
- Random Resets: Provide a stable power supply (avoid using poor-quality USB cables).
In the next lesson, we will explore how to use NodeMCU’s GPIO pins for digital input and output. Stay tuned!