0
0
AutocadHow-ToBeginner · 4 min read

How to Program ESP32 Using Arduino IDE: Step-by-Step Guide

To program an ESP32 using the Arduino IDE, first install the ESP32 board support via the Board Manager by adding the ESP32 URL in Preferences. Then select your ESP32 board from the Tools menu and write or upload your Arduino sketches as usual.
📐

Syntax

Programming ESP32 with Arduino IDE uses the same sketch structure as any Arduino board. The main parts are:

  • setup(): Runs once to initialize settings.
  • loop(): Runs repeatedly to perform tasks.
  • pinMode(): Sets a pin as input or output.
  • digitalWrite() and digitalRead(): Control or read digital pins.

You write your code inside these functions and upload it to the ESP32.

arduino
void setup() {
  pinMode(2, OUTPUT); // Set GPIO 2 as output
}

void loop() {
  digitalWrite(2, HIGH); // Turn LED on
  delay(1000);          // Wait 1 second
  digitalWrite(2, LOW);  // Turn LED off
  delay(1000);          // Wait 1 second
}
💻

Example

This example blinks the onboard LED of the ESP32 every second. It shows how to set a pin as output and toggle it on and off.

arduino
void setup() {
  pinMode(2, OUTPUT); // Onboard LED pin on many ESP32 boards
}

void loop() {
  digitalWrite(2, HIGH); // LED on
  delay(1000);           // Wait 1 second
  digitalWrite(2, LOW);  // LED off
  delay(1000);           // Wait 1 second
}
Output
The onboard LED blinks on and off every second.
⚠️

Common Pitfalls

  • Not installing ESP32 board support: You must add the ESP32 URL in Arduino IDE Preferences and install the board via Board Manager.
  • Wrong board selected: Choose the correct ESP32 model under Tools > Board to avoid upload errors.
  • Incorrect COM port: Select the right port where ESP32 is connected.
  • Pin differences: ESP32 pins differ from Arduino Uno; check your board's pinout before coding.
arduino
/* Wrong way: Using Arduino Uno board selected */
// This causes upload failure or wrong behavior

/* Right way: Select ESP32 board in Tools > Board */
// Then upload the sketch normally
📊

Quick Reference

Here is a quick checklist to program ESP32 with Arduino IDE:

  • Add https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json to Arduino IDE Preferences under Additional Board URLs.
  • Open Tools > Board > Board Manager, search for ESP32, and install.
  • Select your ESP32 board from Tools > Board.
  • Choose the correct COM port under Tools > Port.
  • Write your sketch using setup() and loop().
  • Click Upload to program the ESP32.

Key Takeaways

Install ESP32 board support via Arduino IDE Board Manager before programming.
Always select the correct ESP32 board and COM port in Arduino IDE.
Use the standard Arduino sketch structure with setup() and loop() functions.
Check ESP32 pinout as it differs from Arduino Uno to avoid hardware mistakes.
Upload your code normally once setup is complete to program the ESP32.