Photocell operating LED code

Hi, I am wondering if you could please help me work with a photocell code that I have. I would like for the photocell to turn an led on and am not sure what I have wrong in the code. I am quite new to this area of expertise and sure could use some help!

Here is the code that I have been trying to work with:

int InitialReading;
int Reading;

void setup()
{
Serial.begin(9600);
pinMode (11, OUTPUT);
InitialReading = analogRead(0);
Serial.print("Initial Reading= ");
Serial.println(InitialReading);

}

void loop()
{
Reading = analogRead(0);
Serial.println(Reading);

if(Reading>(60+InitialReading))
digitalWrite(11,HIGH);

if(Reading<= (60+InitialReading))
digitalWrite(11,LOW);

delay(1000); // waits 1 sec
}

Thank you for your time!

3 things come to mind:

  1. You should use an "else" instead of a 2nd if block (although this won't break anything)
  2. If you get rid of the reading stuff and just do digitalWrite(11, HIGH), does your LED light?
  3. Are you certain that the 60 value that you're testing against is appropriate?

What are you in trouble with?
Can you describe what's wrong for you?

Code looks good to me, maybe it's the hardware.

When you have that working you might want to add a hysteresis, that is a different threshold to turn it on to that to turn it of. That will stop it flickering wildly when the sensor is at the threshold level.

What sort of values are you getting back from the Photocell? It also might be worth sticking in a delay before the initial read. Quite a few sensors take a second or so to fully stablise, if yours is doing that then the inistial read could be WELL off. Lastly, have you tried sing the onboard LED (pin 13 i think offhand). Just in case your LED is dud.

Cynar