Running code independently

I have a LDR sensor reading analog value, i have a led, once ldr reads 800 or above it should turn on led and wait for 1 hour and turn it off, Problem here is let led be in whatever state but analog values should print in serial monitor all the time.

What have you tried?

I'm guessing you use an delay(....); function for the led to stay on? Is that correct?

Incase of that, you could use millis. As an if function for the timing.
https://forum.arduino.cc/index.php?topic=503368.0

while using millis your loop keeps online, and doesn't wait until the time of delay come. So you will be able to keep printing the analog value.

int val;
void setup() {
pinMode(D5,OUTPUT);
digitalWrite(D5,LOW);
Serial.begin(9600);
}

void loop() {
val=analogRead(A0);
Serial.println(val);
if(val>800){
digitalWrite(D5,HIGH);
delay(3600000);
}

digitalWrite(D5,LOW);

}

i dont want to stop analogread for 1 hour

i dont want to stop analogread for 1 hour

So stop doing this:

delay(3600000);

Delay stops everything from happening while the delay is running. The post linked in reply #2 by Gert-Jan_Snik is the answer. Read it and if you have questions, ask away.

AbhayHM:
int val;
void setup() {
pinMode(D5,OUTPUT);
digitalWrite(D5,LOW);
Serial.begin(9600);
}

void loop() {
val=analogRead(A0);
Serial.println(val);
if(val>800){
digitalWrite(D5,HIGH);
delay(3600000);
}

digitalWrite(D5,LOW);

}

i dont want to stop analogread for 1 hour

something like this maybe then:

#define D5 5
const unsigned long WAIT_TIME = 3600000;
unsigned long old_time1, old_time2;
uint16_t val;
uint8_t flag;
void setup() {
  pinMode(D5, OUTPUT);
  digitalWrite(D5, LOW);
  old_time1 = millis();
  old_time2 = old_time1;
  Serial.begin(9600);
  flag = 0;
}

void loop() {
  analogRead(A0);
  val = analogRead(A0);

  if (val > 800 && flag == 0) {
    digitalWrite(D5, HIGH);
    old_time1 = millis();
    flag = 1;
  }
  else if (flag == 1 && millis() - old_time1 > WAIT_TIME) {
    digitalWrite(D5, LOW);
    flag = 0;
  }
  
  if (millis() - old_time2 > 1000) { //serial print every 1000ms
    Serial.println(val);
    old_time2 = millis();
  }
}

The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R