ESPHow ToIoT HardwaresTutorials/DIY

ArduinoOTA ESP32: Wireless Update from the Arduino IDE

Introduction

Updating firmware on the ESP32 using a USB cable can be inconvenient, especially if your ESP32 board is deployed in a hard-to-reach location. This is where ArduinoOTA (Over-The-Air) updates come in handy. Using ArduinoOTA, you can wirelessly upload new code to your ESP32 without a physical connection, making development and maintenance much easier.

This guide will walk you through setting up ArduinoOTA for your ESP32 board using the Arduino IDE for seamless wireless updates.

What is ArduinoOTA?

ArduinoOTA is a library that enables wireless code updates for ESP32 and ESP8266 boards. It establishes a Wi-Fi connection between the development environment (Arduino IDE) and the ESP32, allowing firmware updates over the air.

Key Benefits of ArduinoOTA:

  • Wireless Firmware Updates: No physical USB connection needed.
  • Remote Deployment: Perfect for devices installed in hard-to-access areas.
  • Time-Saving: Faster and more convenient than manual USB uploads.
  • Stable and Secure: Supports password protection for secure firmware deployment.

Requirements

Before you proceed, ensure you have the following:

  • ESP32 Development Board
  • Arduino IDE (Latest Version)
  • ESP32 Board Package installed in Arduino IDE
  • Stable Wi-Fi Network

Step 1: Install ArduinoOTA Library

The ArduinoOTA library is included in the ESP32 core package. If you haven’t installed the ESP32 board package yet:

  1. Open Arduino IDE.
  2. Go to File → Preferences.
  3. In the “Additional Board Manager URLs” field, add:
https://dl.espressif.com/dl/package_esp32_index.json
  1. Go to Tools → Board → Board Manager.
  2. Search for ESP32 and click Install.

Step 2: ArduinoOTA Code for ESP32

Now, create a new sketch in Arduino IDE and add the following code for OTA updates:

C
#include <WiFi.h>
#include <ArduinoOTA.h>

// Wi-Fi Credentials
const char* ssid = "YOUR_SSID";      // Replace with your Wi-Fi SSID
const char* password = "YOUR_PASSWORD"; // Replace with your Wi-Fi password

void setup() {
    // Start Serial Monitor
    Serial.begin(115200);

    // Connect to Wi-Fi
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nWiFi Connected");

    // Initialize ArduinoOTA
    ArduinoOTA.setHostname("ESP32_OTA_Device");

    ArduinoOTA.onStart([]() {
        String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
        Serial.println("Start updating " + type);
    });

    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 for OTA Updates");
}

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

Step 3: Upload the Code via USB

  1. Connect your ESP32 to your PC via USB.
  2. In Arduino IDE, go to Tools → Board and select ESP32 Dev Module.
  3. In Tools → Port, select the appropriate COM port for your ESP32.
  4. Upload the sketch via USB to initially program your ESP32 with OTA support.

Step 4: Wireless OTA Update Setup

Once your ESP32 has the OTA firmware:

  1. Disconnect the USB cable.
  2. Restart your ESP32 — it will now connect to Wi-Fi and await OTA updates.
  3. In Arduino IDE, go to Tools → Port, and you should see a new network port named “ESP32_OTA_Device”.
  4. Select this network port.
  5. Now you can wirelessly upload new code changes without physically reconnecting the ESP32 to your computer.

Step 5: Testing OTA Firmware Update

To test OTA updates:

  1. Modify your sketch slightly (e.g., add a new Serial.print() message in loop()).
  2. Select the “ESP32_OTA_Device” network port from the Tools → Port menu.
  3. Click the Upload button — your code will upload wirelessly.
  4. Monitor the changes in the Serial Monitor.

Step 6: Adding OTA Security (Optional but Recommended)

To enhance security during OTA updates, add password protection:

ArduinoOTA.setPassword("your_OTA_password");

This will prompt for a password each time you upload firmware via OTA, ensuring better security for your ESP32 device.

Step 7: Troubleshooting Common Issues

If you face issues during the OTA update process:

  • No Network Port Visible: Ensure your ESP32 and computer are on the same Wi-Fi network.
  • ESP32 Not Responding: Check that ArduinoOTA.handle() is present inside the loop().
  • Update Fails at 0% Progress: Verify your ESP32 has sufficient free memory for OTA updates.
  • Authentication Errors: Double-check your OTA password if enabled.

Conclusion

Using ArduinoOTA with ESP32 is a powerful way to streamline firmware updates wirelessly. By enabling OTA updates, you can improve your workflow, reduce development time, and manage devices deployed in remote areas more efficiently.

If you have any questions, feel free to ask in the comments.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin