Sunday, February 28, 2010

Day five....



Task 24 - Photocell simple testing sketch.
The LDR is a light dependent resistor. Using allows us to measure how much light is around it.

int photoCellPin = 0;
int photoCellReading;

void setup(void)
{
Serial.begin(9600);
}

void loop(void)
{
photoCellReading = analogRead(photoCellPin);

Serial.print("analog reading = ");
Serial.print(photoCellReading);

if (photoCellReading 'less than' 10)
{Serial.println(" - Very Dark");}
else
if (photoCellReading 'less than' 100)
{Serial.println(" - Dark");}
else
if (photoCellReading 'less than' 200)
{Serial.println(" - Dim");}
else
if (photoCellReading 'less than' 500)
{Serial.println(" - Light");}
else
if (photoCellReading 'less than' 600)
{Serial.println(" - Lighter");}
else
if (photoCellReading 'less than' 800)
{Serial.println(" - Bright");}
else
{Serial.println(" - Very Bright");}

delay(1000);
}

note: Blogger would not accept html symbol.

To see the full effect of this, after uploading it to the ardiuno, click on the "serial monitor" button in the sketch. At each second, it will display feedback about the light source at that time.

No comments:

Post a Comment