Connecting LED with Node MCU

In this blog, we will learn how to connect an LED using a resistor with Node MCU.

Hardware requirements-

  • Led
  • 200ohm resistor
  • Node MCU
Need for resistor
If the maximum capacity of the led is 5 Volts and we give it a power supply of 10 volts then the LED will burn but if we use a resistor it prevents the extra flow of current.
In the case of Node MCU, we don't need a resistor to turn an led on because node MCU supplies 3.3volts current that is bearable by an led, but it is a good practice.

You can watch this video for a detailed understanding:




There are two wires in an led.



The long one is a positive wire which gets the power from digital pins and the short one is connected to the ground.

How to make the connection-
  • Connect one end of the led to one end of the resistor.
  • Connect the other end of the led to the Ground pin of Node MCU.
  • Then connect the resistor with the D1 pin of node MCU. You can use any GPIO pin from D0 to D8. For a detailed pin explanation of Node MCU watch this video.
Now let's take a look at the code.
#define led D1 //controlling led connected to pin D1
void setup() {
  pinMode(led,OUTPUT); // declaring pinmode
}

void loop() {
  digitalWrite(led,1); //turns led on
  delay(1000); // 1000 milliseconds or 1 second delay
  digitalWrite(led,0); //turns led off
  delay(1000); // 1 second delay
}  

Here, I have declared a macro where led is the variable and D1 is the value
In the pinMode, we will declare whether we will use D1 as an input pin or output pin. Here D1 will send signals to light an led so it will act as an output pin
In the void loop, I have written the code that will control the LED.
Here (led,1) turns the led on and (led,0) turns the led off.

Now select the port and upload the code.

I have already explained the purpose of pinMode and digital write in my previous blog, so please read it before coming to this one.

When your code gets uploaded, you can see that led is glowing.
Try to connect two LEDs to two different pins and make them work together
Make this yourself and let us know in the comment section.

So this is how you connect an LED with Node MCU. We will keep blogging on technical topics. Keep following!

YouTube - youtube.com/techStormers
Facebook - facebook.com/techstormers
Instagram - instagram.com/techstormers

Comments

Popular posts from this blog

Introduction to Node MCU

The Rise of Functional Programming