ESP32: A Guide to Connecting and Controlling the Onboard LED

Introduction:

Greetings, fellow tech enthusiasts and LED aficionados! Today, we’re going to embark on a whimsical journey to the land of ESP32, where we’ll learn how to connect to this magical microcontroller and light up its onboard LED. So, grab your favorite beverage, put on your thinking cap, and let’s dive into the world of ESP32 with a twinkle in our eye and a sparkle in our step!
Step 1: Gather Your Tools and Components
Before we can start our LED-lighting extravaganza, we’ll need to gather some essential tools and components. Here’s what you’ll need:

 

  • An ESP32 development board (our shining protagonist)
  • A micro-USB cable (the trusty sidekick)
  • A computer with a USB port (the command center)
  • Arduino IDE (the magical software that brings our story to life)

Install the Arduino IDE

To communicate with our ESP32 hero, we’ll need the Arduino IDE. If you haven’t already installed it, head over to the Arduino website (https://www.arduino.cc/en/software) and download the latest version for your operating system. Follow the installation instructions, and soon you’ll have the power of Arduino at your fingertips!

 

Configure the Arduino IDE for ESP32

Now that we have the Arduino IDE installed, we need to teach it the ancient art of ESP32 communication. To do this, follow these steps:

Open the Arduino IDE and navigate to File > Preferences.

 

 

In the “Additional Boards Manager URLs” field, add the following URL: https://dl.espressif.com/dl/package_esp32_index.json (If you have more than one, they can be separated by a comma)

 

 

 

 

 

Click “OK” to save your changes and the AGAIN “OK”.

Next, go to Tools > Board > Boards Manager.

 

 

In the search bar, type “ESP32” and hit Enter.

Find the “esp32” entry by Espressif Systems and click “Install.”

 

 

Congratulations! Your Arduino IDE is now fluent in ESP32-ese.

Connect the ESP32 to Your Computer

It’s time to introduce our ESP32 hero to its command center. Grab your micro-USB cable and connect one end to the ESP32 development board and the other end to your computer’s USB port.

Problems with the connection? If not, move a long.

Maybe there isn´t a valid Driver for the board…go to the device manager and check it out. ([WIN key + r] and write devmgmt.msc)-This is one of the ways.

 

 

  • You can download the CP2104 USB to UART Driver  for Windows 10 + Windows 11 and unzip it to a folder. Then just update the driver by going to the place in your computer were the unzipped folder is.

 

 

 

  • All done!

Upload the LED-Blinking Sketch

With our ESP32 connected and ready to go, it’s time to upload the LED-blinking sketch that will bring light to our lives. Follow these steps:
  • In the Arduino IDE, go to File > New to create a new sketch.
  • Copy and paste the following code into the sketch:

 

const int ledPin = 2; // Onboard LED is connected to GPIO2

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

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

 

Go to Tools > Board and select “ESP32 Dev Module” from the list.

 

 

  • Go to Tools > Port and select the appropriate port for your ESP32.
  • In my case, before the upload i have a extra step that is to put the ESP32 in programming mode by Pressing first the BOOT and next the EN button. The serial monitor will give us the following message and we will be ready to download.

 

 

Click the “Upload” button (the right-facing arrow) to compile and upload the sketch to your ESP32. After the download,  Press the EN button for jumpstart he board. The onboard LED should start blinking.

 

 

Bask in the Glory of Your Blinking LED

If all went according to plan, your ESP32’s onboard LED should now be blinking on and off like a beacon of hope in a sea of darkness. Take a moment to bask in the glory of your accomplishment and let the soothing rhythm of the blinking LED wash over you.

Conclusion

And there you have it, folks! You’ve successfully connected to an ESP32, uploaded a sketch, and lit up the onboard LED. Give yourself a pat on the back and a hearty chuckle, for you’ve just taken your first steps into the enchanting world of ESP32. Who knows what other illuminating adventures await you on this journey? Only time (and more blog posts) will tell!