Search
Close this search box.

Home

How to Program ESP32 with Arduino IDE?

In this tutorial, we will learn how to install ESP32 Board in Arduino IDE and also how to program ESP32 with Arduino IDE. This tutorial is applicable for all the major Operating Systems like Windows, macOS and Linux as long as you have Arduino IDE installed. So, let’s get started.

Getting-Started-with-ESP32

NOTE: This is not an Introduction to ESP32. I made a dedicated Getting Started with ESP32 tutorial. If you are a beginner, please read that tutorial first before proceeding with this Programming ESP32 with Arduino IDE tutorial.

Have you Installed Arduino IDE?

The first thing you need is the Arduino IDE. If your computer doesn’t have Arduino IDE installed, then visit the official Arduino download page and download the installation file for your preferred operating system.

ESP32-Arduino-IDE-1

If you have already installed Arduino IDE, then make sure that it is up to data.

Preparing Arduino IDE

Open the Arduino IDE and go to File -> Preferences option.

ESP32-Arduino-IDE-2

A new window pops up. Near the end, there is an option called “Additional Boards Manager URLs”. In the space next to this option, paste the following URL and click on OK.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

ESP32-Arduino-IDE-3

NOTE: You can add multiple URLs by separating with commas.

Arduino IDE will now look for additional boards (other than that are already installed) from the above URL.

Installing ESP32 Board in Arduino IDE

After adding the URL, you are now ready to install the ESP32 boards in Arduino IDE. Go to Tools -> Board -> Boards Manager. . . option. A Boards Manager window will pop-up.

ESP32-Arduino-IDE-4

In the search bar on the top, type “esp32” and hit enter. You will get a result saying “esp32 by Espressif Systems”. Select this and click on install button. Arduino IDE will now download all the necessary files for ESP32 like boards, tools, programmer etc., from the internet.

ESP32-Arduino-IDE-5

Make sure your computer has internet connectivity. This might take a minute or two. Once the installation is successful, you can close the Boards Manager.

Selecting ESP32 Development Board

Now, in order to write programs for ESP32 boards, you have to first select the right board (the board which you have). To do this, once again go to Tools -> Board. You can see a new option called ESP32 Arduino added to the list of boards.

ESP32-Arduino-IDE-6

Hover over ESP32 Arduino and a list of ESP32 Board supported by Arduino IDE will appear. As I have a generic ESP32 DevKit, I selected ESP32 Dev Module. This board is applicable for most of the generic 30-pin ESP32 boards available today.

In case you have a different board from a different manufacturer like SparkFun or WEMOS, select the appropriate board.

Now, once again go to Tools menu and you can see the board options are changed and are now specific to ESP32 Board you selected. Do not change / modify any options as of now. I will specify the required changes whenever necessary.

ESP32-Arduino-IDE-7

Your First ESP32 Program

To demonstrate the working of ESP32 Arduino IDE installation, let us write a small program to, well, as you guessed, Blink an LED. My ESP32 Development Board has one user LED on-board and is connected to GPIO2 of ESP32.

ESP32-LED-Blink

If you have a generic 30-pin ESP32 Board, then chances are, your board will also have the LED connected to same GPIO. If your board doesn’t have any on-board LED, then you can still use the following program by connecting a 5mm LED to GPIO2 (marked as D2 on the board) using a 220 Ω current limiting resistor.

There isn’t much to explain regarding the code as all we are doing is Blinking an LED.

Programming ESP32 with Arduino IDE

Now is the moment of truth. Connect a micro-USB cable to the ESP32 board and plug in the other end to a USB port on your computer. If your computer is running Windows 10 and is up to date, then you will not have any driver issues with respect to the CP2102 USB to UART Bridge.

Troubleshooting Tip

But if your computer couldn’t identify the device, then you have to install the Virtual COM Port Drivers from the official website of CP2102 (manufacturer is Silicon Labs). You can visit this link and download the appropriate driver for your operating system.

If the device is recognized by Windows, then it will be assigned a COM port. In Windows OS, go to Device Manager and get the correct COM Port number.

CP2102-COM-Port

Now go to Tools menu in Arduino IDE and select the COM Port of ESP32. In my case, it was COM4.

ESP32-COM-Port

Type the code in Arduino IDE (or copy from above) and click on Upload button. If every thing goes well, then the Board itself will automatically put ESP32 in Programming Mode, upload the code to the on-board flash memory and also reset the microcontroller to normal mode.

ESP32-Arduino-IDE-8

You can see the LED Blinking.

ESP32-LED-Blink-GIF

Common Problems

The first problem with ESP32 Board which you might face is related to the CP2102 USB to UART Bridge Drivers. I already gave the link to download drivers.

Another problem is not putting the ESP32 in programming mode while uploading the code. Close the Serial Monitor (if it is open) and click and hold the BOOT button on the ESP32 board while clicking on the Upload button on Arduino IDE.

Once it identifies the chip, you can release the BOOT button and the code will be uploaded. To reset the microcontroller, press the EN button once.

Conclusion

A complete tutorial on Programming ESP32 with Arduino IDE. You learned how to install ESP32 Board in Arduino IDE, write your first program for ESP32 and upload the program.

4 Responses

  1. Just purchased the ESP32. Trying the Blink sketch. I do get an output/flash from GPIO2 but not on the onboard LED. The only thing different is I can’t find JUST ESP32 in the library select menu. I do have the “preference” string as you show. I did remove _dev_ from mine. I tried just “LED_BUILTIN” and the IDE didn’t like it. Not defined.

    Retired, vet, just trying to stay out of the bars….LOL

    Kindly, Suggestions?

    1. Sorry for the chatter, found ESP32 in Board Manager but the onboard LED still does not flash. I even tried using my second board.

      1. Hi, if you have the same board as I have, the ledPin should be 1, not 2 (it works for me if I change the number in the first line). You can also try the “AsciiTable” example from the Arduino examples.. but in all cases I always had to press the “Boot” button for the upload to actually work…

Leave a Reply

Your email address will not be published. Required fields are marked *