Blink an LED with NodeMCU ESP8266
Overview
In this project, we will learn how to blink an LED using the NodeMCU ESP8266 microcontroller. This simple project is a great way to get started with the NodeMCU and familiarize yourself with the Arduino IDE setup for this board.
What We Will Learn in This Section
- Setting up the Arduino IDE for NodeMCU ESP8266.
- Writing and uploading code to blink an LED.
- Understanding the basic GPIO functions of the NodeMCU.
Why Is This Lesson Important to You?
This lesson provides a foundational understanding of how to work with the NodeMCU ESP8266 and the Arduino IDE. Blinking an LED is a basic yet crucial step in learning microcontroller programming and understanding GPIO operations.
Components List
- NodeMCU ESP8266
- LED
- 200 ohm resistor
- Micro USB cable
- Breadboard
- Jumper Wires
Circuit Diagram (With Connection)
- Connect the anode (longer leg) of the LED to GPIO 3 (D3) of the NodeMCU.
- Connect the cathode (shorter leg) of the LED to one end of the 200 ohm resistor.
- Connect the other end of the resistor to the GND pin of the NodeMCU.
Code
/*
Sarul Hassan
Complete project details at http://mechatronicslabrpi.blogspot.com/
*/
int pin = 3; // GPIO 3
void setup() {
// initialize GPIO 3 as an output.
pinMode(pin, OUTPUT);
}
void loop() {
digitalWrite(pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(pin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Code Explanation (Explanation Code Line by Line)
int pin = 3;
- This line declares a variablepin
and assigns it the value 3, which corresponds to GPIO 3.void setup() {
- This function is called once when the program starts. It initializes the settings.pinMode(pin, OUTPUT);
- This line sets GPIO 3 as an output pin.void loop() {
- This function runs repeatedly in a loop.digitalWrite(pin, HIGH);
- This line sets GPIO 3 to a high voltage level, turning the LED on.delay(1000);
- This line creates a 1-second delay.digitalWrite(pin, LOW);
- This line sets GPIO 3 to a low voltage level, turning the LED off.delay(1000);
- This line creates another 1-second delay.
Final Notes
- Ensure you have the correct board and port selected in the Arduino IDE:
- Go to Tools > Board > NodeMCU 0.9 (ESP-12 Module).
- Go to Tools > Port and select the appropriate port for your NodeMCU.
- Once your setup is complete, you can upload the code to your NodeMCU and see the LED blink on and off at 1-second intervals.
thanks sir nice post
ReplyDeletethanks sir nice post
ReplyDelete