Step 4: Upload Your First Program
Now that your ESP32 is connected, let's upload a test program to make sure everything is working.
The Blink Example
We'll use the classic "Blink" example, but modified for the ESP32's onboard LED.
Open the Blink Example
- Open the Arduino IDE
- Go to File > Examples > 01.Basics > Blink
Modify the Code for ESP32
The ESP32's onboard LED is typically connected to GPIO 2. Replace the code in the Blink example with:
void setup() {
pinMode(2, OUTPUT); // Initialize digital pin 2 as an output
}
void loop() {
digitalWrite(2, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(2, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}
Upload the Code
- Click the Upload button (right-facing arrow in the top left)
- Wait for the upload to complete
- You should see messages in the console at the bottom:
- "Compiling sketch..."
- "Uploading..."
- "Done uploading."
Verify the Blink
After the upload is complete:
- Look at your ESP32 board
- You should see a small blue LED blinking
- It will turn on for 1 second, then off for 1 second, repeatedly
Troubleshooting
If the LED doesn't blink:
Check the LED Pin
- Some ESP32 boards have the onboard LED on a different pin
- Common alternatives: GPIO 5, GPIO 16, or GPIO 22
- Try changing
pinMode(2, OUTPUT)to use a different pin number
Check Upload Settings
- Verify Tools > Board is set to "ESP32 Dev Module" (or "DOIT ESP32 DEVKIT V1")
- Verify Tools > Port is set to the correct COM port
- Verify Tools > Upload Speed is set to "921600" (or try "115200")
Check Physical Connection
- Make sure the USB cable is firmly connected
- Try a different USB port on your computer
- Try a different USB cable if available
Success!
If the LED is blinking, congratulations! Your setup is complete and working correctly.
What's Next?
Now that you've verified your setup:
- Explore the components - Check out the Components Reference
- Try a tutorial - Start with something simple like Push Button
- Experiment - Modify the blink code to change the timing or pattern
Remember to save your sketches regularly and have fun exploring!