📅  最后修改于: 2023-12-03 14:59:22.473000             🧑  作者: Mango
Arduino LDR refers to the Light Dependent Resistor used in Arduino boards for detecting light intensity. In this article, we will discuss the concept of LDR, its features, and how to use it with Arduino boards.
An LDR is a kind of resistor made of semiconductor material that changes its resistance value based on the exposure to light. These resistors are sensitive to light and change their resistance when they encounter light of different intensities. When light falls on the LDR, its resistance decreases, and when there is no light, its resistance increases.
Some of the important features of LDR are:
To use LDR with Arduino boards, we need to build a circuit that connects LDR with the board. Here is the circuit diagram:
+5V
|
|
|
|
|
|
LDR
|
|
|
|
|
|
|
10k ohm |
Res |
Arduino Pin A0-------
In this circuit, one end of the LDR is connected to the +5V pin of the Arduino board, and the other end is connected to the analog input pin A0 of the Arduino board through a 10k ohm resistor. The 10k ohm resistor is used to create a voltage divider circuit that measures the voltage across the LDR.
Here is an example Arduino code to use LDR:
const int ldr = A0; //LDR is connected to analog input pin A0
void setup() {
Serial.begin(9600); //initialize serial communication
}
void loop() {
int ldrValue = analogRead(ldr); //read LDR value
Serial.println(ldrValue); //print LDR value on serial monitor
delay(1000); //wait for 1 second
}
This code reads the analog value of the LDR using the analogRead() function and prints the value on the serial monitor.
In this article, we discussed the concept of LDR, its features, and how to use it with Arduino boards. LDRs are useful in various applications such as streetlights, cameras, and speed controls. They are easy to interface and can be used to detect light intensity in a cost-effective manner.