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
}
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).
You should see messages like “Compiling…” and “Uploading…” at the bottom.
When it finishes, the onboard LED should start blinking once per second.
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
You’ve just taken your first successful step into IoT programming!
In the next post, we’ll explore how to read sensor data and display it using 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!