Movement related to temperature

when I try and go 40000 or above it stops working.

int period = 40000;

What's the largest number that can fit into an int?

The delay function is throwing in an error every now and then so I tried the millis() function but I am having a small problem.

What error is delay "throwing".

You are not using the milis() function for timing in the correct non blocking way. The while loop is blocking your code in the same fashion as delay(). If you want to do something after an interval, then

//int period = 40000;
unsigned long period = 4000;
unsigned long time_now = 0;
unsigned long time_previous = 0;
 
void setup() {
    Serial.begin(115200);
}
 
void loop() {
    time_now = millis();
    if(time_now - time_previous >= period)
    {
      time_previous = time_now;  //alternatively, use time_previous += period  for a more constant interval  
      Serial.println("Hello");
    }
   
    //while(millis() < time_now + period){
        //wait approx. [period] ms
    //}
}