Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Computer Science » IoT Lab » Digital Input and Output using NodeMCU ESP8266
Suryateja Pericherla Categories: IoT Lab. No Comments on Digital Input and Output using NodeMCU ESP8266
0
(0)

In this article we will cover how to implement digital input and output using NodeMCU ESP8266. If your are new to Internet of Things (IoT), learn about IoT by visiting our Internet of Things tutorial for beginners.

 

Watch this video to learn about digital input and output using NodeMCU:

 

Aim of Experiment

To implement digital input output

 


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


Components Required

  • NodeMCU – 1
  • LED – 1
  • 330 Ω Resistor – 1
  • 10 kΩ Resistor – 1 (acts as a pull down resistor)
  • Pushbutton – 1
  • Breadboard – 1

 

Connections Diagram (Schematic)

Digital input output using NodeMCU ESP8266

 

Code (C++/Arduino IDE)

//By default, NodeMCU built-in LED is connected to pin D4
const int led_pin = D0;
const int push_pin = D2;

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

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(push_pin) == 1){
    digitalWrite(led_pin, HIGH);
  }
  else{
    digitalWrite(led_pin, LOW);
  }  
}

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

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

Blogarama - Blog Directory