/ / Introduction
LDR stands for Light Dependent Resistor and is also known as a
photoresistor. An LDR is made of a high resistance semiconductor. The LDR is similar to a normal resistor with the exception
that normal resistor have fixed values and the LDR:s resistance is
dependent on light in its vicinity. It is very hard to use an LDR to
determine an exact amount of light in a given setting but they are
good enough to use for determining light in a broader sense — if its
dark or light.
/ /
Materials
- One LDR
- One 10k resistor
- Conductive thread
- Three wires
Follow the illustration for how to sew the LDR and resistor
onto a piece of fabric and where the wires should connect to the
arduino:
The resistor in the example is used as what is called a
pull up resistor. You will sometimes use pull up resistors to ensure that you won’t get
5V straight back in the Arduino. A pull up resistor is the same as a
normal resistor but you use them to lower the output voltage from a
power source. Connect a red cable to one of the legs of the resistor
and to 5V on the Arduino. In between the resistor and the LDR
put a wire that connects to your analog pin on the Arduino. The
same connection goes to one leg of the LDR. It doesn’t matter
which leg you connect it to. From the other leg of the LDR, sew a
wire that connects to GND on the Arduino.
When you have connected everything try the following code
and see what values the LDR will give you:
/* declare the analog pin you are using on the Arduino */
/* create a variable to store the LDR value */
void setup(){
/* set up communication and communication speed */
}
void loop(){
/* read the value from ther LDR and store it */
/* print the value stored in myLDR */
/*delay 200 milliseconds */
}
In the above code example you read the value, store it and print it
back to the computer. Don't forget to open your serial monitor
in the Arduino IDE and set it to 9600 baud to be able to see the
value printed from the Arduino. Once you get everything to work,
try covering the LDR with your hand and check what value the
Arduino prints back. Remember this value and try the next code
example.
/* declare the analog pin you are using on the Arduino */
/* declare digital 13 as an led pin */
/* create a variable to store the LDR value */
/* create a variable to hold the threshold value for dark */
void setup(){
/* set up communication and speed */
/* declare ledPin as OUTPUT */
}
void loop(){
/*read the value and test if it is less tha your threshold.
If it is, light the led. If it isn't, turn off the led
*/
}