Run different code on different type of reset in arduino nano
The MCUSR register (page 79 of the datasheet) tells you what kind of reset happened most recently. As long as the USB interface chip on your nano isn't controlling the RESET pin without the port being opened (i.e., toggling it at power up regardless of the USB state) then you could query that register to see how it reset:

if (MCUSR &amp; (1 &lt;&lt; 0)) { // POR
    digitalWrite(4, HIGH);
} else if (MCUSR &amp; (1 &lt;&lt; 1)) { // External Reset
    digitalWrite(5, HIGH);
}


However, if the USB chip does toggle the RESET pin then there is no way you can distinguish between the two resets since they are bot the same "external" reset using the RESET pin.