ESP32 101 : Turning on LED Lights

Farhandika
5 min readFeb 1, 2022

--

An ESP32

Level : Beginner

ESP32 is a low cost microcontroller device with wifi and bluetooth module integrated into the package. This chip was originally made by TSCM and fabricated using 40 nm transistors. It has various use case, one is to create a simple door lock with magnetic sensors.

But today, we are not going to built that complex system. Today, we are going to understand the basics of ESP32 by turning on and off an internal LED light and external LED light.

Components

What we need to create this simple project is
- 1 ESP32
- USB cable
- 5 Jumper Cable (Male to Male)
- 1 Breadboard
- 1Resister ( 330 Ohm)
- 1 LED Light (Any Color)

We also need to have an IDE named Arduino IDE and a basic understanding of any programming language to understand what the code really do. But, if you do not know how, you may also tag along as we will explain it in detail.

To watch how to install Arduino IDE, you may watch videos on youtube or read this simple how to do made by my lecture.

To understand ESP32 pins, you may also check the data sheet

Manipulate Your First LED Lights

Before we jump into the codes, we need to built the hardware first. First, connect your ESP32 to your breadboard

Bread board and ESP32
Connect your ESP32 to the breadboard
Push it so that it’s truly connected

Once you installed the ESP32 to the breadboard, open your Arduino IDE and let’s start coding!

Programming the system

In the beginning, ESP32 does not know what it will do. To make it simple, it’s plain stupid and ready to be instructed by YOU.

First, create a new project, and then copy paste this code below :

#define LED1 2

void setup() {
pinMode(LED1,OUTPUT);
}

void loop() {
delay(1000);
digitalWrite(LED1,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
}
copy pasting the code into your arduinoIDE

This code is written in C, what this code do is simple turning on/off the led light in ESP32. Let’s breakdown each part !

#define LED1 2

Here, we set pin number 2 as LED1 to ease up when we’re coding. In ESP32 pin number 2 is equal to built in LED.

void setup() {
pinMode(LED1,OUTPUT);
}

Setup is a function that returns nothing. This function purpose is to add which pins in ESP32 that we want to play with. In this case, we are playing with LED1 and we set it so that we can play with it.

void loop() {
delay(1000);
digitalWrite(LED1,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
}

Loop is a function that runs how the pin will work. For example, what we do here is delay 1s before we turn it on and then delay 1s before we turn it off. This state will continue until you turn the device off.

Once you paste it into the project, we shall continue by uploading it into the ESP32.

Uploading The Code

To upload your code into the device, all you have to do is connect your ESP32 to your computer you’re currently working with and then press upload. Some version requires you to press the boot button on esp32 while uploading.

Upload button is on the top left corner on your Arduino IDE with arrow button

Congratulation! You Just Made Your Very First ESP32 Project

uploading is done

Now that you are done uploading it into the ESP32, you can see that the light is blinking and that’s how you know your code works and uploaded.

The blue LED will lights on once you’re done uploading

Upgrading The Project

Like what i have previously mentioned, this session will also cover turning on an external LED Light.

All you have to do is follow the previous steps with some tweaking. In this project, the breadboard will be a very crucial item as we will add LED into it.

Just like the previous lesson, we’ll start by setting up the hardware.

Adding LED into Breadboard

Adding external LED Lights schematics

To add an external LED Light to your project, you need to have 1 LED Light, 2 Jumper cable, and an 220 Ohm Resistor.

Here are the steps to follow :
1. Connect your GND(Ground) pin to the negative part on your breadboard
2. Connect your 3V3 pin to the positive part on your breadboard
3. Connect your D5 pin to a resistor
4. Connect your resistor to an LED Light
5. Connect your LED Light to the positive side by using a jumper

The image above shows how it should have been done. If you have read the ESP32 data sheet, you should know that we’re playing with pin number 5 for the output.

Code The Program

All you have to do is copy paste this code to your arduino IDE

#define PIN5 5void setup() {
pinMode(PIN5,OUTPUT);
}
void loop() {
delay(1000);
digitalWrite(PIN5,HIGH);
delay(1000);
digitalWrite(PIN5,LOW);
}

I will not explain it deeply as it’s similar to the one on the previous project. The difference is we’re playing with pin number 5 while the previous project plays with pin number 2.

Finnish it

once you’re done with the code, upload it and you’ll see something simmilar to the image below

The LED Light is on

Congratulation!

Congratulation, you just made a project using ESP32!

--

--

Farhandika

A part time Software Engineer and theoritical cs enthusiasts. I use a very expensive language called swift