ESP8266-01 automatic upload and run (without manually toggle GPIO0 to GND)
ESP8266 boards that have at least 1MB of flash (for the ESP-01, usually indicated by a black PCB) support Over-The-Air updates, which happen to be natively supported by the Arduino IDE! The example in Arduino OTA > BasicOTA has the following basic code:


#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266mDNS.h&gt;
#include &lt;WiFiUdp.h&gt;
#include &lt;ArduinoOTA.h&gt;

const char* ssid = "..........";
const char* password = "..........";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
  // ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ArduinoOTA.handle();
}


By changing the commented code // ArduinoOTA.setPassword((const char *)"123");, you can set a password. If you merge this code with your existing code, instead of selecting the ESP8266's serial port when programming, your ESP8266 will show up in the "Ports" menu. You will be prompted for a password if you set one. Then, just click "Upload" like normal. After the upload is complete, the ESP8266 will automatically restart and execute your new code. You don't connect GPIO 0 to a special mode when programming, just leave it in its normal position.