Lighting three LEDs connected to the ESP32 board via WIFI

ESP32 13-09-23
259 0

Tutorial plan

1- The difference between WIFI and Bluetooth

2- The ESP32 board and WIFI

3- Role of and files in ESP32 board

4- The webserver with the ESP32 card

5- Lighting three LEDs connected to the ESP32 board via WIFI with Micropython

6- The components needed to use three LEDs with the ESP32

7- Mounting the ESP32 with three LEDs



The difference between WIFI and Bluetooth

Wi-Fi and Bluetooth are both wireless communication technologies, but they serve different purposes and have distinct characteristics. Here are the key differences between Wi-Fi and Bluetooth:

1- Purpose:

– Wi-Fi (Wireless Fidelity): Wi-Fi is primarily designed for high-speed data transmission over relatively long distances. It is commonly used for connecting devices to the internet, local area networks (LANs), and to each other for tasks like file sharing and media streaming.

2- Bluetooth: Bluetooth is designed for short-range wireless communication between devices. It is mainly used for connecting peripherals like keyboards, mice, headphones, speakers, and for transferring smaller files between devices such as smartphones, tablets, and laptops.

2- Range:

– Wi-Fi: Wi-Fi typically has a longer range compared to Bluetooth. Wi-Fi signals can cover large areas, depending on the router’s power and the presence of obstacles.

– Bluetooth: Bluetooth has a shorter range, usually up to about 30 meters (100 feet). However, this range can vary depending on the Bluetooth version and the specific devices involved.

3- Data Transfer Rate:

– Wi-Fi: Wi-Fi offers much higher data transfer rates than Bluetooth. Modern Wi-Fi standards, like Wi-Fi 6 (802.11ax), can provide speeds of several gigabits per second, making it suitable for streaming high-definition video and fast internet access.

– Bluetooth: Bluetooth offers lower data transfer rates compared to Wi-Fi. The latest Bluetooth 5.x standard provides speeds of up to 2 Mbps, which is sufficient for most audio streaming and file transfers but not ideal for high-bandwidth tasks.

4- Power Consumption:

– Wi-Fi: Wi-Fi tends to consume more power, which is why devices like smartphones and laptops have limited battery life when actively using Wi-Fi connections.

– Bluetooth: Bluetooth is designed to be more power-efficient, making it suitable for battery-operated devices like wireless headphones and fitness trackers. Bluetooth Low Energy (BLE) is a variant of Bluetooth designed specifically for low-power applications.

5- Use Cases:

– Wi-Fi: Wi-Fi is commonly used for internet access, online gaming, streaming media, and connecting multiple devices to a network.

– Bluetooth: Bluetooth is often used for connecting accessories like headphones, speakers, keyboards, and mice to computers and mobile devices, as well as for tasks like transferring photos and files between smartphones.

In summary, Wi-Fi is better suited for high-speed, long-range wireless data transmission, while Bluetooth is designed for short-range connections between devices, emphasizing low power consumption and compatibility with various peripherals. The choice between Wi-Fi and Bluetooth depends on the specific use case and requirements of the devices involved.

The ESP32 board and WIFI

The ESP32 is a versatile microcontroller board that is well-known for its built-in Wi-Fi capabilities. Here’s an overview of the ESP32 board and its Wi-Fi features:

1- ESP32 Microcontroller:

– The ESP32 is a microcontroller board based on the ESP32 chip, which is developed by Espressif Systems.

– It features a dual-core Xtensa LX6 CPU, which allows for multitasking and processing tasks efficiently.

– The ESP32 includes various built-in peripherals, including GPIO pins, ADCs, DACs, UART, SPI, I2C, and more, making it suitable for a wide range of IoT (Internet of Things) and embedded projects.

2- Wi-Fi Connectivity:

– One of the standout features of the ESP32 is its integrated Wi-Fi capabilities. It supports 2.4 GHz Wi-Fi 802.11 b/g/n, which enables it to connect to wireless networks and the internet.

– The Wi-Fi stack on the ESP32 allows it to act as both a station (client) that can connect to existing Wi-Fi networks and an access point (AP) that can create its own Wi-Fi network for other devices to connect to.

– The ESP32 supports secure Wi-Fi connections using protocols like WPA/WPA2 and even more advanced security features.

3- Applications:

The combination of the ESP32’s processing power and built-in Wi-Fi makes it ideal for a wide range of applications, including:

– IoT devices: Sensors and actuators can be connected to the ESP32, which can then transmit data to the cloud or a local server via Wi-Fi.

– Home automation: ESP32 boards can be used to control smart home devices, monitor energy usage, and more.

– Wi-Fi-connected gadgets: You can build Wi-Fi-connected gadgets like weather stations, smart doorbells, and Wi-Fi-controlled robots.

– Internet-connected displays: ESP32 can be used to create web servers, IoT dashboards, and even simple web-based games.

4- Programming:

– The ESP32 can be programmed using various development environments, including the Arduino IDE, PlatformIO, and the Espressif IDF (IoT Development Framework).

– A rich ecosystem of libraries and resources is available for ESP32 development, making it easier to build Wi-Fi-enabled projects.

5- Power Consumption:

The ESP32 is relatively power-efficient, especially when compared to more power-hungry Wi-Fi modules. It offers power-saving features, making it suitable for battery-operated IoT devices.

In summary, the ESP32 board is a popular choice for IoT and embedded projects that require Wi-Fi connectivity. Its combination of a powerful microcontroller, integrated Wi-Fi capabilities, and extensive development support has made it a go-to platform for building a wide range of Wi-Fi-enabled devices and applications.

Role of and files in ESP32 board

In the context of the ESP32 microcontroller board, the and files play essential roles in the firmware execution and control flow. These files are used in MicroPython, a popular Python implementation for microcontrollers.


Bootstrapping: The file is executed very early in the boot process of the ESP32. It is responsible for setting up some basic system configurations and initialization tasks. This includes configuring the board’s pins, setting up the network stack (if required), and other low-level hardware configurations.

Pre-main Tasks: Anything that needs to be established before the main application code runs can be placed in this file. For example, you might configure the serial communication, initialize hardware peripherals, or set up system-wide variables.

Control Flow: If there are issues during the execution (e.g., incorrect pin configuration or failed network initialization), the system may halt or enter safe mode, depending on the specific implementation.


Application Code: The file contains the main application code that you want to run on the ESP32. This is where you write your Python code to control sensors, actuators, and perform other tasks specific to your project.

Control Flow: After the initialization is complete, the control is transferred to the file, and the code in this file starts executing. Your application logic should be organized here.

It’s important to note that not all MicroPython setups require both and In some cases, you might only need a file if you don’t have specific bootstrapping or initialization requirements. The purpose of these files is to separate low-level system setup from the high-level application code, making it easier to maintain and manage your ESP32 projects.

Lighting three LEDs connected to the ESP32 board via WIFI with Micropython

To light three LEDs connected to an ESP32 board via Wi-Fi using MicroPython and separate and scripts, follow these steps:

1. Hardware Setup: Connect three LEDs to the GPIO pins on your ESP32. Make sure to connect the anode (longer leg) of the LED to a current-limiting resistor and then to the GPIO pin. Connect the cathode (shorter leg) of the LED to the ground (GND) pin.

2. Flash MicroPython: Ensure you have MicroPython firmware flashed onto your ESP32, and that it has Wi-Fi support enabled.

3. Script: Create a script (this script runs on boot and initializes Wi-Fi):

4. Script: Create a script (this script will run after and control three LEDs):

5. Customize GPIO Pin: Replace LED_PIN with the GPIO pin number where  LED is connected. In the example, it’s set to GPIO pin 23 to red LED , set to GPIO pin 22 to green LED and set to GPIO pin 22 to yellow LED.

6. Upload Scripts: Upload both the and scripts to your ESP32 using a tool like ampy or WebREPL.

7. Power On the ESP32: Power on your ESP32, and it should connect to your Wi-Fi network (as configured in and start toggling the three LEDs connected to the specified GPIO pins according to the logic in

This setup will automatically connect your ESP32 to Wi-Fi on boot and run the LED control code in Make sure to replace 'Your_WiFi_SSID' and 'Your_WiFi_Password' with your actual Wi-Fi credentials.

The components needed to control three LEDs by the ESP32 board

To control three LED with the ESP32 board, you will need the following components:

1- ESP32 Board:

ESP32 card

The ESP32 is a microcontroller board that features built-in WiFi and Bluetooth capabilities. It can be programmed and used to control the LED.

2- Three Resistors

Three resistors

A resistor is an essential electronic component used to impede or limit the flow of electric current in a circuit. It’s designed to have a specific resistance value, which is measured in ohms (Ω). Resistors come in various shapes, sizes, and types to suit different applications.

3- Three LEDs (Light Emitting Diode):

A Light Emitting Diode (LED) is a semiconductor device that emits light when an electric current passes through it. LEDs are widely used in various applications due to their efficiency, small size, and low power consumption.

4- Breadboard:

Test plate

A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.

5- Jumper wires:

Jumper wires

You will need jumper wires to make electrical connections between the components on the breadboard.[/vc_column_text]

Mounting ESP32 with three LEDs

Here are the steps to mount the ESP32 with three LEDs:

1- Place the ESP32 board on the breadboard.

2- Insert the LEDs into the breadboard, connecting them to the output pins of the ESP32 board. For example, connect the red LED to GPIO 23, the green LED to GPIO 22, and the yellow LED to GPIO 21. Make sure to insert the LEDs correctly, paying attention to the polarity (anode and cathode).

3- Connect a resistor in series with each LED. The resistor should be connected between the corresponding GPIO pin and the positive terminal (anode) of the LED.

4- Connect the negative terminal (cathode) of each LED to the ground (GND) of the ESP32 board.

5- Double-check that all connections are properly made and that nothing is short-circuited.

Once the mounting is complete, you can program the ESP32 board to control the LEDs. For example, you can use the MicroPython programming language and the uGPIO module to turn the LEDs on and off.

Mounting ESP32 with three LEDs

Mounting ESP32 with three LEDs

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

Pictures of the articles

Robotic site created by MedAli-Teacher info