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.

Categories: IoT Lab. No Comments on LDR Sensor Module with NodeMCU ESP8266

In this article we will learn how to implement LDR sensor module with NodeMCU ESP8266 and Arduino. 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 using LDR sensor with NodeMCU and ESP8266:

 

Aim of Experiment

To capture light intensity in the environment using LDR sensor

 

Components Required

  • NodeMCU – 1
  • LED – 1
  • 330 Ω Resistor – 1
  • 10k Ω Resistor – 1 (acts as a pull down resistor) (for analog LDR)
  • LDR Sensor (Analog or Digital) – 1
  • Breadboard – 1

 

Connections Diagram (Schematic)

LDR Sensor Module with NodeMCU ESP8266

 

LDR Sensor Module with NodeMCU ESP8266 2

 

Code (C++/Arduino IDE)

const int ldr = D2;
const int led = D0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(ldr, INPUT);
  pinMode(led, OUTPUT);
  delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  int value = digitalRead(ldr);
  if(value == 1){
    digitalWrite(led, HIGH);
  }
  else{
    digitalWrite(led, LOW);
  }
  Serial.println(value);
  delay(200);
}

 

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?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Leave a Reply

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