Blinking LED on ESP32

Hello! I will explain the steps to make the internal and external LED on the ESP32 board blink!


Internal LED

First, you must prepare the hardware needed:

1. ESP32 board

ESP32 board

2. Laptop/PC

Laptop

3. Micro USB cable

Micro USB cable

Then, don't forget to install the required software:

1. Download the program at this link: https://www.arduino.cc/en/software. Choose your Laptop/PC's operating system in the download options.

Arduino IDE website

2. After the file is downloaded, open the folder and run arduino.exe

arduino.exe in File Explorer

3. Open File > Preferences

Opening Preferences in Arduino IDE

4. Add https://dl.espressif.com/dl/package_esp32_index.json in Additional Boards Manager URLs and click OK.

Adding ESP32 board manager

5. Open Tools > Board > Boards Manager...

Opening Boards Manager in Arduino IDE

6. Look for esp32 and install it

Installing esp32 board

7. Download USB to UART port driver here: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers. Again, choose your Laptop/PC's operating system in the software options.

VCP Installer website

8. Install the driver by running the installer

VCP Driver Installer


After installing all of that, we're ready to try the experiment.

1. Set up the board according to your ESP 32 board. As I use the DEVKIT V1, I set it up by choosing Tools > Board > DOIT ESP32 DEVKIT V1

Setting up the board in Arduino IDE

2. Connect your ESP32 board with your PC by micro USB cable. If the LED on the board is on, then your computer and the board are connected.

The LED light on the ESP32 board is on

3. Change the port to the installed USB to the UART driver. I use COM3.

Changing the port to COM3

4. Open Examples > 01. Basics > Blink to open the code for blinking LED

Opening the Blink code

5. Click the Upload button to upload the code into the ESP32 board.

Uploading the code into the ESP32 board

6. Wait until it's done compiling and uploading.

Compiling and uploading

7. If it's successful, you will see the internal LED on your ESP32 board blinking.
Blinking internal LED



some tips!
1. I've encountered an error where the port is not showing even though the red LED on the board is on. You can try changing your micro USB cable because probably the one you're using doesn't have data exchange wires.
2. I also got an error like this

and I found a solution by manually removing and reinstalling the ESP32 boards' platform. You can read the full solution here https://forum.arduino.cc/t/esp32-error-when-compiling/886030/16


External LED

For lighting the external LED, we have to prepare several components other than the ones I've mentioned before.
1. LED 5mm
LED 5mm

2. Breadboard
Breadboard

3. Resistor 330ohm
Resistor 330 ohm
4. Male-to-male jumper
Male-to-male jumper


After you're ready with your tools, you can start arranging the circuity.
1. Put the ESP32 on the breadboard.
Attaching ESP32 on the breadboard

2. Connect the ground of the ESP32 (GND) to the power rails. You can use either the positive or the negative side, but I'll be using the negative side in this tutorial.
Connecting the ground with the negative side with a jumper

3. Attach the resistor and make sure it's connected with the ESP32.
Attaching the resistor

4. Attach the lamp. The negative pin should be on the same side as the ground.
Attaching the lamp

5. Connect the lamp with the ESP32 by using a jumper. I'm using the D33 pin for this project.
Connecting the lamp with ESP32 by using a jumper

If your circuitry is ready, then you can proceed with uploading the code to the ESP32 board.
1. Write the code. You can modify the last blink code by changing the LED part. I'm marking the parts that I added or changed as the parts with blue font color.

const int ledpin = 33;
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize ledpin 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
}
 
2. Connect your laptop/PC with the ESP32 board by using a micro USB cable.
Connecting ESP32 with the laptop

3. Upload the code to the ESP32 board.
Uploading the code

4. Yay! The external LED is now blinking!
Blinking external LED




And that's all! Hope this helps :)




Comments

Popular posts from this blog

ESP32 OLED Display and ESP32 PWM

ESP32 I2C Serial Communication