8 novembre 2013

Photorésistance ldr arduino

LDR stands for Light dependant resistor.An LDR is usually made of a semiconductor material(Normally Silicon) doped with a small percentage of a valency 5 material (commonly Arsenic), to make it an "N" material.
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. 1  arduino
  2. 1  LDR
  3. 1  10K resistor
  4. 1 breadboard
Connect the LDR in this way.
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