Embedded System #1 — LED Blink with ESP32

Syafiq Ziyadul Arifin
5 min readJan 30, 2023

--

ESP32

Hi, it’s me, Syafiq Ziyadul Arifin, also known as Safiq. I am currently enrolled in the II2260 Embedded System course this semester, and my lecturer has tasked me with some projects using ESP32 and the Arduino IDE. This is not my first time working with the Arduino IDE as I have used an Arduino UNO in previous projects. During this course, I hope to learn new things and share my weekly explorations with ESP32 through blog posts (get the list here). So, stay tuned!

Components Used:

  • ESP32 Devkit V1
  • Data cable (USB type A to Micro B)*

Arduino IDE

For my first project, I have to make the built-in LED on the ESP32 blink. The first step is to download and install the Arduino IDE from https://www.arduino.cc/en/software.

Arduino IDE 2.0.3

As of January 30th, 2023, the latest version is v2.0.3. Choose the option for your operating system, for me, I am using Windows 11 and selected the first option.

After installing the Arduino IDE, you will need to configure it for ESP32. By default, the Arduino IDE only supports Arduino boards, so there are a couple of steps to install ESP32 in the Arduino IDE:

  1. Go to File > Preferences in the Arduino IDE.
  2. Add “https://dl.espressif.com/dl/package_esp32_index.json" to the additional boards manager URLs.
  3. Open the Boards Manager and search for “esp32” and install the package.

Check the GIF below.

Install ESP32

You will also need to download the CP210x USB to UART bridge VCP driver from https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads.*

CP210x USB to UART Bridge VCP Drivers

As of January 30th, 2023, the latest version is v11.2.0 which was released on October 21st, 2022.

Once you have installed the driver, open the Device Manager and show the hidden devices (View > Show hidden devices). In the “Other devices” section, you should see the CP210x USB to UART Bridge Controller with a warning symbol.

Other devices

To fix this, update the controller using the driver you just downloaded.

The next step is to select the board and port that you are using. In my case, my board is ESP32 Devkit V1 (you can check the model on the back of your ESP32) and it is connected to the COM3 port.

Select Other Board and Port

Code

To access the code to blink the built-in LED, go to File > Examples > 01.Basics > Blink in the Arduino IDE. You will see a new window open with the code.

Blink example code
/*
Blink

Turns an LED on for one second, then off for one second, repeatedly.

Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products

modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman

This example code is in the public domain.

https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
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
}

The setup() function initializes the built-in LED, and the loop() function makes it blink. There are two delay() functions that accept an integer argument representing the time in milliseconds. The first delay() function controls how long the LED is turned on, and the second delay() function controls how long the LED is turned off. To upload the code to the ESP32, simply click on Upload.

Upload

Wait for the output to show “Connecting…”, then press and hold the BOOT button on the ESP32. The built-in LED should now be blinking.

LED blink

Congratulations, you have successfully completed your first project with ESP32 and the Arduino IDE!

(*) Trivia:

  • There are 2 types of Micro B cable, data cable and (only) charging cable. Data cables have 4 wires for power and data transfer, while charging cables only have 2 wires for power.
  • USB to UART bridge is used to make a serial connection from our device to ESP32.

--

--