DEV Community

Cover image for ๐Ÿš€ Uploading Your Code with Arduino IDE
Mohamed Ahmed
Mohamed Ahmed

Posted on

๐Ÿš€ Uploading Your Code with Arduino IDE

Introduction

Welcome back to our IoT journey! ๐Ÿ‘‹
In the previous post
, we installed the Arduino IDE and configured it to recognize our ESP32 board.

Now, itโ€™s time to bring our board to life by uploading our very first program โ€” the classic โ€œBlinkโ€. This small project will make the onboard LED on your ESP32 blink at regular intervals โ€” a simple but exciting sign that everything is working!

๐Ÿงฐ What Youโ€™ll Need

  • Your ESP32 development board (e.g., ESP32 DevKit C)
  • A USB cable (connected to your computer)
  • The Arduino IDE (already configured for ESP32)

โšก Step 1: Open the Arduino IDE

Launch the Arduino IDE on your computer.
Make sure your ESP32 is connected to your PC via USB.

๐Ÿงฉ Step 2: Select the Correct Board and Port

Before writing any code, confirm that youโ€™ve selected your ESP32 board and port correctly:

  • Go to Tools โ†’ Board โ†’ ESP32 Arduino โ†’ ESP32 Dev Module
  • Go to Tools โ†’ Port โ†’ select the one that says something like COM7

_๐Ÿ’ก If no port is visible, you may need to install the USB driver for your board (CH340 or CP210x depending on your model). You can check the chip model next to your USB port.
_

๐Ÿ’ป Step 3: Write the Blink Code

In your Arduino IDE, copy and paste the following code:

// The classic Blink program for ESP32
int ledPin = 2; // Built-in LED on most ESP32 boards is on GPIO 2

void setup() {
  pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
}

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

Enter fullscreen mode Exit fullscreen mode

Explanation:

  • setup() runs once when your board starts.
  • loop() runs continuously, making the LED turn on and off.
  • delay(1000) means 1000 milliseconds (1 second).

โš ๏ธ If the upload fails, try holding the BOOT button on your ESP32 while uploading.

โฌ†๏ธ Step 4: Upload the Code

Now the fun part! ๐ŸŽ‰
Click the Upload button (the right-pointing arrow in the toolbar).

Your IDE should look like this:
You should see messages like โ€œCompilingโ€ฆโ€ and โ€œUploadingโ€ฆโ€ at the bottom.
When it finishes, the onboard LED should start blinking once per second.
ESP32 should look like this
LED not blinking Some boards use different pins for the built-in LED. Try changing int ledPin = 2; to int ledPin = 5; or int ledPin = 13;

๐Ÿ’ก If the LED isnโ€™t blinking, some boards use different pins for the built-in LED. Try changing int ledPin = 2; to int ledPin = 5; or int ledPin = 13;.

๐ŸŽฏ Whatโ€™s Next
In the next post, weโ€™ll take things a step further โ€” moving from the built-in LED to controlling an external LED using wires, resistors, and ESP32 pins โ€” all while monitoring outputs through the Serial Monitor.

Until then โ€” happy tinkering! ๐Ÿ”งโœจ

*Did your LED blink? *๐Ÿ˜„
Share your success (or any errors you faced) in the comments โ€” Iโ€™d love to help you troubleshoot and celebrate your first ESP32 project!

Top comments (0)