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
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)