1.Using an LDR (Light Dependent Resistor) with Arduino to Measure Light Intensity

 Using an LDR (Light Dependent Resistor) with Arduino to Measure Light Intensity.



Components Needed:

  1. Arduino board
  2. LDR (photoresistor)
  3. 10kΩ resistor
  4. Breadboard and jumper wires

Circuit Connections:

  1. LDR: Connect one leg of the LDR to 5V on the Arduino, and the other leg to an analog input pin (e.g., A0).
  2. Resistor: Connect a 10kΩ resistor between the LDR leg (that goes to the analog pin) and GND. This forms a voltage divider.

Explanation:

  • When light falls on the LDR, its resistance changes, affecting the voltage at the analog pin.
  • The analog pin reads a value between 0 and 1023 depending on the light intensity.

Example Code:

C++ Code


int ldrPin = A0; // Analog pin to which LDR is connected int ldrValue; void setup() { Serial.begin(9600); // Start the serial communication to view the LDR value } void loop() { ldrValue = analogRead(ldrPin); // Read the LDR value Serial.println(ldrValue); // Print the value to the Serial Monitor delay(500); // Delay for half a second }

Explanation of Code:

  • analogRead(ldrPin) reads the value from the LDR, which will vary based on light intensity.
  • You can use this value to trigger actions, such as turning on LEDs when it gets dark or adjusting the brightness of a display.


Comments

Popular posts from this blog

Arduino projects