Have you heard about the LDR sensor?

Sathya
2 min readNov 29, 2021

--

If your answer is NO then you came to the right place at the right time. Through this blog, we are going to implement an LDR sensor using NodeMCU.

Source

So What is an LDR sensor?

If you google it you will get the following answer.

An LDR is a component that has a (variable) resistance that changes with the light intensity that falls upon it. This allows them to be used in light sensing circuits. … They can be described by a variety of names from light dependent resistor, LDR, photoresistor, or even photo cell, photocell or photoconductor.

The above definition seems a little perplexing but if we decode it then we can understand that LDR is a sensor that actually detects light. If light falls on the sensor then the sensor sends signals to the LED or any output device.

Basic Requirements

  • NodeMCU
  • Connecting wires
  • LED
  • LDR Sensor
  • Resistor
  • A PC with Arduino IDE installed and configured

Circuit Diagram

Source

Arduino Code

  • In the above code, we initially set the appropriate pins for our LED and LDR sensor in this case they are D6 and D2 respectively
  • Then we set the LDR’s pinMode to be INPUT as it received the light signals and LED’s pinMode to be OUTPUT
  • We initially set the LED to be in the LOW state
  • After that, we create the condition

Now upload the code and test it

--

--

No responses yet