ESP32 Touch Blink Led Example
Fromp;     https://microcontrollerslab.com/gpio-pins-esp32-led-blinking-example/
GPIO pins of ESP32 – LED Blinking example

In this tutorial, we will learn how to use GPIO pins of the ESP32 devkit with 
LED blinking examples using Arduino IDE. Whenever any beginner starts learning 
about any microcontroller-based development board, Experts always recommend 
beginners to start with an LED blinking example which is also known as a light 
emitting diode. LED blinking examples use general-purpose input output pins to 
turn on and turn off the LED. By learning how to control GPIO pins, you will be 
able to use GPIO pins of ESP32 board for other applications like LCD interfacing,
keypad interfacing, and other embedded system projects.


ESP32 LED Blinking Tutorial Prerequisites

Let’s start with the basic introduction of general-purpose input-output pins of the ESP32 Devkit. You can use any ESP32 development board you want until it has an ESP-WROOM-32 chip on it. Also, the concepts used in this article will remain applicable to other types of ESP32 boards. For more features of this board, you can go through this tutorial: Introduction to the ESP32 development board We will be using Arduino IDE to program ESP32. So if you don’t know how to install a library of this IOT board you can check this tutorial: How to install ESP32 in Arduino IDE ESP32 GPIO Pins
In the market, various ESP32 dev kits are available, and the one used in this tutorial has 36 GPIO pins, although not all of them can be utilized as digital output pins. Out of a total of 30 pins, 24 pins can function as both digital input and output, while the remaining six pins (GPIO34, GPIO35, GPIO36, GPIO37, GPIO38, GPIO39) can only serve as digital input pins. Nonetheless, the 24 pins available for digital output are sufficient to power LED, relay, seven-segment displays, liquid crystal display, and other actuators. Therefore, any of the thirty pins can be utilized for this purpose. Note: GPIO6 to GPIO 11 are not exposed to pinout of ESP32 dev kit which we are using in this tutorial. Because these pins are internally connected to the integrated SPI flash on the ESP-WROOM-32 chip. Do you want to learn the difference between a sensor and an actuator? Check here. For more information about the GPIO pins of the ESP32 development board, check this article: ESP32 pinout and details of each pin Now that I believed you have already installed ESP32 in Arduino IDE You have also gone through the article on ESP32 pinout. Now let’s see how to blink an LED using ESP32 and Arduino IDE. ESP32 pin mapping LED Blinking Example Using ESP32
As I mentioned earlier in ESP32, we have can use 30 pins as a digital output pin. Now let’s select one pin and used it to turn on and turn off LED with some delay. In this example, we will control an LED with GPIO22 of ESP32. That means we will learn to use GPIO pins as digital output pins. We connect an LED to GPIO22 through a current limiting resistor of 220 ohms. This ESP32 LED blinking example works as mentioned below: LED blinking ESP32 example in Arduino IDE LED Blinking Connection Diagram
As you can in the above pinout diagram of ESP32, we have a total of 36 GPIO pins, but we will be using GPIO22 as a digital output pin. On different boards, these pins can be located at different locations. Therefore, you need to check its datasheet before using pin number in programming which I will explain in the programming part of this article. Now check the schematic and make it on your breadboard as shown below: LED blinking ESP32 Now make the circuit connection according to the above circuit diagram on the bread board. ESP32 GPIO Pins Arduino Functions
To write code for LED blinking using ESP32, first, you need to understand three main functions used in Arduino IDE to control general purpose input output pins. If you have already used Arduino IDE for Arduino or esp8266 programming, you will be already familiar with these functions : Arduino Code
This code is used to blink an LED connected with pin number 22 with a delay of one second. /*F******************************************************************** * **********************************************************************/ void setup() { pinMode( 22, OUTPUT ); // Set GPIO22 as digital output pin } /*F******************************************************************** * **********************************************************************/ void loop() { digitalWrite( 22, HIGH ); // Set GPIO22 active high delay( 1000 ); // delay of one second digitalWrite( 22, LOW ); // Set GPIO22 active low delay( 1000 ); // delay of one second } The code consists of two functions: setup() and loop(). The setup() function is called once when the board is first powered on or reset. It sets the mode of GPIO22 to an output pin. The loop() function is called repeatedly after setup() and contains the main logic of the program. In loop(), the digital pin 22 is turned on (set to a HIGH state) using the digitalWrite() function. Then a delay of 1000 milliseconds (1 second) is introduced using the delay() function. After the delay, the pin 22 is turned off (set to a LOW state) using digitalWrite() function again. Another delay of 1000 milliseconds is introduced. This process of turning the pin on and off is repeated indefinitely in a loop. digitalWrite( 22, HIGH ); // Set GPIO22 active high delay( 1000 ); // delay of one second digitalWrite( 22, LOW ); // Set GPIO22 active low delay( 1000 ); // delay of one second In summary, this code turns on and off a digital pin (GPIO22) on an Arduino board with a delay of 1 second between each state change. This can be used for various purposes such as blinking an LED connected to the pin, controlling a relay, or sending signals to other devices. ESP32 LED Blinking Demo
Now to run this example of LED blinking using ESP32, simply copy this code to Arduino IDE and compile the code. After compiling code, click on the upload button to upload the code to the ESP32 devkit. Before uploading the code, make sure you have selected the board and COM pin to which your ESP32 board is connected. If you do not see this board in the tools>port option, you need to install the driver for this board, you can download and install drivers from this link. Go to tools>Boards and select ESP32 Go to tools>Upload speed and choose 115200 Also, select Flash Frequency of 80Mhz from the tools options. Now click on the upload button. After that, you will see LED will be blinking with a delay of one second. It is a getting started tutorial with ESP32. To explore more tutorials and projects follow these guides: Push button interfacing with ESP32 How to use Built-in hall effect sensor of ESP32 Using touch sensor of ESP32 as a push button I2C LCD interfacing with examples Create ESP32 Web server in Arduino IDE