LDR


Here is everything you need to control a blinking LED with a light dependent resistor (LDR). LDRs are also called photoresistors, cadmium sulfide (CdS) cells or photo-conductors. They are resistors whose resistance decreases with increasing incident light intensity. All the parts are from your Adafruit Industries starter kit.


The LDR is not polarized.

Put the pins of the LDR into the breadboard.

A light-emitting diode (LED) is polarized.  It is easy to figure out which side of an LED is positive and which one is negative. The positive leg is slightly longer and if you look inside, the chunk of metal is larger on the negative side. Too much current will overheat an LED and possibly separate the leads. LEDs should be used with a current-limiting resistor in series with the LED.
 
LED calculator: current limiting resistor value http://www.superbrightleds.com/led_info.htm

Put the LED into the breadboard. Leave some space between it and the LDR.

This is a 1KΩ resistor - it is not polarized. Its stripes are: brown, black, red and gold. The first two bands encode the first two significant digits of the resistance value, the third is a power-of-ten multiplier or number-of-zeroes, and the fourth is the tolerance accuracy, or acceptable error, of the value (in this case +/-5%). A resistor is primarily used to create and maintain a known safe current within an electrical component. Resistance is measured in ohms (Ω).

A decent explanation of how to read these color codes is here http://www.bcdxc.org/resistor_color_codes.htm or you can use one of many online calculators, such as:
http://www.electronics2000.co.uk/calc/resistor-code-calculator.php there is even a free iPhone app on iTunes (ResistorCode by Christopher Brown).

Put the resistor into the breadboard. Put the left leg of the resistor in the same row as the right leg of the LDR.

Put the other 1KΩ resistor into the breadboard. Put the left leg of the resistor in the same row as the right leg of the LED.

Connect the row that the left leg of the LDR is in (on your breadboard) to +5v on your Arduino.

Connect the right leg of the first resistor (the one connected to the LDR) on your breadboard to gnd on your Arduino.

Connect the left leg of the first resistor (the one connected to the LDR) on your breadboard to pin 0 on your Arduino.

Connect the left leg (the longer one) of the LED on your breadboard to pin 13 on your Arduino.


Connect the right leg of the second resistor (the one for the LED) on your breadboard to gnd on your Arduino.

The circuit is complete, attach your USB cable and upload the code (below) to your Arduino.

The frequency of the blinking LED is now driven by the amount of light falling on the LDR.

// Adapted from Getting Started with Arduino by Massimo Banzi

#define LED 13 // the pin for the LED

int val = 0; // stores the value from the input pin

void setup() {
  pinMode(LED, OUTPUT); // LED is an output    } void loop() {
  
  Serial.begin(9600); // start the monitor      val = analogRead (0); // read the value from the LDR      digitalWrite(13, HIGH); // turn the LED on      delay (val); // pause      digitalWrite(13, LOW); // turn the LED off      delay (val); // pause      Serial.println(val); // print the reading in the monitor   delay (val); // pause    }
Comments