Another word for LDR is photoresistor.
The resistance of LDR decreases with increase in the intensity of light.An LDR works in the similar manner as any other analog device would work.
Symbol of LDR:
For this tutorial you will need
- 1 arduino
- 1 LDR
- 1 10K resistor
- 1 breadboard
LDRs are non-polarized.That means you can connect it either way.
Code for LDR
int ldr = 0; //analog pin to which LDR is connected
int ldr_value = 0; //variable to store LDR values
void setup()
{
Serial.begin(9600); //start te serial monitor
}
void loop()
{
ldr_value = analogRead(ldr); //reads the LDR values
Serial.println(ldr_value); //prints the LDR values to serial monitor
delay(50); //wait
}
After uploading the code to arduino you can see the readings from LDR on serial monitor of arduino IDE.The value of LDR or any analog device when used with arduino ranges between 0 to 1023.
Aucun commentaire:
Enregistrer un commentaire