// Define the GPIO pins for your LEDs
// You can change these to any suitable digital GPIO pin on your ESP32 board.
// Avoid pins used for specific functions like TX/RX (GPIO1, GPIO3) or strapping pins during boot.
// Common safe choices for output are GPIO 2, 4, 12-19, 21-23, 25-27, 32-33.
const int ledPin1 = 16; // Example: Connecting the first LED to ESP32's GPIO 16
const int ledPin2 = 17; // Example: Connecting the second LED to ESP32's GPIO 17
// Define the blink interval (in milliseconds)
// This controls how long each LED stays on/off before switching.
// 1000 milliseconds = 1 second
const long blinkInterval = 1000;
void setup() {
// Initialize the serial communication for debugging (optional but recommended)
// This allows you to print messages to the Serial Monitor in the Arduino IDE.
Serial.begin(115200);
Serial.println("ESP32 Two LED Blink Program Started!");
// Set the LED pins as OUTPUTs
// This tells the ESP32 that we will be controlling the voltage on these pins.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// Initial state: Ensure both LEDs are off when the program starts.
digitalWrite(ledPin1, LOW); // LOW means 0V (LED off)
digitalWrite(ledPin2, LOW); // LOW means 0V (LED off)
}
void loop() {
// First state: Turn LED1 ON, and LED2 OFF
Serial.println("LED1 ON, LED2 OFF");
digitalWrite(ledPin1, HIGH); // HIGH means 3.3V (LED on for ESP32)
digitalWrite(ledPin2, LOW); // LOW means 0V (LED off)
delay(blinkInterval); // Pause for the defined interval
// Second state: Turn LED1 OFF, and LED2 ON
Serial.println("LED1 OFF, LED2 ON");
digitalWrite(ledPin1, LOW); // LOW means 0V (LED off)
digitalWrite(ledPin2, HIGH); // HIGH means 3.3V (LED on)
delay(blinkInterval); // Pause for the defined interval
// The loop() function will repeat these two states indefinitely,
// creating the continuous alternating blink pattern.
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4