Project 1 : Getting Started with the ESP32 — LED Blink

Gresya Leman
9 min readFeb 1, 2022

Hello everyone!
Welcome to my first step in my journey on learning how to use ESP32.
In this first chapter, here’s a little tutorial to show you how I made the built-in LED light on ESP32 to blink step by step.

STEP 1 : Require all of the necessary components

ESP32
In this project I used ESP32 DevKit V1, but you can use any kind of ESP32.

ESP32 DevKit V1

Micro USB Cable
This cable will be used as a connector between our device and the ESP32.

Micro USB Cable

Laptop/PC
Use the device of your choice, in this project I used my laptop which is Asus TUF Gaming A15.

Laptop

STEP 2 : Set up Laptop/PC and ESP32

Arduino IDE
Download the Arduino IDE through this link : https://www.arduino.cc/en/software and make sure to download the right one according to the operating system that you’re using in your device (Windows/Mac OS/Linux). In this project I used Windows 10, so I downloaded the ‘Arduino IDE for Windows 7 and newer’ version.

Run the program, then on the top of the program, click on the File > Preferences.

A new window will show up and look for Additional Boards Manager URLs. Fill that field with this link : https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json and then click Ok.

After clicking Ok, you will be directed back to the main program.

ESP32 module on Arduino IDE
On the top of Arduino IDE program, click on the Tools > Board > Board Manager.

On the new window, go to the search bar and type in ‘ESP32’.

Click on the install button and wait for it until it finishes installing. Then click ‘Close’ to close the window.

You will be directed back to the main program, then click Tools > Board > ESP32 Arduino > (choose the ESP32 that you’re using). In this project, since I used the ESP32 DevKit V1, I chose the DOIT ESP32 DEVKIT V1.

USB to UART Port Driver
Download the driver through this link : https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers, then go to the ‘Downloads’ tab. Make sure to download the right one according to your device’s operating system. In this project, I downloaded the ‘CP210x Windows Drivers’.

After it’s downloaded, go to your file explorer and unzip the downloaded file. The contents should be like as shown in the image below.

Since I’m using Windows 10 on my Laptop, I used the x64 version for this project. To install, click on the ‘CP210xVCPInstaller_x64’ file and follow the instructions until it’s fully installed.

After you’re done setting up your device, connect the micro USB cable to your device and the ESP32. Check the power indicator light (the red LED) on the ESP32, if it turns on, then it means that the ESP32 is properly connected and is receiving power from your device. But if it’s not on, then check your micro USB cable or check for other possible troubles.

The ESP32 is ready to be used

STEP 3 : Code the Program

Make sure the ESP32 is properly connected to your device, then on the top of the Arduino IDE click on Tools > Port > (choose the right port where the micro USB cable is connected to), in this project, mine was Port COM7.

To blink the built-in LED in the ESP32, you can use the template code provided in the Arduino IDE.
To do that, on the top left of the Arduino, click on File > Examples > 01 Basics > Blink.

Then a new window containing the code will pop up.

Or you can type in the code yourself.

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Click on the tick icon on the top left of the Arduino IDE to compile the code and wait until it says ‘Done compiling’ as shown in the image below.

Then click on the right arrow icon next to the tick icon to upload the code to the ESP32 and wait until it’s done uploading.

If it has trouble on connecting to the ESP, such as error shown below, reuplode the code by clicking the right arrow icon, then press and hold the BOOT button on the ESP32 when its ‘Connecting…’ until the rest of the red writings show up.

Now check your ESP32, the built-in LED (blue LED) should be blinking in 1 second intervals and it should look like the video attached below.

https://drive.google.com/file/d/1x2UQ75VXQ6C9d9fAyHhQVo5giGTaHDTu/view?usp=sharing

— BONUS TUTORIAL —

Using ESP32, you can also make external light blink and I will show you how I did it. But to do that there are a few additional components required, these were the things I used.

Additional Required Components

Breadboard

You can use either the short one or the long one, but in this project I used the one I have which is the long one.

Breadboard

Jumper cable (2pcs)

You can use either the male-to-male jumper cable or the male-to-female jumper cable, but in this project I used the male-to-female jumper cable. Keep in mind that if you use male-to-male jumper cable, the placement of the components would be quite different from the one I did.

Male-to-female Jumper Cable

330 Ohm Resistor

You can either use 220 Ohm or 330 Ohm resistor, in this project I used the one I have which is the 330 Ohm resistor.

330 Ohm Resistor

5mm LED Light

You can use either the 3mm or the 5mm LED in any colors, but here I used a 5mm blue LED.

5mm Blue LED

Component Arrangement

Attach the LED light on the breadboard, like the picture below with the positive side on the right (5f on the breadboard) and the negative side on the left (6f on the breadboard). The longer leg on the LED light indicates the positive side on the LED.

Then attach one of the resistor’s leg on a spot next to the LED’s positive leg (5i on the breadboard)) Also attach the other leg to the positive side of the breadboard parallel to the positive side of the LED.

Connect the male side of the jumper cable to the positive side of the breadboard next to the spot where the resistor is attached to. Connect the female side to one of ESP32’s leg, in this project I used pin number 22.

Attach the second jumper cable with the male side connecting to a spot next to the negative side of the LED (5h on the breadboard) while the female side connects to the GND pin on the ESP32.

Then connect your USB cable from the device to the ESP32, and make sure the red LED on the ESP32 is on.

Code

Open the Arduino IDE and open the template code provided from the Arduino IDE to blink.
Just like how I did it on the first part of this, on the top left of the Arduino, click on File > Examples > 01 Basics > Blink.

On the new window, scroll to the bottom so that the whole code will show up. Then on top of void setup(), type in ‘const int LEDPIN = 22;’ That will inform the program that the pin we’re using is pin number 22 on the ESP32. Then change all of the LED_BUILTIN in the program to LEDPIN. The program should look like this.

Or you can just type in

“const int LEDPIN = 22;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LEDPIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LEDPIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LEDPIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}”

Then just like the first part, compile the program by clicking on the tick icon on the top left of the Arduino IDE to compile the code and wait until it says ‘Done compiling’ as shown in the image below.

Then click on the right arrow icon next to the tick icon to upload the code to the ESP32 and wait until it’s done uploading.

Now check your breadboard, the blue LED should be blinking in 1 second intervals and it should look like the video attached below.

https://drive.google.com/file/d/1xg4VZbsdJhdYlN6u3T0a1DAZKXoD_89d/view?usp=sharing

That’s the end of the mini tutorial, hope this helps. :)

Some struggles I went through when doing this project is to figure out which one is the port connected to my ESP32, since the Arduino IDE showed 5 ports that I could choose from. And also figuring when and how long to press the BOOT button when uploading the code from my device to my ESP32. The rest of it went pretty smoothly and I finished the project.

See you in my next projects!

--

--