millis() resets every time I open the Serial Monitor

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600); 

}

void loop() {
  // put your main code here, to run repeatedly:

  unsigned long currentTime = millis();
  Serial.println(currentTime); 

}

Opening the serial port (starting serial monitor) auto resets the Arduino. You can temporally disable the auto reset by putting a 10uf cap from reset to ground or, on some Arduinos, there is a jumper on the PCB that you can cut. You will need to re-enable the auto reset or manually reset the board to upload new code, though.

Yes it does.

What are you trying to do?

#include <Servo.h>
Servo servo1; 

unsigned long timeElapsed;
unsigned long engage; 

void setup() {

  servo1.attach(9); 
  servo1.write(20); 
  Serial.begin(9600); 

}

void loop() {
  // put your main code here, to run repeatedly:

  engage = 60000; 
  timeElapsed = millis(); 
  Serial.println(timeElapsed); 

  

  if (enagage == timeElapsed){

    *DO THING*
    
  }

  

}

I want to see the time elapsed since the arduino was powered so that I can observe the amount of time elapsed through the Serial Monitor before the servo is activated

Then disable the autoreset while doing this - put a 10uf cap (or anything around there - exact value isn't critical) between reset and ground. Note that you need to remove that in order to upload new sketch - autoreset is used for that.

This code is able to do it, so I don’t know why the previous code cant

// Adds Extra Serial Port 
#include <SoftwareSerial.h> 

// Assigns Serial Port RX to pin 11
SoftwareSerial portOne(10,11);

// Temperature Sensor #1    
    int temp1;
    float temp1Volt;
    float temp1C;
    float temp1F;
    
// Temperature Sensor #2   
    int temp2;
    float temp2Volt;
    float temp2C;
    float temp2F;
   
// Humidity Sensor    
    int humidity;
    float humidityVolt;
    float RH;
    
// Presure Sensor         
    int pressure;
    float pressureVolt;
    float psi;
    
// Accelerometer X  
    int accelX;
    float accelXVolt;
    float accelXG;
    
// Accelerometer Z
    int accelZ;
    float accelZVolt;
    float accelZG;

// Uplink Rate 
   int uplinkRate = 1; 
    
// Time keeper 
// The time stamp used when recording data points
    uint32_t timeStamp = 0;  
    
void setup() {
  // put your setup code here, to run once:
// put your setup code here, to run once:

      Serial.begin(9600);
      portOne.begin(9600); 


// setup the LED Visual Display
      pinMode(3, OUTPUT);  //Arduino on
      pinMode(4, OUTPUT);  //Internal Temp
      pinMode(5, OUTPUT);  //External Temp
      pinMode(6, OUTPUT);  //Humidity
      pinMode(7, OUTPUT);  //Pressure
      pinMode(9, OUTPUT);  //Accels

// turn on Arduino LED
      digitalWrite(3, HIGH);  // Leave on while power is on 

// Print Column Headers

      portOne.println("Time,Temp1F,Temp2F,RH,Pres,AccX,AccZ");
      
}

void loop() {
  // put your main code here, to run repeatedly:
//   put your main code here, to run repeatedly:

//   Turn script running leds OFF at begining of loop
     digitalWrite(4, LOW);
     digitalWrite(5, LOW);
     digitalWrite(6, LOW);
     digitalWrite(7, LOW);
     digitalWrite(9, LOW);
     
     delay(500);  //Amount of time between samples (milliseconds)
     
// Log the time
     timeStamp = millis();
     portOne.print(timeStamp);       
             
     temp1 = analogRead(A0);
     temp1Volt = temp1*(5.0/1023);
     temp1C = (temp1Volt - 0.5)/(0.01);
     temp1F = (temp1C*(9.0/5.0) + 32);
     portOne.print(",");    
     portOne.print(temp1F, 2);
     digitalWrite(4, HIGH);
 
     temp2 = analogRead(A1);
     temp2Volt = temp2*(5.0/1023);
     temp2C = (temp2Volt - 0.5)/(0.01);
     temp2F = (temp2C*(9.0/5.0) + 32);
     portOne.print(",");    
     portOne.print(temp2F, 2);
     digitalWrite(5, HIGH);
    
     humidity = analogRead(A2);
     humidityVolt = humidity*(5.0/1023);
     RH = (((humidityVolt/5.0)-0.16)/0.0062);
     portOne.print(",");    
     portOne.print(RH, 2);
     digitalWrite(6, HIGH);

     pressure = analogRead(A3);
     pressureVolt = pressure*(5.0/1023);
     psi = (pressureVolt-0.5)*(15.0/4.0); 
     portOne.print(",");    
     portOne.print(psi, 2);
     digitalWrite(7, HIGH);
     
     accelX = analogRead(A4);
     accelXVolt = accelX*(5.0/1023);
     accelXG = (accelXVolt - (3.3/2))/(0.330);
     portOne.print(",");    
     portOne.print(accelXG,3);

     accelZ = analogRead(A5);
     accelZVolt = accelZ*(5.0/1023);
     accelZG = (accelZVolt - (3.3/2))/(0.330);
     portOne.print(",");    
     portOne.print(accelZG,3);
     digitalWrite(9, HIGH);
     
     portOne.println();

     uplinkRate++; 

     if ( (uplinkRate % 20) == 0){

      Serial.print("Uplink Completed"); 
      Serial.println();
      Serial.print("Time,Temp1F,Temp2F,RH,Pres,AccX,AccZ"); 
      Serial.println(); 

      Serial.print(timeStamp);  
             
     temp1 = analogRead(A0);
     temp1Volt = temp1*(5.0/1023);
     temp1C = (temp1Volt - 0.5)/(0.01);
     temp1F = (temp1C*(9.0/5.0) + 32);
     Serial.print(",");    
     Serial.print(temp1F, 2);
     digitalWrite(4, HIGH);
 
     temp2 = analogRead(A1);
     temp2Volt = temp2*(5.0/1023);
     temp2C = (temp2Volt - 0.5)/(0.01);
     temp2F = (temp2C*(9.0/5.0) + 32);
     Serial.print(",");    
     Serial.print(temp2F, 2);
     digitalWrite(5, HIGH);
    
     humidity = analogRead(A2);
     humidityVolt = humidity*(5.0/1023);
     RH = (((humidityVolt/5.0)-0.16)/0.0062);
     Serial.print(",");    
     Serial.print(RH, 2);
     digitalWrite(6, HIGH);

     pressure = analogRead(A3);
     pressureVolt = pressure*(5.0/1023);
     psi = (pressureVolt-0.5)*(15.0/4.0); 
     Serial.print(",");    
     Serial.print(psi, 2);
     digitalWrite(7, HIGH);
     
     accelX = analogRead(A4);
     accelXVolt = accelX*(5.0/1023);
     accelXG = (accelXVolt - (3.3/2))/(0.330);
     Serial.print(",");    
     Serial.print(accelXG,3);

     accelZ = analogRead(A5);
     accelZVolt = accelZ*(5.0/1023);
     accelZG = (accelZVolt - (3.3/2))/(0.330);
     Serial.print(",");    
     Serial.print(accelZG,3);
     digitalWrite(9, HIGH);
     
     Serial.println();

      portOne.print("Uplink in Progress"); 
      portOne.println();
      
     } 

}

It will autoreset (except when disBled as i described above)when connection is opened on the hardware serial port only - the same port you upload on. It does not apply to software serial ports or serial ports other than the first one on boards with muliple.serial.ports. Search for info on the dtr reset circuit for more background - details have been discussed ad nauseum.

It is needed to reset into the bootloader so you can easily upload a sketch (before the dtr trick was figured out, the early arduino boards had you press the reset button at the exact right moment in order to upload, it was awful)

If you connect a USB-TTL cable to the Rx Tx and GND connections you can use it to communicate between a PC and an Arduino without causing a reset.

...R

Have a look here: https://forum.arduino.cc/index.php?topic=525237.msg3583376#msg3583376 I've found a 0.1 uF ceramic cap works fine with Nanos, never tried on a UNO or Mega.