Menu Close

NodeMCU Digital Input with Output Arduino IDE

his tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take digital input and show that as an output on NodeMCU on Arduion IDE. The input is taken through switch and the output is taken on LED, the LED glows when button is pressed.

1. Introduction:

A discrete signal (digital signal) supplied to the NodeMCU is known as digital input. This signal can be generated manually using a push button switch.

Push button switch is a switch which provides connectivity between its terminals when pressed. When the button is released terminals get disconnected.

This tutorial is for NodeMCU on Arduino IDE. Please note that the same tutorial can be performed on LUA as well.

S.No.ItemQuantity
1 NodeMCU 1
2 Breadboard 1
3 LED 1
4 Push Button Switch 1
5 Resistor 1k 1
6 Resistor 10k 1
7 Jumper Male to male 6

2. Building Circuit

Schematic Diagram:

Circuit Layout:

3. Programming:

Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.

You may download this code (Arduino Sketch) from here.

// Robo India Tutorial 
// Digital Input and Output on LED 
// Hardware: NodeMCU

const int BUTTON = 4;
const int LED = 0;
int BUTTONstate = 0;

void setup(){ 
  pinMode(LED, OUTPUT);
  pinMode (BUTTON, INPUT);
 }
 
void loop() {
  BUTTONstate = digitalRead(BUTTON); 
  if (BUTTONstate == HIGH)
    {
      digitalWrite(LED, HIGH);
    }
    else
    {
      digitalWrite(LED, LOW);
    }
}

4. Output

After successful uploading of the code, try pressing and releasing the button, the LED glows if the button is pressed and gets off when the button is released.

5. Troubleshooting

LED is not glowing: Try changing polarity of LED, Pull it out, rotate it by 180 degree and insert bit again.
Still not glowing: Check the switch with multimeter, it’s terminal should be connected in pressed condition and vice-versa.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply