Project I : Setting Up and Blinking LED on ESP32

Rayhan Naufal Luthfi
8 min readFeb 6, 2022

Hellooo!!! 👋
Welcome to my first project of ESP32. This project is a form of implementation of the knowledge that i got from Embedded System course. In this first project, we’re going to set up our ESP32 and learn how to blink and LED with ESP32.

#STEP 1 : Required Components/Hardware

First things first we need to know what components are needed for this project. These components are just the examples I used for this project, you can use different types of components that you can find easily on the internet.

1. ESP32 Development Kit
This component can be obtained at a price of 69.000 rupiah and can be found on various online shopping platforms. This component is the main brain of this project

Source : https://sea.banggood.com/ESP32-Development-Board-WiFi+bluetooth-Ultra-Low-Power-Consumption-Dual-Cores-ESP-32-ESP-32S-Board-Geekcreit-for-Arduino-products-that-work-with-official-Arduino-boards-p-1109512.html?imageAb=1&akmClientCountry=ID&cur_warehouse=CN

2. Male to Male Wire Cable
This cable is used to connect the circuit between ESP, LED Lights, and Breadboard

Source : https://images.tokopedia.net/img/cache/500-square/product-1/2019/1/14/1851958/1851958_52511d23-723c-4321-9af8-2bbbc744877c_700_700.jpg

3. Micro USB Cable
This cable is used to connect our computer to the development board

Source : https://d2xjmi1k71iy2m.cloudfront.net/dairyfarm/id/images/239/0823954_PE775936_S5.jpg

4. Breadboard
This component is a place where we can assemble existing circuits

Source : https://images.tokopedia.net/img/cache/500-square/product-1/2015/4/11/7161339/7161339_891cb22c-e00a-11e4-b29b-c5fe86772fba.jpg

5. LED Lamp
In this project we will turn on this LED Light with ESP32

Source : https://m.media-amazon.com/images/I/61nWSDAUFiL._SL1024_.jpg

6. Resistor 330 ohm
The resistor function is to reduce the voltage that enters the led lamp, so the lamp is not easily damaged

Source : https://www.twinschip.com/image/cache/catalog/Products%20Twins%20Chip%20Store%202020/330%20Ohm%20Resistor%20X%205%20Pieces/330%20Ohm%20Resistor%20-%20Twins%20Chip%201-600x315w.jpg

7. Your Computer/PC
We will use Computer/PC as the power source for the ESP32 and to generate code that will be uploaded to the development board aka the ESP32

#STEP 2 : Required Software

After preparing all the components needed, we have to prepare all of the software that we’ll be used in our PC/Computer

1. Install Arduino IDE
You can download Arduino IDE from this Download link. Dont forget to choose the suitable version for your PC

After you download it, you can extract the zip folder to your computer. You can open Arduino IDE by selecting the arduino.exe file in the folder you extracted before.

2. Add Board Manager URL
In order for Arduino IDE to recognize a board connected to the PC, it is required to install the corresponding core for that board’s microprocessor. For Arduino boards it is very simple to install the core, but if your board is manufactured by a third party the procedure is different.

For 3rd party hardware packages, it is first necessary to add the URL of their Boards Manager JSON file in: File > Preferences > Additional Boards Manager URLs. The URLs point to JSON index files that Arduino IDE uses to build the list of available installed boards.

After that, fill the Additional Boards Manager URLs with this link
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json and then click OK.

3. Install ESP32 Module Packages
After we add the URLs for ESP32 Board Manager, we need to install the Board Packages. These Packages can be installed from Tools -> Boards -> Boards Managers

For this step ignore the DOIT ESP32 DEVKIT V1, it’s there because i already installed the packages. Next, we need to search for ESP32 modules made by Espressif System and install it.

Now, change the board to DOIT ESP32 DEVKIT V1 by clicking Tools -> Board -> ESP32 Arduino -> DOIT ESP32 DEVKIT V1

4. Install USB to UART Port Driver
Install the USB to UART Port Driver from this Download link. Download the CP210X Windows Drivers and then Install it

#STEP 3 : Connect ESP32 to our Laptop/PC

Connect ESP32 to your Laptop/PC with Micro-USB Cable (make sure it can trasnfer data). The red light on the ESP32 should be turn on if it connected. It is the indicator to show that your ESP32 is powered on.

The light only showed that it is turned on, but we cant upload a single code yet to our ESP32. We need to change port from Arduino IDE to exact port as ESP32. To do that we need to go to Tools -> Port.

Ok now we can code and upload it to our ESP32 freely. For this first project, i will do a simple project, which is Blinking Light.

#STEP 4 : Experimenting

Now i will blinking an internal light on the ESP32 itself. We can program the code ourselves, but Arduino IDE provides some kind of example to code the program so we don’t have to program it ourselves. All we need to do is just go to File -> Examples -> Basics -> Blink
notes : it is just an example, you can test a different kind of codes there

After you get the code, you need to verify the code so it can check if there is a bug or a problem. You can do that by clicking the checklist buttonon the top left below the File tab.

After finished compiling, we need to upload the code to our ESP32. We can do that by clicking the arrow button next to the checklist button.

If you had done all the steps correctly, then your ESP32 should be blinking like this. You can change the speed of its blink by changing the delay value. 1000 means 1 second. After you change the value, you need to verify and upload the code again. In this below video i used 500ms on the digitalWrite

Now i want to experiment to turn on an external Led with ESP32. To do that we need an extra components that i already mentioned earlier, which is Breadboard, Resistor, Male to Male jumper wire, and an Led Light.

After you get all of the components, we need to attach all the components to the breadboard.

  1. Attach the ESP32 to breadboard carefully, dont let the ESP32 leg’s break.
  2. Attach the LED light straight with the ESP32.
  3. Attach the resistor just beside the positive pin of the LED light, the positive pin is longer than the negative and the other leg of the resistor to the negative side of the breadboard
  4. Plug the male-to-male jumper cable from the pin you want to use aside of the resistor. in this project i’ll use pin number 32
  5. Plug another male-to-male jumper cable from ground (GND) to the negative side of breadboard.

After you assembled all the components, the circuit will look like this.

For this external blinking, i use this code as an example,

const int ledPin = 32;void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}

Make sure to verify and upload the code to your ESP32, and the result will look like this

And for the last experiment i want to try to make the LED fadeout, so i use this code to test the experiment

int ledPin = 32;    
int brightness = 0;
int fadeAmount = 10;

void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
analogWrite(ledPin, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}

After testing the code, I’m quite satisfied with the result, and so here it is

For this first project I faced quite a problem, the micro-usb cable could not be detected by the Arduino IDE. I couldn’t change the Port from the Arduino IDE. After doing some research on the internet, I found a solution on a forum. On the forum it’s said that,

Nowadays there are a lot of cheap (Chinese) USB cables that can only be used for charging or powering devices. I assume these have only 2 out of 4 wires: ground and +5V, but no data lines. If you would use a cable like that, the result would be what you described. So make sure you have a ‘real’ USB cable by testing it on another device. Don’t just check if it charges your phone, but check if you are actually able to transfer data.

For the first trial, i used a micro-usb cable for charging my mouse. After read that forum, I bought a new cable which is intended for data transfer and it’s working properly

Yes, that’s my experience in working on this first project. Thank you for reading this article and I hope this article can be helpful for people who want to start trying ESP32

Rayhan Naufal Luthfi
Information System Technology ITB 2020
18220048

--

--