09 LDR (Light Sensor) with ESP32

 Introduction:-   

Welcome back to new post LDR with ESP32 board, Here we will learn How to interface LDR with ESP32 and We will learn programming also. LDR stand for Light Dependent Resistor  it means LDR is a register which resistance depend on falling light intensity on LDR. When light intensity increases then its resistance will decrease and vice versa. We will change Light intensity on LDR then we will se the Analog value on Serial Monitor.  

Tools and Materials:-

  • ESP32 Development Board
  • Light Dependent Resistor
  • 10K Ohms Resistor
  • Some male to male jumper wires
  • Breadboard

Circuit Diagram:- 

Breadboard Circuit:-

Keep all component with you and create breadboard circuit like shown above. Here I am using D2 pin as Analog Input and LDR connected with 10k resistor like Potential meter configuration, 10k resistor connected to ground and LDR connected to 3.3 volt , Joint point of Resistor and LDR is connected to D2 pin of ESP32 board.

Programming:-
 #define Light 2  

We are using GPIO 2 as an Analog Input so I define first GPIO 2 as Light.
 void setup() {  
Serial.begin(115200);
delay(1000);
}
In setup function I start serial monitor at 115200 bps.
 void loop() {  
int val = analogRead(Light);
Serial.println(val);
delay(100);
}
In loop function I am reading Light Pin and store in val variable. and in next line it is printing in serial monitor.

Output on Serial monitor

Code:-

Click here to download the code

Watch this video for more details:-
Thanks for visiting🙏

No comments:

Powered by Blogger.