[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header

Learn how to fix the Fatal Error Occurred: “Failed to connect to ESP32: Timed out waiting for packet header” error when trying to upload new code to your ESP32 board once for all.

[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header

Why are you getting this error?

Some ESP32 development boards (read Best ESP32 boards) don’t go into flashing/uploading mode automatically when uploading a new code.

This means that when you try to upload a new sketch to your ESP32, the Arduino IDE fails to connect to your board, and you get the following error message:

Holding the BOOT/FLASH button

One of the ways to solve this is holding-down the “BOOT/FLASH” button in your ESP32 board while uploading a new sketch at the same time. But having to worry about this every time you want to upload new code can be tedious, specially when you’re testing and debugging your code. There is a way to fix this once for all – no need to hold down the “BOOT/FLASH” button anymore.

How to fix the Error?

To make your ESP32 board go into flashing/uploading mode automatically, you can connect a 10 uF electrolytic capacitor between the EN pin and GND.

You may want to test this setup first on a breadboard to make sure it works for your ESP32 development board.

Note: electrolytic capacitors have polarity. The white/grey stripe indicates the negative lead.

If it works, then you can solder the 10 uF electrolytic capacitor to the board. Since the EN and GND pins are far apart from each other, you can simply connect the capacitor between the EN and the GND of the ESP32 chip as shown in the schematic diagram below:

Recommended: ESP32 Pinout Reference: Which GPIO pins should you use?

The following figure shows how my ESP32 looks like after soldering the capacitor. It doesn’t occupy much space, and fortunately you won’t get more trouble connecting to the ESP32 when uploading new code.

Before trying to upload a new code, you should check the connections with a multimeter in continuity mode – check that you haven’t inadvertently solder anything to the next pin.

fix timed out waiting for packet header with capacitor testing

If everything is soldered properly, you won’t need to press the BOOT button when uploading new code. You also won’t get the Fatal Error Occurred: “Failed to connect to ESP32: Timed out waiting for packet header”.

Wrapping Up

We hope you’ve found this trick useful and it solved your problem. Thanks to Ben Hall for the suggestion.

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our weekly newsletter!

87 thoughts on “[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header”

  1. I wonder what would occur if I used a 100uf Capacitor instead of the 10uf one as recommended in the post above? Would it hurt the ESP board?

  2. I have an ESP32 with this problem. I have added the capacitor as described in the article. Now the upload start automatically, but the software does not start. I I press the reset I obtain the following message
    waiting for download

    the only way to start the program is to switch off and the switch on again the esp32.
    Any Idea?

  3. I have resolved the problem in my previous post by adding a resistor of one 1kohm between the pin EN and the 3v.
    Now the upload runs automatically and the reset maintain its function.

  4. I would like to add that in some cases, with some esp32 I must add a 47 uF capacitor + resistence of 1Kohm for resolving the problem.

  5. Muito Obrigado pelo excelente post, me ajudou e muito e tenho certeza que vai ajudar muitas outras pessoas. “Compartilhar conhecimento só enriqueci o nosso saber”

  6. Hello, thanks for the info.

    I have the same problem, but the device I’m using is ESP-32 CAM, so the pinouts are different from the original ESP-32. Do you have a solution for this? Thanks again in advance.

  7. I have a Lolin D32 board which was giving this error. It has only one button(Reset). I put the capacitor like suggested above but the error was persistent. As a last ditch effort I used a jumper on GPIO0 to GND during compile and upload(I use Arduino IDE). Now the code is uploaded without a problem. I remove this jumper and the board functions as programmed.

    • Hi.
      Thank you for sharing your solution. It will certainly be useful for other readers that use the Lolin D32 board.

  8. Thank you for the article. I have exactly the same board as in your pictures. It was enough to use 2.5 uF and no resistor was needed. However I didn’t like the metal can of the capacitor so close to the antenna. An alternative location is negative to the pin of the AMS1117 that is closest to the USB connector, positive to the middle pin of the transistor closest to D2. And of course if project allows, the capacitor can be applied on the underlying project PCB.

  9. Many thanks, it worked!
    Is this for esp8266 or is it just in case of this error in esp32? Well, I noticed that the sketch loads faster.

  10. Hi,
    I’m getting error “Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch”
    its a Webcam ESP32s.
    I’ve been able to connect to “factory setting AP” and test the camera and wifi ok but doesn’t matter what I try I can get it to upload a new sketch. I have two and one works as expected but the other is a no go.
    Would try to add a 10 uF electrolytic capacitor but the pinout on the Webcam ESP32 is different from the image shown above. Do you have the EN pin placement for Webcam ESP 32?

    Any ideas?

      • Hi Sarah thanks for the reply but I had followed all the troubleshooting elements of the guidelines. I have one esp32 webcam that works so i know my setup is correct.
        My real question was: were is EN pin on the esp32 webcam so I could try the capacitor fix. The esp32 in that example was not a webcam version.

  11. Thanks for posting the solution. I had been using the ESP32 on my Windows 10 desktop with no issues uploading. Wanted to move over to my MAC Laptop. First issue was the lack of USB driver on the MAC. Found info on that, but then it kept failing to connect – timing out. I assumed it was still an issue with the USB Port / Driver, till I saw your comment about holding down the Boot button throughout the upload process. Worked perfectly. Thank you.

  12. Hey Sara Santos!
    I pulled up EN to 3v3 with a 10K ohm resistor and a switch to ground it while uploading.
    I Pulled up IO0 to 3.3V using a 10K ohm resistor and A button switch to pull it down to GND while uploading the code.
    The Tx and Rx are also correctly connected to the FTDI programmer(PS. I’m using the same 3.3V- 5V programmer that I use for Esp8266).
    And still I am receiving this error. I have even tried attaching capacitor between the EN pin and the gnd. Still the code is just not flashing.
    It flashed once and I was able to blink a LED, but after that the device is just not flashing the code.!
    Please suggest a solution 🙂

    “”Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header””

  13. I am trying to connect with Custom ESP32 Board, Here I have used USB to UART converter for programming the ESP32. While programing first time it showed the timed out and waiting for packet header After I used 10uF capacitor across EN and Ground pin first time it’s programmed fine, Next time I tried to program its showes the same error.

    I don’t know how to resolve this.

    • Hi Rick.
      Yes, It think it should work.
      I recommend testing the circuit on a breadboard first to make sure it works, and only then solder the capacitor to your board.

      • Hi, Sara.

        Thanks for really quick reply!

        I just tried it. The cap slows the connection operation a few seconds, but once it connects it still gives the timeout error. My esp32 has a lot of serial activity going on – GPS, OLED, LoRa, SD Card – which I think challenges the USB flashing.

        On another note, I’m using Windows 10, which has the irritating habit of frequently causing the serial port to lose my esptool script, forcing me to restart the PC. Ever see that issue?


        • Hi Rick.
          The timeout error means that the ESP is not in flashing mode (to receive the code).
          Usually, the solution is to press the BOOT button when you start seeing the dots appearing on the serial monitor.
          In the board you’re using, I think it is the PRG button you need to press when you see the dots.
          Pressing the PRG button solves the problem?
          Unfortunately, I don’t have a board like that to experiment.

          I usually don’t have problems with the serial port. But sometimes if your ESP32 needs a lot of current to operate (like you have), your usb port might not provide enough power and some “strange” things can happen like disconnecting from your computer and having to restart.


      • Hi, Sara.
        I found the flashing worked when I temporarily removed one of the peripheral device that was drawing power through the ESP32_LoRa chip. After flashing I reconnected it, and everything is working great. Thanks, again!

  14. I have resolved the problem.
    In my case, there is a jumper (on the FTDI programmer) which sets the output to be 3.3V or 5V.
    It should go along with the power supply pin you use on the ESP32 (3.3V or 5V pin).
    Hope this helps.

  15. I found my problem was with the USB port on my laptop. If I use a USB 3.0 cable (USB-A -> USB 3) in the USB 2.0 port, I get the exact error messages above. When I moved the cable to the USB 3.0 port it worked just fine. I didn’t realize my laptop had a single 2.0 port which is the one I naturally use due to it’s location. As I understand, it should have worked with the USB 2.0 port, but it does not on my laptop either due to the cable or the port. Hope this helps someone.

  16. I just bought an esp32 , and I am a beginner .
    when I upload the blink , this failed message comes, please help me

    A fatal error occurred: failed to connect to ESP32: timee out waiting for packet header

    • Hi.
      I recommend following the suggestion in this article.
      Also, you may need to reduce the upload rate in your Arduino IDE in Tools > Upoload Speed.
      I hope this helps.

  17. For me with the 10uF the ESP32 did not start the program after the download.
    With a 1uF the ESP32 starts the program automatically after the download.

    Checking the board, it looks like the CP2102 (USB to Serial) is not an original one, as it has no label on it.

    On another ESP32 (Which is working normaly) the CP2102 has a label printed on top.

    • Hi:
      I am using a LOLIN D1 Mini. After several successful uploadings I suddenly got this error; however this board does not have an EN Pin and it only has a RST .

      Do you have any suggestion to correct the problem?
      Thanks in advance, Gerardo

  18. I note that Expressif recommends to load the En line with a 100nF cap if you have programming “connecting” problems
    I had the same problem on a NodeMCU-32s.

    The nice part is that the En line is right next to the 3.3V line and at AC all power pins are the same so connecting a cap to the 3.3V line or Gnd will provide the same filtering (assuming this cap provides noise filtering or slew limiting). I used a 0805 100nF MLCC which just fit between the 0.1″ spaced pins 1 and 2 (En and 3.3V) on the top of the NodeMCU. Now it programmes perfectly.

    A large cap caused me problems with reset after programming but this smaller cap works fine.

  19. Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    Soldered the capacitor to EN and GND.
    Tried this thing as well: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
    not working.
    I’m using ESP32 CAM AI-Thinker
    5V, tested ever single connections with volt meter. Everything works fine.
    Tried all possible ways.
    Watched like 3 hours of youtube.
    Doesn’t fix the problem. Any suggestions? I would really appretiate that.

  20. First of all – thank you for sharing this solution.
    I recently bought two ESP32-boards from OLIMEX and had problems uploading. It was very strange, since it worked the first time, but never again ??? After googling around for quite some time, I found your solution.
    DanKoloff from Olimex gave me some tips too, but it was a capacitor at EN that helped. From curiosity I tested different caps, diffent resistors and the two Olimex-boards plus a AZ-delivery ESP32-Dev which I had bought the week before.
    You can find the table of my tests at
    Regards, Karl

    • Hi Karl.
      I’m glad you solved your problem and thanks for sharing that table. It may be useful for many of our readers.

  21. Hi Sara,
    I was not really satisfied with this solution. Also I noticed, that the RST-button did not always work. Shortly I heard of power-monitoring ICs for the gereation of a clean reset.
    So I ordered a few TPS3809K33 (SMD) and a few MCP102-300 (for breadboard tests). The ESP32-PoE from Olimex has a RST-button from EN to GND. Since the MCP102 has an open collector output, you can connect it directly to ESP_EN (pin4 on EXTERN1). But if you use the TPS3809 (it has a push-pull output), I suggest a resistor in between the output of the IC and EN. I use 4k7 since it only draws current while RST is pressed.
    For me this is the best solution, since it is not dependent on the time constant and now even the RST-button works flawlessly. Now I can upload code and use the RST-button.
    Regards, Karl

  22. Hey guys,

    I admit I’ve never encountered this problem before. The board I’ve been using so far seems to be free of this malfunction… But since I unpacked 3 other identical boards (that I bought at the same place), I’m now facing the problem.

    For those who are interested, here are the boards I use:


    I guess I can compile my projects with the DoIt ESP32 DevKit v1 model. Anyway, that’s what I’ve been doing since the beginning, and it works. If you think it’s not the most appropriate model for compiling, don’t hesitate to let me know!

    I’ve tried by all means to solve the problem with software, but without success. And I stumbled upon a post on the forum with the reference to this article… A providential chance!

    The solution is simple and efficient. Nevertheless, I have a small question: why 10 µF? How did you choose this value? In an empirical way, or is there a logical explanation for that?

    In any case, a big thank you… I can finally stop pulling my hair out on this thing that was driving me crazy.

    All the best,

      • Indeed, as far as I’m concerned, my boards are very widespread, and they are very similar to Rui and Sara’s favorite boards… so it’s easier to find a solution.

        On the other hand, thanks for the info about the MCP102, it’s good to know!

        Thanks Karl!

  23. Very handy little trick. I was suffering with this error for a while, but thanks to you i can use my boards just fine 🙂

  24. I own a TTGO LoRa Esp32 v2 and I am struggling to upload the new code (.bin). I treat it with really care, I was uploading and testing some codes and suddenly, it stop allowing me to upload new programs.

    I have tried many different things and combinations of all of them:

    usb ports
    usb wires
    2 linux
    arduino ide
    pressing the RST button (it doesn’t have boot)
    changing the baud rate (upload speed)
    changing the flash freq
    changing the board type (TTGO Lora32 v1, v2, Heltec…)

    And I get always this:

    python /home/user/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py –chip esp32 –port /dev/ttyUSB0 –baud 115200 –before default_reset –after hard_reset write_flash -z –flash_mode dio –flash_freq 80m –flash_size detect 0xe000 /home/user/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/partitions/boot_app0.bin 0x1000 /home/user/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/sdk/bin/bootloader_dio_80m.bin 0x10000 /tmp/arduino_build_119083/WiFiScan.ino.bin 0x8000 /tmp/arduino_build_119083/WiFiScan.ino.partitions.bin
    esptool.py v2.6
    Serial port /dev/ttyUSB0
    Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch
    Failed to connect to ESP32: Timed out waiting for packet header

    The weird thing is that I achieved loading sample programs like OLEDHelloWorld and it is working (showing that program in the OLED), but I cannot boot/upload any other program since that happened (yesterday).

    Any idea?

  25. I faced the same problem, after adding 10uF capacitor it still could not work.
    Finally, I found that problem caused by myself, I connected TX0 RX0 pin to RS485 transceiever. After moved the transceiver to UART2 the problem gone.

  26. I am using a DOIT ESP32 WROOM-32D board and facing same issue. Adding a 10uF capacitor solves the sketch loading problem but the board needs to be manually reset every time.

  27. Hi Sara
    On the RPi /Node red side everything seems fine, with mqtt nodes showing connected.

    Then, to download the code, I tried a several ESPs, using a capacitor etc and nothing worked. Finally I found that I had an ESP 12F, tried this, and amazingly it uploaded. However, when I went to do the test as you suggested (before building the DHT circuit) the message I get I failed to get an MQTT connection.
    My router says that I have an IP address for the ESP12F,
    If you have any suggestions why I can’t connected to the MQTT on RPI – that would be much appreciated. I put the correct address of my RPi in the code and included the 1883 port in the address. So frustrating when you get so close.

  28. Hello,

    I have the AI Thinker module of ESP32-CAM. My problem is similar but at a later stage. When I upload the sketch, it can connect and start writing, however at the end it fails with the same error as above. Here is the output:
    esptool.py v2.6
    Serial port /dev/ttyUSB0
    Chip is ESP32D0WDQ5 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: f0:08:d1:76:94:38
    Uploading stub…
    Running stub…
    Stub running…
    Changing baud rate to 460800
    Configuring flash size…
    Warning: Could not auto-detect Flash size (FlashID=0x0, SizeID=0x0), defaulting to 4MB
    Compressed 8192 bytes to 47…
    Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 4217.0 kbit/s)…

    A fatal error occurred: Timed out waiting for packet header
    A fatal error occurred: Timed out waiting for packet header

  29. Hi, I put 10 uF electr. (smd) cap.
    It was not working.
    Then i put an 1k resistor (THT) between rst and 3v3
    It was not working.
    Then take the resistor and now it is working 😀 😀 (cap. is still soldered)
    I really do not understand yet, but maybe this can help sy else too.


Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.