Erratic Serial Behavior

Hello there. I’m a beginner that has decided to join this community. I’ve began to wet my feet with the code and developed some basic blinky lights with an Arduino Uno R3. However I ran into problems trying to create a night light with an LED. Reading values from a photo-resistor works fine,but when combined with additional code, I experience some erratic behavior.

The LED remains turned on when the serial is reading values.
If I should remove the serial portion from the code, the program works as intended.
Reading up on the internet results in no useful information.

Any assistance would be highly appreciated. Thank you!

/*
Average Light Reading 10k Resistor at 1:12pm with full sunlight in a room.
612-620

Average Light Reading with a 10k Resistor with a Flashlight in a room.
~982
*/

int photoresistor = 0;
int led = 1;

void setup() {
  analogReference(DEFAULT);
  pinMode(photoresistor, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightvalue = analogRead(photoresistor);
  
  Serial.println(lightvalue);
  delay(1000);
  
  if (lightvalue < 620) {
  digitalWrite(led, HIGH);
  }
  
  if (lightvalue > 620) {
  digitalWrite(led, LOW);
  }

  else { 
  digitalWrite(led, LOW);
  }
}

edit: Cleaned up grammar and code a bit.

You will have a problem using Pin 1 for both Serial and an LED. Try moving it to Pin 2.

I think your clean-up must have changed something since this statement:

  if (lightvalue > 620) {
  digitalWrite(led, LOW);
  }
  else { 
  digitalWrite(led, LOW);
  }

is functionally equivalent to:

  digitalWrite(led, LOW);

Thank you! I must of left it accidentally when I had a buzzer feature with the code.

Still nothing's changed on the serial issue.

Verenos:
Still nothing's changed on the serial issue.

Did you move the LED to a different pin so it would not conflict with Serial I/O on pins 0 and 1?

Wow, I moved the LED pin over to number 8 on the board and in code, and now it works. Thank you! Then again, why does this happen? Is there something special with pin 0 and 1?

In short, they are used only for serial purposes when you include Serial.begin();

Verenos:
Wow, I moved the LED pin over to number 8 on the board and in code, and now it works. Thank you! Then again, why does this happen? Is there something special with pin 0 and 1?

Pins 0 and 1 are the Serial I/O pins. The onboard USB-to-Serial hardware is connected to those pins. If you don’t need them for Serial I/O you can use them as general-purpose digital I/O pins but you may have to disconnect them to upload a new sketch. In general Serial.print() is so useful for debugging that unless you have exhausted all other possibilities you should NOT use Pin 0 or Pin 1 for anything.