Light Dependent Resistors and Arduino

From Learning

Jump to: navigation, search

Light dependent resistors (LDRs) or photoresistors are resistors that have high resistance in the dark and decrease in resistance as they are exposed to more light.

Contents

Voltage Divider

The Arduino reads the voltage at a pin, so in order for the LDR to be read by the Arduino, it needs to affect the voltage. This is done by creating a voltage divider.

Voltage dividers are circuit made of 2 resistors. The resulting voltage is the ratio of those resistors.

Voltage divider schematic.png


V_{out} = \frac{R_2} {R_1+R_2} \times V_{in}

Voltage divider graphs.png

By replacing one of the resistors with an LDR, you have made a variable voltage divider dependent on the light level.


Circuit

The below circuit has two LDRs each in a different position within the voltage divider. The resistor value that you choose will vary according to the range of the LDR and the light levels you want to detect. 10kOhms may be a good starting place.

Arduino ldr.png

Full Source

void setup() {
  // open the serial connection at 
  // 9600 BAUD
  Serial.begin(9600); 
}
 
 
void loop() {
  // store the value read from pins 1 and 2
  // into a variable
  int sensorValue1 = analogRead(1);
  int sensorValue2 = analogRead(2);
  // print that variable over the serial connection
  Serial.print(sensorValue1);
  Serial.print(' ');
  Serial.println(sensorValue2);
}


See Also

Voltage Divider in Wikipedia

  • This page was last modified on 7 March 2012, at 08:56.
  • This page has been accessed 11,404 times.