help understanding this ldr sketch

I’ve played with the basic LDR sensor sketch that reads the ldr sensor and writes the value to an led. Everything worked as it should. I tried playing with the sketch, so that if the ldr data is below a threshold it would turn the led on. If it was above the threshold, it would turn the led off.
It seems simple. On the Serial monitor everything seems to work correctly, but the led won’t turn on. I’ve gone over it, but I’m missing something. Can anyone offer some insight?
Here’s the sketch:

/*trial with LDR
if the ldr sensor reads below a certain threshold, it should trigger the LED to light.
const int analogInPin = A0;
const int ledPin = 9;
int photocell;

void setup() {


void loop() {
photocell = analogRead(analogInPin);
if (photocell < 150) {
digitalWrite(ledPin, HIGH);
Serial.println(“should be high”);
} else {
digitalWrite(ledPin, LOW);
Serial.println(“should be low”);


If you're going to write to it, don't you think you should make it an output?

(Is there a code tags shortage today?)

Yeah, I was just going to delete my post, as I discovered I hadn't set the pinMode to output....dumb mistake...sorry for wasting your time!

If you don't forget pinMode once a month, you're not writing much code :o