Datasheet
NOT WORKING? (3 things to try)
MAKING IT BETTER
CODE (no need to type everything in just click)
MORE, MORE, MORE:
Still not quite working?
You may be in a room which is
either too bright or dark. Try
turning the lights on or off to
see if this helps. Or if you have
a flashlight near by give that a
try.
It Isn't Responding to
Changes in Light.
Given that the spacing of the
wires on the photo-resistor is
not standard, it is easy to
misplace it. Double check its in
the right place.
More details, where to buy more parts, where to ask more questions:
http://ardx.org/CIRC09
LED Remains Dark
This is a mistake we continue
to make time and time again,
if only they could make an LED
that worked both ways. Pull it
up and give it a twist.
Reverse the response: Light controlled servo:
Perhaps you would like the opposite response. Don't Let's use our newly found light sensing skills to control a
worry we can easily reverse this response just change: servo (and at the same time engage in a little bit of Arduino
analogWrite(ledPin, lightLevel); ---->
code hacking). Wire up a servo connected to pin 9 (like in
analogWrite(ledPin, 255 - lightLevel);
CIRC-04). Then open the Knob example program (the same
Upload and watch the response change:
one we used in CIRC-08) File > Examples > Servo >
Knob. Upload the code to your board and watch as it works
Night light:
unmodified.
Rather than controlling the brightness of the LED in
Using the full range of your servo:
response to light, let's instead turn it on or off based on
You'll notice that the servo will only operate over a limited
a threshold value. Change the loop() code with.
portion of its range. This is because with the voltage dividing
void loop(){
int threshold = 300;
circuit we use the voltage on analog pin 0 will not range from
if(analogRead(lightPin) > threshold){
digitalWrite(ledPin, HIGH);
0 to 5 volts but instead between two lesser values (these
}else{
values will change based on your setup). To fix this play with
digitalWrite(ledPin, LOW);
}
the val = map(val, 0, 1023, 0, 179); line. For hints on what to
}
do visit http://arduino.cc/en/Reference/Map .
Download the Code from ( http://ardx.org/CODE09 )
(copy the text and paste it into an empty Arduino Sketch)
/*
* A simple programme that will change the
//output
* intensity of an LED based on the amount of
}
* light incident on the photo resistor.
/*
*
* loop() - this function will start after setup
*/
* finishes and then repeat
*/
//PhotoResistor Pin
void loop()
int lightPin = 0; //the analog pin the
{
//photoresistor is
int lightLevel = analogRead(lightPin); //Read the
//connected to
// lightlevel
//the photoresistor is not
lightLevel = map(lightLevel, 0, 900, 0, 255);
//calibrated to any units so
//adjust the value 0 to 900 to 0 to 255
//this is simply a raw sensor
lightLevel = constrain(lightLevel, 0, 255);
//value (relative light)
//make sure the value is between 0 and 255
//LED Pin
analogWrite(ledPin, lightLevel); //write the value
int ledPin = 9;//the pin the LED is connected to
}
//we are controlling brightness so
//we use one of the PWM (pulse
//width modulation pins)
void setup()
{
pinMode(ledPin, OUTPUT); //sets the led pin to
25
CIRC-09