Easy steps 2 Interface NodeMCU with push-button?

OVERVIEW

In the era full of technologies, we are in search of technologies that we have full control of. So, we require a gadget that is a semi-automatic(for example: Interface NodeMCU with push button which works like a remote control device),i.e., which is controlled manually as well as automatically. One component that is used to make our device controlled manually at just one click is a push button.

In this blog you will learn how to :
1. Interface NodeMCU with push button
2. Control different LEDs connected to NodeMCU

Interface NodeMCU with push button

Now, let’s get started. Firstly, the push button is a passive device that is used to switch between the active high and active low states. Now, let’s understand what is this active high and active low state. Active low means the function gets done when input is in a low state. Active high means function gets done when input is in a high state.

So, how does a push button switches between active high and active low states? In the figure shown below, you can see when the button is not pressed at that time you are getting the output as 1 whereas when we are pressing the button at that time we are getting the output as 0 as when the button is pressed it completes the circuit for discharging through the ground.

So, from the above figure it will be clear to you that when a button is pressed it completes the circuit and changes the path and also changes it’s state.

In this way, we will be using the output coming from the above circuit and will send it to the NodeMCU to perform different tasks according to the present state (HIGH or LOW). Now let’s interface the above circuit with NodeMCU and control the LED state, i.e., turning the LED ON or OFF. So, let’s make the connection for the interfacing of NodeMCU with push button and LED. Now make all the connection as shown below.

Interface NodeMCU with push button

So, these are the connections to Interface NodeMCU with push button and LED. In the above circuit we are not connecting any external LED because we are using the in-built LED of NodeMCU which is connected to pin D4. For more info and a proper clarification you can also watch the video show below.

Now, our next step is to write a program to perform this task of controlling LED with a push button interfaced with NodeMCU. If you don’t have arduino installed on your system then download it from here and install it. So the program is as shown below, Now just open Arduino IDE, create a new file and write the program written below:

void setup() {
// put your setup code here, to run once:
pinMode(D3,INPUT);
pinMode(D4,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int button=digitalRead(D3);
if(button==1){
digitalWrite(D4,LOW);
delay(100);
}
else{
digitalWrite(D4,HIGH);
delay(100);
}
}

After you are done with the code verify the code and upload it to NodeMCU to test your program. If in case you are facing difficulty while uploading the program the check this video:

I hope everything was clear to you that is shown you in the blog, but still if you are having any doubts or any query related to the topic then do leave a comment below in the comment section and I’ll try to resolve it at the earliest. Also, you can suggest me to write a blog for you of your choice if you feel I can explain to you well then please suggest in as well. Also check these links to learn more Send Real-Time Sensor Data to Google Firebase with ESP8266,BEST WAY TO BUILD YOUR OWN SMARTWATCH | INTERNET OF THINGS | ESP32,etc

For any doubts or queries related to the How to Interface NodeMCU with push-button feel free to leave a comment below in the comment section. Also, do comment your valuable feedback to appreciate us. For any further information or queries, you can also WhatsApp me at +91 8209829808.

Stay tuned and happy learning. 😉

One thought on “Easy steps 2 Interface NodeMCU with push-button?

Leave a Reply

Your email address will not be published. Required fields are marked *