Arduino stops working when pc turned off

I have an ESP32 running a sketch, programmed via arduino IDE on a windows 10 PC.
Its connected via a powered usb hub.

I dont want to leave the PC on 24/7 - but when I turn it off the arduino stops - with the power LED still on.

Yet the program runs fine if I just plug it into a USB power source.

I'm sure there is a simple answer but google couldnt find it for me. Also (ok a second question) - is there no search facility on this forum?

What kind of sketch does the ESP32 perform?
Why did you decide that it would stopped?

There is a search box in the upper right.


He may have implemented one of the "fixes" to suppress the stupid green top bar. :grin:

I have, so I don't have it either, but getting rid of the useless screen space-wasting bar is worth any minor loss.

Okay, Here it is. :wink:

@johnerrington Do you have a piece of code like
while (!Serial); // wait for serial port to open.
in your code?

Thanks @Paul, silly me found it now - but a search for "stoops working when PC turned off" was fruitless.

I checked the issue with this simple sketch on a NODE - and when I turned the PC off it stopped - but restarted. Not sure why that should happen.

I'll need to check it with the ESP32 to see if the issue is with the ESP32 or the code I'm running.
But the ESP32 code DOES run on a USB wall wart so I dont see it can be a serial comms issue.

   Read pot on "A0" and short flash LED1
   LED is connected to GND via 1k resistor
   the only analog input - A0 is on the opposite side to digital io pins.
   GPIO pins on the same side as A0 can not be used for digital io

#define LED1 16 //D0

const int analogInPin = A0;  // ESP8266 Analog Pin ADC0 = A0
int sensorValue = 0;  // value read from the pot

void setup() {
  pinMode(LED1, OUTPUT);    // LED pin as output.

void loop() {
  sensorValue = analogRead(analogInPin);
  digitalWrite(LED1, HIGH);// turn the LED on.
  delay(sensorValue);     // wait for sensoeValue" msec
  digitalWrite(LED1, LOW); // turn the LED off for 100msec.

@chrisknightley - thanks for the link - I found the button, and the "options" in the drop down. Good to know.

I am inclined to think that the hub is generating some sort of signal that plays with the DTR and RTS signals on the USB interface, putting the ESP into reset and/or programming mode.

1 Like

Hardware problems require a schematic
Software problems require code.

If it runs on a wall wart
It is a hardware problem

Where does the hub get power?

1 Like

Perhaps the PC turning off upsets the DTR/RTS.

Just checked plugged directly into the usb port; Same behaviour - hadnt realised the USB continues to provide power when the PC is "off".

With the ESP32 hardware & sketch (I've added a "flash the LED" to indicate a reset ) I find the system is now doing repeated resets, and never gets the
WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);

IS there something in the arduino code that can trigger a reset?

I havent included the rest of the sketch because with the PC turned OFF it never gets past the "setup"

void setup() {
  pinMode(LED_WiFi, OUTPUT);
  pinMode(LED_Pulse, OUTPUT);
  pinMode(intPin, INPUT_PULLUP);
  digitalWrite(LED_WiFi, 1); //flash blue LED twice to show there has been a reset event
  digitalWrite(LED_WiFi, 0); 
  digitalWrite(LED_WiFi, 1); 
  digitalWrite(LED_WiFi, 0); //ensure blue LED off

  // added in V2.11:  delete old wifi config

  //separate heading from reset diagnostic messages
  Serial.println("Starting Solar Logger");

  //added in V2.11: monitor Wifi connection and handle LED - nb these dont work as is on 8266
  WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);
  WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);

  //  FTP Setup, ensure SPIFFS is started before ftp;
  if (SPIFFS.begin(true)) {
    Serial.println("SPIFFS opened!");
    ftpSrv.begin("esp8266", "esp8266");  //ftp username, password. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);   // Init and get the time
  delay(100); //allow to get NTP time
  while (!getLocalTime(&timeinfo)) {
  currMonth = 1 + timeinfo.tm_mon; //tm_mon gives months since jan so eg April is 03 hence add 1
  currDay = timeinfo.tm_mday; //set current day
  Serial.printf("Setup: -  success getting time. currMonth is %i: currDay is %i \n", currMonth, currDay);
  //currDay = 0; //testing - force new day scenario
  //currMonth = 0; //testing - force new month scenario
  newMonth();  //if no file exists as yet for month data create one; but if there is one dont overwrite it.

  // Handle Web Server
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/html", index_html, processor);

  // Handle Web Server Events
  events.onConnect([](AsyncEventSourceClient * client) {
    if (client->lastId()) {
      Serial.printf("Client reconnected! Last message ID that it got is: %u\n", client->lastId());
    // send event with message "hello!", id current millis and set reconnect delay to 10 second
    client->send("hello!", NULL, millis(), 10000);

  Serial.println("Setup complete \n");

  digitalWrite(LED_WiFi, 1); //flash LED THRICE
  digitalWrite(LED_WiFi, 0); 
  digitalWrite(LED_WiFi, 1); 
  digitalWrite(LED_WiFi, 0); 
  digitalWrite(LED_WiFi, 1); 
  delay(500); //++++++++  add longer delay so flashes are separated
  digitalWrite(LED_WiFi, 0); //ensure blue LED off

I like to use the small OLED I2C displays for projects.
I pepper the Startup with print statements

your blinking lights works similar.

add a THRICE blink after


move it down to other functions as you find it works

How do I get rid of mine? I don't see an option in the "Interface" settings.

A bit tricky, but you use NoScript (IIRC - or is it ABP - yes, it actually use ABP as I am using uBlock Origin, not NoScript) to reject the URL of the said bar (which also has two parts).