ESP8266 NODE MCU LED Blink
by Ramatronics Laboratory in Circuits > Microcontrollers
1729 Views, 5 Favorites, 0 Comments
ESP8266 NODE MCU LED Blink
INTRODUCTION:
Hello everyone!. Today in this instructables, I am going to introduce you about a more special microcontroller with wifi support. This microcontroller is ESP8266. most of you would have heard about this also. ESP8266 is a microcontroller which has wifi capability so you can control your projects form anywhere in the world using internet. Sounds awesome right. There are many ESP8266 based microcontroller boards available in the market but the one which is most popular and used is ESP8266 Node Mcu. One of the advantages of using this board is that we can program it using different high level programming languages i.e. C, C++, Micro Python and Circuit Python. In this project, I am going to use Micro Python high level programming language to program the ESP8266 Node Mcu board. I will make a simple Micro Python program to blink the on board LED of ESP8266 Node Mcu. I shall also blink an external LED. So let's get started.
Supplies
List of the Electronic components and Hardware:
https://quartzcomponents.com?sca_ref=3671286.DzEptz4I3w
ESP8266 Node Mcu
https://quartzcomponents.com/products/nodemcu-development-board?_pos=2&_sid=e28dbbfed&_ss=r
Bread Board
https://quartzcomponents.com/products/65pcs-breadboard-jumper-cable?_pos=7&_sid=87f214f85&_ss=r
LED(color = Red, Size = 5mm)
https://quartzcomponents.com/products/red-5mm-led?_pos=1&_sid=cca959799&_ss=r
Resistor - 330 Ohm
Micro-B USB Cable.
https://quartzcomponents.com/products/raspberry-pi-cable-for-charging?_pos=1&_sid=243da5802&_ss=r
ESP8266 Node Mcu
Bread Board
Jumper Wires
LED(color = Red, Size = mm)
Resistor = 330 Ohm
Micro-B USB Cable
Downloading and Installing Thonny IDE
Thonny is an integrated development environment (IDE). Which is use to program program microcontroller boards that supports Micro Python and Circuit Python programming languages. It is easy to use for beginners. You can download the latest version of Thonny from the link given below:
Downloading and Installing CP2102 USB Driver
ESP8266 Microcontroller does not support USB interface, so The ESP8266 Node Mcu uses either CH340G or CP2102 Chip to connect ESP8266 to computer. I have provided the link below to download the Driver for both Chips:
Download driver for CH340 Chip:
https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all
Download driver for CP2102 Chip:
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Downloading & Installing the Firmware on ESP8266 Node Mcu
You can download the latest version of ESP8266 Micro Python firmware from the link given below:
https://micropython.org/download/esp8266/
To program the ESP8266 Node Mcu with Thonny IDE, first we need to install the Micro Python firmware on ESP8266. For proper installation of firmware follow the given steps:
Connect ESP8266 Node Mcu to your computer. Run Thonny IDE on your computer and click on 'Tools' then choose 'options...' further click on interpreter. Now two options will appear on the IDE. In the first option, we have to select the MicroPython(ESP8266). In second option we have to choose the COM port on which our ESP8266 Node Mcu is connected to.
At the bottom you will see this option:- 'Install or update MicroPython'. click on this option and then again choose the PORT of your ESP8266 Node Mcu and in the second option we have to choose the location of the folder in which we have saved the ESP8266 Node Mcu firmware. Now just click on install option and firmware starts installing on the ESP8266.
After successfully installation of firmware you will be able to see this
MicroPython v1.19.1 on 2022-06-18; ESP module with ESP8266 Type "help()" for more information.
in the shell area of your Thonny IDE. Now type print('hello word') in the shell area and click enter and then ESP8266 prints hello world in the next line. This indicates that everything is working properly. Now we are ready to write and run the blink script on the ESP8266 Node Mcu board.
You can also download the firmware from my GitHub repository:
Blink the Onboard LED
The ESP8266 Node Mcu has two on board LEDs. The following Micro Python script blinks the on board LED connected on GPIO-2 Pin.
from machine import Pin
import utime
led = Pin(2, Pin.OUT) #configure GPIO-16(D4) pin as output
while True:
led.value(1) #set led pin high
utime.sleep(1) #delay for 1 second
led.value(0) #set led pin low
utime.sleep(1) #delay for 1 second
Making Circuit on Bread Board
Fix the ESP8266 and LED on the bread board as shown in the figures. Connect the cathode of the LED to the GND pin of the ESP8266 Board. Further connect the Anode of the LED to DO pin of ESP8266 with a 330 Ohm Resistor in series. Now connect the ESP8266 to computer using USB cable.
Blinking an External LED
To blink an external LED, I connect a 5mm Red led on GPIO-16 (D0) along a 330 Ohm resistor in series. Now write the following Micro Python script and run:
from machine import Pin
import utime
led = Pin(16, Pin.OUT) #configure GPIO-16(D0) pin as output
while True:
led.value(1) #set led pin high
utime.sleep(1) #delay for 1 second
led.value(0) #set led pin low
utime.sleep(1) #delay for 1 second