When creating the ladayada photocell program i used one 1k resistor and an LDR. I connected the cable from 5V, 0 and ground to the breadboard from the input section of the Arduino. I then connected the resistor to ground and the 0 point and connected the LDR to the ground and 5V. This then enabled me to run it after using the below code:
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;
// the analog reading from the analog resistor divider
void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
delay(1000);
}
Sunday, February 28, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment