Wednesday 21 January 2015

Using a LDR with Arduino


To know about LDR check wikipedia


The sketch of the above schemetic is based on LED blinking code,but instead of using a fixed delay the rate is determined by the light sensitive sensor called LDR.

So now the following sketch will help you how to read the value of the LDR based on the sensitivity of light.

// Sketch to get the input from the LDR

int inputLDR=A0;
void setup()
{
  pinMode(inputLDR,INPUT);
 Serial.begin(9600);  // starts a serial connection with your computer to display the input of LDR with Baud rate of 9600
}
void loop()
{
   int a;    // to store the values which we received from the LDR
   a=analogRead(inputLDR); // Gets input from the LDR
   Serial.println(a);
}