Introduction: NodeMCU Basic Project-Blink a LED

About: Osoyoo brand products are mainly focused on STEM education.User experience and customer feeling are always our first priority. Our goal is to create the best designed product to help students and hobbyist to e…

OSOYOO NodeMCU IOT Starter kit

In this lesson,we will introduce how to blink the on-board LED and how to blink a external LED.

Hardware Preparation:
NodeMCU x 1

LED x 1

200 ohm resistor x 1

Micro USB cable x 1

PC x 1

Software Arduino IDE(version 1.6.4+)

Step 1: Blink the On-board LED

In this part,we will learn how to use the Arduino IDE to blink the on-board LED,the blue led in the board was used to signal the execution of a particular procedure.Because the GPIO16 (DO) limitation to use the analogWrite() and looking to see my LED doing something else…

First,connect the NodeMCU to the PC,put below code to the Arduino IDE:

#define LED D0 // Led in NodeMCU at pin GPIO16 (D0).
void setup() { pinMode(LED, OUTPUT); // LED pin as output. } void loop() { digitalWrite(LED, HIGH);// turn the LED off.(Note that LOW is the voltage level but actually //the LED is on; this is because it is acive low on the ESP8266. delay(1000); // wait for 1 second. digitalWrite(LED, LOW); // turn the LED on. delay(1000); // wait for 1 second. }

Then config the board settings(choose the corresponding board and port for your NodeMCU) and upload the sketch to the board.

After upload done,you will see the on-board LED blink every second.

Step 2: Blink an External LED

Connect one end of the resistor to the digital pin correspondent to the LED_BUILTIN constant.

Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor.

Connect the short leg of the LED (the negative leg, called the cathode) to the GND. In the diagram we show a NodeMCU that has D1 as the LED_BUILTIN value.

The value of the resistor in series with the LED may be of a different value than 200 ohm; the LED will lit up also with values up to 1K ohm.

Upload below code to your NodeMCU:

#define LED D1 // Led in NodeMCU at pin GPIO16 (D0).
void setup() { pinMode(LED, OUTPUT); // set the digital pin as output. } void loop() { digitalWrite(LED, HIGH);// turn the LED off.(Note that LOW is the voltage level but actually //the LED is on; this is because it is acive low on the ESP8266. delay(1000); // wait for 1 second. digitalWrite(LED, LOW); // turn the LED on. delay(1000); // wait for 1 second. }

After the upload done,you will see the led blink .