7. Mixly Tutorial¶
Development Environment Setup¶
Download Software:
You can download the Mixly development environment from the Mixly website https://mixly.cn
If you are using a Windows system, it is recommended to download our version that already has the plugins installed Mixly
It is recommended to download the mixly3.0 version (the screenshots in the document are of 2.0 and will be updated gradually later)
Click the link in the red box in the image below to enter the Baidu Cloud Drive main page


Mixly For Windows:

Mixly For Mac(Select according to your system):

Install Software:
- Windows version installation:
It is recommended to download the latest version. This case uses the mixly3.0-win32-x64-rc4 full version as an example. After downloading, rename it to mixly3.0, right-click and extract it to a local disk.
Special reminder:
(1) It is recommended to extract it to the root directory of the hard drive. The path must not contain Chinese characters or special characters (such as: . _ ( ) etc.).
(2) The recommended installation path is D:mixly3.0
Because Mixly is a green, installation-free software, the "Mixly3.0-win32-x64-rc4 full version" version can be used directly after extraction. If you download the "One-click update version.7z" compressed package, after extracting it, you need to left-click and double-click to open "One-click update.bat" and follow the prompts to update Mixly.
The contents of the complete Mixly folder are shown in the figure below:

Start the software:
Double-click "Mixly.exe" here to open the Mixly software, as shown in the figure below:

After opening the Mixly software, find and click " Arduino ESP32 " to enter the Mixly programming interface. The software interface is shown in the figure below:

- Mac version installation:
There is a MAC Installation Mixly3.0.txt file description here.

Interface Introduction:


Overall, the Mixly software interface is divided into 4 parts.
-
The left side of the interface is the module area, which contains all the program modules that can be used in Mixly. According to different functions, they are roughly divided into the following categories: "Input/Output", "Control", "Math", "Logic", "Text", "Arrays", "Variables", "Functions", "Serial", "Sensors", "Actuators", "Displays", "Communication", "Storage", and "Network". Each type of module is represented by a different color block, and the modules in each category will be introduced in detail in Appendix A.
-
To the right of the module area is the program building area. The modules in the module area can be dragged with the mouse to the program building area. The dragged modules will be combined here into a program block with certain logical relationships. This area is somewhat similar to the place where code is written in a code editing software. There is a trash can in the lower right corner of this area. When we delete a module, we need to drag the module to the trash can. Above the trash can there are three round buttons, which can achieve zooming in, zooming out, and centering of the program building area.
-
Above the module area and the program building area is the basic function area, similar to the menu area of general software. It not only contains buttons such as "New", "Open", "Save", "Save As", "Export Library" and "Manage Library" that all software has, but also contains buttons such as "Compile", "Upload", "Board Selection", "Serial Port" and "Serial" that are needed in hardware programming software.
-
At the very bottom of the interface is the prompt area, where corresponding prompt information is displayed during the process of compiling and uploading software. We can use the prompt information to solve some problems that occur during the compiling and uploading process.
Finally, there are two more points to add:
The first point is that Mixly supports multiple languages. We can find and click
through the following interface to enter the personalization settings page, find the Simplified Chinese drop-down menu under Language, and select a different language version. At this time, the drop-down menu shows Simplified Chinese, as shown in the figure below:


The second point is that there is a
button on the upper right of the top of the interface. Clicking this button will enter the pure code form, as shown in the figure below:

As a development environment that integrates graphical programming and code programming, Mixly would not be good enough if it could only display code or display graphical program blocks separately. In Mixly, code and graphical program blocks can be presented on the screen together. This function can be realized through a button on the upper right of the top of the interface. After clicking this
button, it is as shown in the figure below:

At this time, the corresponding code will be displayed on the right side of the program building area. This code corresponds to the program block composed of the modules in the program building area, and will change as the modules change, but the code in the area is not editable. At the same time, the left-pointing arrow button on the far right of the interface becomes a right-pointing arrow.
Note: To learn more about Mixly-related knowledge, please click the link:https://mixly.readthedocs.io/zh-cn/latest/ 。
ESP32 Main Control Board Driver Installation:
For the ESP32 main control board driver installation method, please refer to the previous "Arduino C Tutorial Windows System" section, which will not be repeated here. If the driver has already been installed, skip this step.
Add Mixly Library Files:
Note: The Mixly library file (index library) must be added, otherwise the example code involving related modules later will not be able to open。
Special reminder: The library files are provided at the Materials Download location above. Please download and install the library files.
After downloading and installing the Mixly software, click Arduino ESP32 to enter the code editor. First click "Settings" in the upper right corner, then click "Manage Library" to enter the add library file interface, as shown in the figure below:


First click "Import Library", then click
to enter the location where the library files are stored, find and select the index.xml library file, then click "OK". After that, you can see that the library file is being imported, and after a while the words "Import Successful" will appear, indicating that the library file has been imported successfully, as shown in the figure below:



Click "Manage Library" to see the successfully added library file, as shown in the figure below:

Close the window interface for adding library files, and you can see the added library files on the left side of the code editor, as shown in the figure below:

Write Code and Upload to the ESP32 Main Control Board: (The steps for uploading project code later are the same, i.e., same as below。)
Make sure the ESP32 main control board is successfully connected to the computer, then double-click the " Mixly.exe " icon to open the Mixly software.
Method ①: Directly drag code blocks to the program building area to write code, using pin IO15, as shown in the figure below:

After writing, save it to the computer. Click "File" --> "Save As", as shown in the figure below:

Select the ESP32 main control board type "ESP32 Dev Moduel" and the serial port (COM6) (Tip: Different computers have different serial ports), (Note: Only after connecting the ESP32 board to the computer via a USB cable can you see the corresponding port.), as shown in the figure below:


Click
to upload the code to the ESP32 main control board, as shown in the figure below:

Method ②: Open the already-written code from the computer
Extract the code file compressed package we provide, and save the extracted code folder to a convenient location.
"File" --> "Open", then select the path where the code is saved, select the code file and open it, as shown in the figure below:


After the code file is opened, you need to manually select the ESP32 main control board type "ESP32 Dev Moduel" and the serial port (COM6) (Tip: Different computers have different serial ports), (Note: Only after connecting the ESP32 board to the computer via a USB cable can you see the corresponding port.), as shown in the figure below:


Click
to upload the code to the ESP32 main control board, as shown in the figure below:

Project 01 Hello World¶
1. Project Introduction:
For beginners of ESP32, we will start with some simple things. In this project, you only need an ESP32 board, a USB cable and a computer to complete the "Hello World!" project. It is not only a communication test between the ESP32 board and the computer, but also a beginner project for ESP32.
2. Project Components:
![]() |
![]() |
|---|---|
| ESP32*1 | USB Cable*1 |
3. Project Wiring:
In this project, we connect the ESP32 and the computer via a USB cable.

4. Code Description:

Set the serial baud rate, generally set to 9600.

Automatically wrap the output data. Output data from the serial port, followed by a carriage return and a line feed.

Output data from the serial port without wrapping.

Pause the execution of the program for a period of time, that is, a delay. The unit is milliseconds.
5. Project Code:
You can open the code we provide, which is saved at (i.e., path): ..\program-code\mixly-code。( The paths where later project codes are saved are the same, i.e., same as below。)
You can also write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
". -
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", change hello to Hello World. -
Drag out "
" from "
".
Complete code:

Before uploading the project code to ESP32, you need to manually select the Arduino ESP32 main control board type "ESP32 Dev Moduel" and the serial port (COM6) (Tip: Different computers have different serial ports). (Note: Only after connecting the ESP32 board to the computer via a USB cable can you see the corresponding port.) (The steps for uploading project code later are the same, i.e., same as below。)


Click
to upload the project code to the ESP32 board. (Same below)

Note:(Same below) If the upload fails, you can click
again and then press the Boot button
on the ESP32 board with your hand, and release the Boot button after the upload progress percentage appears, as shown in the figure below:

Project code uploaded successfully!

6. Project Result:
After the project code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 9600, so that the serial monitor prints "Hello World!".



Project 02 Light Up an LED¶
1. Project Introduction:
In this project, we will show you how to light up an LED. We use a digital pin of the ESP32 to turn on the LED so that the LED is lit.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Red LED*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*1 | Jumper Wires*2 | USB Cable*1 |
3. Component Knowledge:
(1)LED

An LED is a semiconductor called a "light-emitting diode", an electronic device made of semiconductor materials (silicon, selenium, germanium, etc.). It has a positive pole and a negative pole. The short leg is the negative pole, connected to GND, and the long leg is the positive pole, connected to 3.3V or 5V.

(2)Five-band Resistor
A resistor is an electronic component that limits or regulates the flow of current in a circuit. On the left is the appearance of the resistor, and on the right is the symbol used to represent the resistor in a circuit. The unit of resistance (R) is the ohm (Ω), 1 mΩ= 1000 kΩ, 1kΩ= 1000Ω.
We can use resistors to protect sensitive components, such as LEDs. The strength of a resistor (in Ω) is marked on the body of the resistor with small color bands. Each color represents a number, which you can look up using a resistor reference card.

In this kit, we provide 3 five-band resistors with different resistance values. Here we take the 3 five-band resistors as an example:
220Ω Resistor ×10

10KΩ Resistor ×10

1KΩ Resistor ×10

At the same voltage, there will be a smaller current with a larger resistance. The relationship between current, voltage, and resistance can be expressed by the formula: I=U/R. In the figure below, the current passing through R1 at present is: I = U / R = 3 V / 10 KΩ = 0.0003A = 0.3mA.

Do not connect a resistor with a very low resistance value directly to the two poles of the power supply, because this will make the current too high and damage electronic components. Resistors have no positive or negative pole.
(3)Breadboard
The breadboard is an important tool used to build circuits in the laboratory. There are many holes on the breadboard, into which circuit components such as integrated circuits and resistors can be inserted. Being proficient in using the breadboard is one of the important foundations for improving experimental efficiency and reducing the probability of experimental failures. The following is a brief introduction to the structure and usage of the breadboard. A typical breadboard is shown below:

The appearance and internal structure of the breadboard are shown in the figure above. The common smallest-unit breadboard is divided into three parts: upper, middle and lower. The upper and lower parts are generally narrow strips composed of one or two rows of sockets, and the middle part is a strip composed of an isolation groove in the middle and 5 rows of sockets on the top and bottom.

The two narrow strips of the breadboard each have two rows of sockets. The two rows are not connected to each other, and are generally used as the path for power supply introduction. The first row on the top, marked with "+", has 10 groups of sockets (all connected internally), all of which are positive poles; the second row on the top, marked with "-", has 10 groups of sockets (all connected internally), all of which are ground. The structure of the first and second rows at the bottom of the breadboard is the same as above. If you need to use the entire breadboard, usually connect "+" to "+" with a wire, and "-" to "-" with a wire.
The wide strip in the middle is composed of an isolation groove in the middle and 5 rows of sockets on the top and bottom. The 5 sockets in the same column are connected to each other, while the columns and the parts above and below the groove are not connected. The appearance and structure are shown below:

The connection holes of the wide strip in the middle are divided into upper and lower parts, which are the main working area of the breadboard, used for inserting components and jumper wires. The 5 sockets in the same column (i.e., a-b-c-d-e, f-g-h-i-j) are connected to each other; the columns and the parts above and below the groove are not connected. When doing experiments, usually a small unit composed of two narrow strips and one wide strip is used. The main part of the circuit is built on the wide strip, one row of the upper narrow strip is used as the power supply, and one row of the lower narrow strip is used as ground. The middle wide strip is used to connect the circuit. Because the parts above and below the groove are not connected, integrated circuits are generally inserted across the groove.
(4) Power Supply
The ESP32 needs a 3.3V-5V power supply. In this project, we connect the ESP32 and the computer via a USB cable.

4. Project Wiring Diagram:
First, cut off all power to the ESP32. Then build the circuit according to the wiring diagram. After the circuit is built and verified to be correct, connect the ESP32 to the computer via a USB cable.
Note: Avoid any possible short circuits (especially connecting 3.3V and GND)!
Warning: A short circuit may cause a large current in the circuit, overheat the components, and cause permanent damage to the hardware.

Note:
How to connect an LED

How to identify the five-band 220Ω resistor

5. Code Description:

Set the specified pin to "HIGH" or "LOW". Selecting "HIGH" means setting the pin to a high level, with voltage and current, so the LED lights up; selecting "LOW" means setting the pin to a low level, with no voltage and no current, so the LED does not light up.
6. Project Code:
You can open the code we provide, which is saved at (i.e., path): ..\program-code\mixly-code 。(The paths where later project codes are saved are the same, i.e., same as below。)
You can also write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, set to "LOW". -
Drag out "
" from "
" again, pin is 15, set to "HIGH".
Complete code:

7. Project Phenomenon:
After the project code is uploaded successfully, power it on via the USB cable, and the LED is lit.

Project 03 LED Blink¶
1. Project Introduction:
In this project, we will show you the LED blinking effect. We use a digital pin of the ESP32 to turn on the LED and make it blink.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Red LED*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*1 | Jumper Wires*2 | USB Cable*1 |
3. Project Wiring Diagram:
First, cut off all power to the ESP32. Then build the circuit according to the circuit diagram and wiring diagram. After the circuit is built and verified to be correct, connect the ESP32 to the computer via a USB cable.
Note: Avoid any possible short circuits (especially connecting 3.3V and GND)!
Warning: A short circuit may cause a large current in the circuit, overheat the components, and cause permanent damage to the hardware.

Note:
How to connect an LED

How to identify the five-band 220Ω resistor

4. Project Code:
You can open the code we provide: it is saved at (i.e., path): ..\program-code\mixly-code 。(The paths where later project codes are saved are the same, i.e., same as below。)
You can also write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, set to "LOW". -
Drag out "
" from "
", pin is 15, set to "HIGH". -
Drag out "
" from "
", set the delay to 500 milliseconds. -
Copy the code block "
" once, and change "HIGH" to "LOW".
Complete code:

5. Project Phenomenon:
After the project code is uploaded successfully, power it on via the USB cable, and you can see that the LED in the circuit will blink repeatedly.

Project 04 Breathing LED¶
1. Project Introduction:
In previous research, we know that an LED has an on/off state, so how do we enter an intermediate state? How to output an intermediate state to make the LED "half-bright"? This is what we will learn. A breathing LED means that the LED goes from off to on, and then from on to off, just like "breathing". So, how do we control the brightness of the LED? We will use the PWM of the ESP32 to achieve this goal.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Red LED*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*1 | Jumper Wires*2 | USB Cable*1 |
3. Component Knowledge:

Analog Signal & Digital Signal
An analog signal is a signal that is continuous in time and value. In contrast, a digital signal or discrete-time signal is a time sequence composed of a series of numbers. Most signals in life are analog signals. A familiar example of an analog signal is: the temperature throughout the day changes continuously, rather than changing abruptly from 0 to 10 in an instant. However, the value of a digital signal can change instantly. This change is represented digitally as 1 and 0 (the basis of binary code). As shown in the figure below, we can more easily see the difference between them.

In practical applications, we often use binary as digital signals, i.e., a series of 0s and 1s. Because binary signals have only two values (0 or 1), they have great stability and reliability. Finally, analog signals and digital signals can be converted into each other.
PWM:
Pulse Width Modulation (PWM) is an effective method of using digital signals to control analog circuits. Ordinary processors cannot directly output analog signals. PWM technology makes this conversion (converting digital signals into analog signals) very convenient. PWM technology uses digital pins to send square waves of a certain frequency, i.e., the output of high level and low level alternately for a continuous period of time. The total time of each group of high level and low level is generally fixed and is called a period (note: the reciprocal of the period is the frequency). The time of high-level output is usually called the pulse width, and the duty cycle is the percentage of the ratio of the pulse width (PW) to the total period (T) of the waveform. The longer the high-level output lasts, the longer the duty cycle, and the corresponding voltage in the analog signal is also higher. The figure below shows how the analog signal voltage changes between 0V-3.3V (high level is 3.3V) corresponding to a pulse width of 0%-100%.

The longer the PWM duty cycle, the higher the output power. Now that we understand this relationship, we can use PWM to control the brightness of an LED or the speed of a DC motor, etc. From the above, it can be seen that PWM is not a real analog signal, and the effective value of the voltage is equal to the corresponding analog signal. Therefore, we can control the output power of LEDs and other output modules to achieve different effects.
ESP32 and PWM
On the ESP32, the LEDC (PWM) controller has 16 independent channels, and each channel can independently control the frequency, duty cycle, and even precision. Unlike traditional PWM pins, the PWM output pins of the ESP32 are configurable, and each channel has one or more PWM output pins. The relationship between the maximum frequency and bit precision is shown in the following formula:

Where the maximum value of the bit is 31. For example: generating an 8-bit precision PWM (2ˆ8 = 256, with a range of 0 to 255), the maximum frequency is 80,000,000/255 = 312,500Hz.)
4. Project Wiring Diagram:

5. Code Description:

Set the channel for the specified pin, and the assigned value can be 0 to 255.

Set the channel of digital pin 15 to CH0(LT0), assign the value 0, so the LED goes out.

Set the channel of pin 15 to CH0(LT0), assign the value i.

Set a variable i, i gradually increases from 0 to 255, adding 5 each time, for a total of 51 times, increasing by 5 at a frequency of 10 milliseconds each time, and the LED gradually becomes brighter.

Set a variable i, i gradually decreases from 255 to 0, subtracting 5 each time, for a total of 51 times, decreasing by 5 at a frequency of 10 milliseconds each time, and the LED gradually becomes dimmer.
6. Project Code:
This project is designed to make GPIO15 output PWM, with the pulse width gradually increasing from 0% to 100%, and then gradually decreasing from 100% to 0%.
You can open the code we provide, which is saved at (i.e., path): ..\program-code\mixly-code 。(The paths where later project codes are saved are the same, i.e., same as below。)
You can also write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, channel is set to CH0(LT0), assign the value 0. -
Drag out "
" from "
", change from 1 to 10 with step 1 to from 0 to 255 with step 5. -
Drag out "
" from "
" and put it into "
", pin is 15, channel is set to CH0(LT0); then drag out "
" from "
" and put it at the place where the value is assigned 0. -
Drag out "
" from "
" and put it into "
", set the delay to 10 milliseconds. -
Copy the code block "
" once, change from 0 to 255 with step 5 to from 255 to 0 with step -5.
Complete code:

7. Project Phenomenon:
After the project code is uploaded successfully, power it on via the USB cable, and you can see that the LED in the circuit gradually becomes brighter from dim, and then gradually becomes dimmer from bright, just like breathing.

Project 05 Traffic Light¶
1. Project Introduction:
Traffic lights are very common in our daily lives. According to certain time rules, traffic lights are composed of three colors: red, yellow, and green. Everyone should obey traffic rules, which can avoid many traffic accidents. In this project, we will use ESP32 and some LEDs (red, yellow, green) to simulate traffic lights.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Red LED*1 | Yellow LED*1 |
![]() |
![]() |
![]() |
![]() |
| Green LED*1 | 220Ω Resistor*3 | Several Jumper Wires | USB Cable*1 |
3. Project Wiring Diagram:

4. Project Code:
You can open the code we provide, which is saved at (i.e., path): ..\program-code\mixly-code 。(The paths where later project codes are saved are the same, i.e., same as below。)
You can also write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" , "
" , "
" respectively from "
" and put them into "
", the red LED pin is 0, the yellow LED pin is 2, the green LED pin is 15, all set to "LOW".

- Copy the code block "
" once, set the red LED to "HIGH"; then drag out "
" from "
", set the delay to 5000 milliseconds; then copy the code block "
" once, with a delay of 500 milliseconds.

-
Drag out "
" from "
", change from 1 to 10 with step 1 to from 1 to 3 with step 1. -
Copy the code block "
" once and put it into "
", change the yellow LED set to "LOW" to set to "HIGH", then copy the code block "
" once and put it into "
" ,

- Copy the code block "
" once, change the red LED set to "HIGH" to "LOW", and change the green LED set to "LOW" to set to "HIGH".

- Copy the code block "
" once.
Complete code:

5. Project Phenomenon:
After the project code is uploaded successfully, power it on via the USB cable, and you will see: 1. First, the red light stays on for 5 seconds and then goes out; 2. Second, the yellow light blinks 3 times and then goes out; 3. Then, the green light stays on for 5 seconds and then goes out; 4. Continue running the above steps 1-3.

Project 06 RGB LED¶

1. Project Introduction:
An RGB LED is composed of three colors (red, green, blue), and can emit different colors by mixing these three basic colors. In this project, we will introduce the RGB LED and show you how to use the ESP32 to control the RGB LED to emit different colors of light. Even though RGB LEDs are very basic, this is also a great way to introduce yourself or others to the basics of electronics and coding.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | RGB LED*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*3 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:
Most displays follow the RGB color standard, and all colors on a computer screen are made by mixing the three colors red, green, and blue in different proportions.

This RGB LED has 4 pins, one for each color (red, green, blue) and one common cathode. To change the brightness of the RGB LED, we can use the PWM pins of the ESP. The PWM pins will give the RGB LED signals with different duty cycles to obtain different colors.
If we use three 10-bit PWMs to control the RGB LED, theoretically we can create 2^10 ×2^10 ×2^10= 1,073,741,824 (1 billion) colors through different combinations.
4. Project Wiring Diagram:

5. Code Description:

Set the common-cathode RGB LED to emit different colors of light. R, G, and B can be set to any number between 0 and 255.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", R pin is 0, G pin is 2, B pin is 15, and the values of R, G, and B are all assigned 0.

-
Drag out "
" from "
", change from 1 to 10 with step 1 to from 0 to 255 with step 1. -
Copy the code block "
" once and put it into "
", then drag out "
" from "
" and put it at the 0 after R (0 ~ 255); then drag out "
" from "
" and put it at the 0 after G (0 ~ 255), change " + " to " - ", change the 1 before " - " to 128, and replace the 1 after " - " with variable i; then copy the code block "
" and put it at the 0 after G (0~255), change 128 to 255; then delay 10 milliseconds.

- Copy the code block "
" once, change from 0 to 255 with step 1 to from 255 to 0 with step -1.

Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that the RGB LED begins to display random colors.

Project 07 Flowing Light¶
1. Project Introduction:
In daily life, we can see many billboards composed of LEDs of different colors. They constantly change their lights (like flowing water) to attract customers' attention. In this project, we will use the ESP32 to control 10 LEDs to achieve the effect of flowing light.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Red LED*10 |
![]() |
![]() |
![]() |
| 220Ω Resistor*10 | Several Jumper Wires | USB Cable*1 |
3. Project Wiring Diagram:

4. Project Code:
This project is to design and make a flowing light. These are the actions: first turn on LED #1, then turn it off. Then turn on LED #2, then turn it off... and repeat the same operation for all 10 LEDs until the last LED is turned off. This process repeats to achieve the "movement" of flowing water.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
First drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it into "
", change "item" to " i ".

- Drag out "
" from "
" and put it into "
", change from 1 to 10 with step 1 to from 12 to 22 with step 1.

- First drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it at "Pin 0 ", change " HIGH " to " LOW ".

- First drag out "
" from "
", change from 1 to 10 with step 1 to from 12 to 22 with step 1; then drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it at "Pin 0 "; add a delay of 200 milliseconds.

- Copy the code block "
" once, change from 12 to 22 with step 1 to from 22 to 12 with step -1, and change " HIGH " to " LOW ".

Complete code:

5. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that the 10 LEDs will light up from right to left, and then return from left to right.


Project 08 One-Digit Seven-Segment Display¶
1. Project Introduction:
A seven-segment display is an electronic display device used to display decimal digits, and is widely used in digital clocks, electronic instruments, basic calculators, and other electronic devices that display digital information. Even the bombs we see in movies have seven-segment displays. Perhaps seven-segment displays do not look modern enough, but they are a substitute for more complex dot-matrix displays and are easy to use in limited light conditions and under strong sunlight. In this project, we will use the ESP32 to control a one-digit display to show numbers.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | One-Digit Seven-Segment Display*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*8 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

One-digit seven-segment display principle: A segment display is a semiconductor light-emitting device. Its basic unit is a light-emitting diode (LED). Segment displays can be divided into 7-segment displays and 8-segment displays according to the number of segments. An 8-segment display has one more LED unit than a 7-segment one (used for decimal point display). Each segment of the seven-segment LED display is an individual LED. According to the wiring method of the LED units, segment displays can be divided into common-anode segment displays and common-cathode segment displays.
In a common-cathode 7-segment display, all the cathodes (or negative poles) of the segment LEDs are connected together, and you should connect the common cathode to GND. To light up a segment LED, you can set its associated pin to HIGH.
In a common-anode 7-segment display, the anodes (positive poles) of all segment LEDs are connected together, and you should connect the common anode to +5V. To light up a segment LED, you can set its associated pin to LOW.

Each segment of the display is composed of an LED. So when you use it, you also need to use a current-limiting resistor. Otherwise, the LED will be burned out. In this experiment, we use an ordinary common-cathode one-digit segment display. As we mentioned above, you should connect the common cathode to GND. To light up a segment LED, you can set its associated pin to HIGH.
4. Project Wiring Diagram:
Note: The direction of the seven-segment display inserted into the breadboard is the same as that in the wiring diagram, with one more dot in the lower right corner.


5. Code Description:

Initialize the pins of the one-digit segment display, the two-dimensional array, etc.

This is the one-digit segment display command block for displaying digits, which can display a 1-digit number: 0 to 9.
6. Project Code:
The digital display is divided into 7 segments, and the decimal point display is divided into 1 segment. When displaying certain numbers, the corresponding segments will be lit. For example, when displaying the number 1, segments b and c will be turned on.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
". -
Drag out "
" from "
", change the number 0 to 9. -
Drag out "
" from "
", set the delay to 1000 milliseconds. -
Copy the code block "
" 9 times, and change the number 9 to 8, 7, 6, 5, 4, 3, 2, 1, 0 respectively.
Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that the one-digit segment display will display the numbers from 9 to 0.

Project 09 Four-Digit Seven-Segment Display¶
1. Project Introduction:
A four-digit segment display is a very practical display device. The display of electronic clocks, scorekeepers on sports fields, and the number of people in parks all need it. Due to its low price and ease of use, more and more projects will use 4-digit segment displays. In this project, we use the ESP32 to control a four-digit segment display to show numbers.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Four-Digit Seven-Segment Display*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*8 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

Four-digit segment display: Four-digit segment displays come in two types, common-anode and common-cathode. The display principle is similar to that of a one-digit display: 8 GPIO ports control the display segments of the display, i.e., 8 LED lights. However, here it is 4 digits, so 4 additional GPIO ports are needed to control the digit selection terminals, i.e., to select which individual digit is lit. The digit switching is very fast, and the naked eye cannot distinguish it, so it looks like multiple digits are displayed at the same time.
Our four-digit segment display is common-cathode。
The figure below is the pin diagram of the 4-digit display. G1, G2, G3, and G4 are the pins that control the digits.

The figure below is the internal wiring schematic of the 4-digit display


4. Project Wiring Diagram:

5. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
- Drag out "
" from "
", change the number 0 to 3456.
Complete code:

6. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that the four-digit segment display shows the four-digit number 3456.

Project 10 8×8 Dot-Matrix Display¶
1. Project Introduction:
A dot-matrix display is an electronic digital display device that can display information on machines, clocks, public transit departure indicators, and many other devices. In this project, we will use the ESP32 to control an 8x8 LED dot matrix to display patterns.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | 8×8 Dot-Matrix Display*1 |
![]() |
![]() |
![]() |
| 220Ω Resistor*8 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:
8×8 Dot Matrix: It is composed of 64 LED lights, and there are two types, row common-anode and row common-cathode. Our module is row common-anode, that is, each row has a line connecting the positive poles of the LEDs together, and the columns connect the negative poles of the LED lights together. See the figure below:

Each LED is placed at the intersection of a row and a column. When the level of a certain row is 1 and the level of a certain column is 0, the corresponding LED will light up. If you want to light up the LED at the first point, you should set pin 9 to high level and pin 13 to low level. If you want to light up the LEDs in the first row, you should set pin 9 to high level, and set pins 13, 3, 4, 10, 6, 11, 15, and 16 to low level. If you want to light up the LEDs in the first column, set pin 13 to low level, and set pins 9, 14, 8, 12, 1, 7, 2, and 5 to high level.
The external view of the 8×8 dot-matrix display is shown below:



4. Project Wiring Diagram:

5. Code Description:

Initialize the 8×8 dot-matrix display component.

Set the number displayed on the 8×8 dot-matrix display.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
" .

- First drag out "
" from "
"; then drag out "
" from "
", set the delay to 2000 milliseconds.

- Copy the code block "
" 9 times, and change the number 0 to 1, 2, 3, 4, 5, 6, 7, 8, 9 respectively.
Complete code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that the 8*8 dot-matrix display displays the numbers 0 to 9 in sequence, cycling continuously.

Project 11 Shift Register Controlling 8 LEDs¶
1. Project Introduction:
In previous projects, we have already learned how to light up an LED.
Generally, the number of IO ports on a development board is limited. If you need to control a large number of devices, there will be a situation where the IO ports are not enough. For example, in Project 2, each light requires one IO port to control it, and if you need to control many lights, the IO ports will be exhausted. To deal with this scenario, we introduce a shift register to expand the IO ports. In this project, we will use the ESP32, a 74HC595 chip, and LEDs to make a flowing light to understand the functions of the 74HC595 chip.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | 74HC595N Chip*1 | Red LED*8 |
![]() |
![]() |
![]() |
|
| 220Ω Resistor*8 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

74HC595N Chip: This chip has an 8-bit shift register and a memory, as well as a three-state output function. Simply put, its greatest role is to "use a small number of I/O ports to expand multiple output ports". Normally, controlling 8 LEDs requires occupying 8 GPIO pins of the ESP32. But through the 74HC595N, you only need to occupy 3 GPIO pins to easily control 8 outputs, and it can also be infinitely expanded through cascading.
If you want to learn more, you can look at the relevant material Click to jump

Pin Description:
| Pin: | Pin Description: |
|---|---|
| Pin 13 OE | It is an output enable pin, used to ensure whether the data of the latch is input to the Q0-Q7 pins. At low level, no high level is output. In this experiment, we directly connect it to GND to keep outputting data at low level. |
| Pin 14 SI/DS | This is the pin through which the 74HC595 receives data, i.e., the serial data input terminal. Only one bit can be input at a time, so by inputting continuously 8 times, a byte can be formed. |
| Pin 10 SCLR/MR | A pin for initializing the storage register pins. At low level, the internal storage register is initialized. In this experiment, we connect it to VCC to keep a high level. |
| Pin 11 SCK/SH_CP | The clock pin of the shift register. On the rising edge, the data in the shift register shifts backward as a whole and receives new data input. |
| Pin 12 RCK/ST_CP | The clock input pin of the storage register. On the rising edge, data is transferred from the shift register to the storage register. At this time, data is output in parallel from the Q0~Q7 ports. |
| Pin 9 SQH | The pin is a serial output pin, specially used for chip cascading, connected to the SI terminal of the next 74HC595. |
| Q0--Q7(Pin 15, Pins 1-7) | Eight-bit parallel output terminals, which can directly control the 8 segments of a segment display. |
4. Project Wiring Diagram:
Note: You need to pay attention to the insertion direction of the 74HC595N chip.


5. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
First drag out "
" from "
" 3 times and put it into "
"; then drag out "
" from "
" 3 times and put it into "
", change item to dataPin, latchPin, clockPin respectively, and change the number 0 after the corresponding assignment to 14, 12, 13.

-
Drag out "
" from "
", change from 1 to 10 with step 1 to from 0 to 255 with step 1. -
Drag out "
"、"
"、"
" respectively from "
" and put them into "
", then drag out "
"、"
"、"
"、"
"、"
" respectively from "
" and put them in the corresponding order; change the " HIGH " after the first pin latchPin to " LOW ", and change " MSB first " to " LSB first ".

- Drag out "
" from "
" and put it into "
", set the delay to 100 milliseconds.
Complete code:

6. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you can see that the 8 LEDs begin to blink in a flowing pattern.

Project 12 Active Buzzer¶
1. Project Introduction:
An active buzzer is a sound-producing component. It is widely used as a sound-producing element in computers, printers, alarms, electronic toys, telephones, timers, etc. It has an internal vibration source, and only needs a 5V power supply to continuously emit a buzzing sound. In this project, we will use the ESP32 to control the active buzzer to emit a "beep beep" sound.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Active Buzzer*1 | NPN Transistor (S8050)*1 |
![]() |
![]() |
![]() |
|
| 1KΩ Resistor*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

Active Buzzer: It has a simple oscillator circuit inside, which can convert constant direct current into pulse signals of a specific frequency. Once the active buzzer receives a high level, it will produce sound. A passive buzzer, on the other hand, is an integrated electronic buzzer without an internal vibration source, and it must be driven by a 2K-5K square wave rather than a DC signal. The appearances of these two buzzers are very similar, but the buzzer with a green circuit board is a passive buzzer, while the one with black tape is an active buzzer. A passive buzzer cannot distinguish positive polarity, while an active buzzer can. As shown below:


Transistor: Because the buzzer needs a large current, and the GPIO output capability of the ESP32 cannot meet the requirement, an NPN transistor is needed here to amplify the current. A transistor, full name: semiconductor transistor, is a semiconductor device that controls current. A transistor can be used to amplify weak signals and can also be used as a switch. It has three electrodes (pins): base (b), collector (c), and emitter (e). When current passes through "be", "ce" will allow several times the current to pass (transistor amplification), and at this time the transistor works in the amplification region. When the current through "be" exceeds a certain value, "ce" will no longer allow the current to increase, and at this time the transistor works in the saturation region. There are two types of transistors as shown below: PNP and NPN

In our kit, the PNP transistor is marked 8550 and the NPN transistor is marked 8050.
Based on the characteristics of the transistor, it is often used as a switch in digital circuits. Because the output current capability of a microcontroller is very weak, we will use a transistor to amplify the current and drive high-current components. When using an NPN transistor to drive a buzzer, the following method is usually adopted: if the GPIO outputs a high level, current will flow through R1, the transistor will conduct, and the buzzer will emit sound. If the GPIO outputs a low level, no current flows through R1, the transistor will not conduct, and the buzzer will not sound. When using a PNP transistor to drive a buzzer, the following method is usually adopted: if the GPIO outputs a low level, current will flow through R1, the transistor will conduct, and the buzzer will emit sound. If the GPIO outputs a high level, no current flows through R1, the transistor will not conduct, and the buzzer will not sound.

4. Project Wiring Diagram:

Note: The power supply for the buzzer in this circuit is 5V. Under a 3.3V power supply, the buzzer can work, but the loudness will be reduced.
5. Code Description:

Set the specified pin to "HIGH" or "LOW". Selecting "HIGH" means setting the pin to a high level, with voltage and current, so the active buzzer buzzes; selecting "LOW" means setting the pin to a low level, with no voltage and no current, so the active buzzer does not sound.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, set to "LOW". -
Drag out "
" from "
", pin is 15, set to "HIGH". -
Drag out "
" from "
", set the delay to 500 milliseconds. -
Copy the code block "
" once, change "HIGH" to "LOW".
Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you can see that the active buzzer emits a "beep beep" sound.

Project 13 Passive Buzzer¶
1. Project Introduction:
In the previous project, we studied the active buzzer, which can only emit one sound, which may make you feel monotonous. In this project, we will learn another buzzer, the passive buzzer. Unlike the active buzzer, the passive buzzer can emit sounds of different frequencies. In this project, you will use the ESP32 to control the passive buzzer to work.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Passive Buzzer*1 | NPN Transistor (S8050)*1 |
![]() |
![]() |
![]() |
|
| 1KΩ Resistor*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:
Passive Buzzer: It is an integrated electronic buzzer without an internal vibration source. It must be driven by a 2K-5K square wave rather than a DC signal. Its appearance is very similar to that of the active buzzer, but the buzzer with a green circuit board is a passive buzzer, while the one with black tape is an active buzzer. A passive buzzer cannot distinguish positive polarity, while an active buzzer can.

Transistor: Please refer to Project 12 .
4. Project Wiring Diagram:

5. Code Description:

Turn off the passive buzzer on the specified pin so that the buzzer does not sound.

Set the tone and beat of the passive buzzer sound on the specified pin.

Set the passive buzzer on the specified pin to play specific music.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15 . -
First drag out "
" from "
", pin is 15, select "Christmas Song"; then drag out "
", pin is 15. -
Drag out "
" from "
", set the delay to 2000 milliseconds. -
Copy the code block "
" once, select "Happy Birthday Song".
Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that the passive buzzer plays music.

Project 14 Small Desk Lamp¶
1. Project Introduction:
Do you know that the ESP32 can light up an LED when you press an external button? In this project, we will use the ESP32, a button switch, and an LED to make a mini desk lamp.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Button*1 |
![]() |
![]() |
![]() |
| 10KΩ Resistor*1 | Red LED*1 | 220Ω Resistor*1 |
![]() |
![]() |
![]() |
| Button Cap*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

Button: A button can control the on/off of a circuit. When the button is connected to a circuit, the circuit is open when the button is not pressed, and once the button is pressed, the circuit is closed, but it opens again after being released. But why does it only conduct when pressed? This has to start from the internal structure of the button. Before it is pressed, the current cannot pass from one end of the button to the other; when pressed, the metal piece inside the button connects the two sides to allow current to pass.
The internal structure of the button is shown in the figure:
. Before the button is pressed, 1 and 2 are conductive, and 3 and 4 are also conductive, but 1 and 3, or 1 and 4, or 2 and 3, or 2 and 4 are open (not conductive); only when the button is pressed, 1 and 3, or 1 and 4, or 2 and 3, or 2 and 4 are conductive.
When designing circuits, the button switch is one of the most commonly used components.
Button Schematic:

What is button bounce?
The switch circuit we imagine is "press the button - immediately conduct" and "press again - immediately open", but in reality it is not the case. Buttons usually use mechanical elastic switches, and at the instant when the mechanical contact opens and closes (usually about 10ms), a series of bounces will be produced due to the elastic effect, causing the button switch to not immediately and stably connect the circuit when closed, and to not completely disconnect instantly when opened.

So how do we eliminate button bounce?
There are two common debouncing methods: the software method and the hardware method. Here we will focus on the convenient and simple software method. We already know that the bounce time caused by elastic inertia is about 10ms. Using a delay command to postpone the execution time of the command can achieve the effect of debouncing.
So we added a 0.02-second delay in the code to implement the button debouncing function.

4. Project Wiring Diagram:

Note:
How to connect an LED

How to identify the five-band 220Ω resistor and the five-band 10KΩ resistor


5. Code Description:

Read the digital signal (high/low level) of the button switch from the specified digital pin.

The value of a Boolean (bool) variable has only true (true) and false (false). In C++, if the value is non-zero, it is True, and if it is zero, it is False. Here we can know that the initial value of ledState is 0.

Invert the current value of ledState and then assign it back to ledState itself.

The role of the delay here is debouncing by software method. When the mechanical contacts of the button open and close, due to the elastic effect of the contacts, the button switch will not be stably connected immediately or disconnect all at once, and a series of bounces accompany the instant of closing and opening. The measure taken to prevent this phenomenon is button debouncing. In the code, after detecting that the key is closed, a delay program is executed, a 10ms delay, to make the leading-edge bounce disappear and then detect the state of the key again. If it still maintains the closed state level, it is confirmed that a key is really pressed.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 4, set to "LOW".

- First drag out "
" from "
" and put it into "
", change " Integer " to "Boolean", change "item" to "ledState"; then drag out "
" from "
" and put it into "
", select "false".

- First drag out "
" from "
"; then drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it on the left side of " = ", pin is 15; finally drag out "
" from "
" and put it on the right side of " = ".

- Drag out "
" from "
", set the delay to 10 milliseconds.

- First copy the code block "
" once, change the delay of 10 milliseconds to 200 milliseconds; then copy the code block "
" once, change the number 0 to 1.

- Copy the code block "
" once, remove the 10-millisecond delay, then drag out "
" from "
", then drag out "
" from "
", and finally drag out "
" from "
".

- Drag out "
" from "
", pin is 4, and drag out "
" from "
" and put it at "HIGH".

Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that: when the button is pressed, the LED lights up; when the button is released, the LED remains on. Press the button again, and the LED goes out; when the button is released, the LED remains off. Isn't it just like a small desk lamp?

Project 15 Simulated Hourglass¶
1. Project Introduction:
Ancient people did not have electronic clocks, so they invented the hourglass to measure time. The two sides of the hourglass have relatively large capacity, with fine sand loaded in one side and a very small channel in the middle. When the hourglass is placed upright with the side containing fine sand on top, due to gravity, the fine sand flows down through the channel to the other side of the hourglass. When all the fine sand has flowed to the bottom, it is turned upside down, and the number of times it is turned over in a day is recorded. The next day, the approximate time of that day can be known through the number of times the hourglass flows back and forth. In this lesson, we will use the ESP32 to control a tilt switch and an LED light to simulate an hourglass and make an electronic hourglass.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Tilt Switch*1 | 10KΩ Resistor*1 |
![]() |
![]() |
![]() |
![]() |
| Red LED*4 | 220Ω Resistor*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

A tilt switch is also called a digital switch or ball switch, and there is a metal ball inside it. It is used to detect tilting at small angles.
The principle is very simple: when the switch tilts at a certain angle, the ball inside rolls down and contacts the two contacts connected to the external pins, thereby triggering the circuit. Otherwise, the ball stays away from the contacts, thereby opening the circuit.
The internal structure of the tilt switch is used here to explain how it works, as shown in the figure below:

4. Project Wiring Diagram:

Note:
How to connect an LED

How to identify the five-band 220Ω resistor and the five-band 10KΩ resistor


5. Code Description:

Read the digital signal (high/low level) of the tilt switch from the specified digital pin.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
". -
First drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it into "
", change " Integer " to "Byte", change "item" to "switch_state".

- First drag out "
" from "
", then drag out "
" from "
", pin is 15.

- First drag out "
" from "
", then drag out "
" from "
".

- First drag out "
" from "
"; then drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it on the left side of " = "; finally drag out "
" from "
" and put it on the right side of " = ".

- First drag out "
" from "
" and put it into "
" , change from 1 to 10 with step 1 to from 16 to 19 with step 1; then drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it at "Pin 0 "; add a delay of 500 milliseconds.

- Copy the code block "
" once, change the number 0 on the right side of " = " to 1, change from 16 to 19 with step 1 to from 19 to 16 with step -1, and change " HIGH " to " LOW ".

Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that: when the breadboard is tilted to a certain angle, the LEDs will light up one by one. When returning to the previous angle, the LEDs will turn off one by one. Just like an hourglass, as time goes by, the sand leaks out.

Project 16 Anti-Theft Alarm¶
1. Project Introduction:
A human body infrared sensor measures the thermal infrared (IR) rays emitted by moving objects. This sensor can detect the movement of people, animals, and cars, thereby triggering security alarms and lighting. They are used to detect movement and are ideal for security, such as anti-theft alarms and security lighting systems. In this project, we will use the ESP32 to control a human body infrared sensor, a buzzer, and an LED to simulate an anti-theft alarm.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Human Body Infrared Sensor*1 | NPN Transistor (S8050)*1 |
![]() |
![]() |
![]() |
![]() |
| Active Buzzer*1 | Red LED*1 | 220Ω Resistor*1 | 1KΩ Resistor*1 |
![]() |
![]() |
![]() |
|
| 3P to Dupont Line Male Single*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:
Human Body Infrared Sensor: It is a human body infrared sensor based on the pyroelectric effect, which can detect infrared rays emitted by the human body or animals, and combined with a Fresnel lens it can make the detection range of the sensor farther and wider. It mainly uses the RE200B-P sensor element. When a person or animal is moving nearby, the module will output a high level 1; otherwise it outputs a low level 0. Pay special attention: this sensor can detect people, animals, and cars in motion, but cannot detect stationary people, animals, and cars, and the farthest detection distance is about 7 meters.
Note: The human body infrared sensor should avoid direct irradiation from sunlight, car headlights, and incandescent lamps, and should not face heat sources (such as radiators, heaters) or air conditioners, to avoid false alarms caused by large changes in ambient temperature. It is also easily affected by radio frequency radiation interference.
Sensor Technical Parameters:
Maximum input voltage: DC 5-15V
Maximum operating current: 50MA
Maximum power: 0.3W
Quiescent current: <50uA
Operating temperature: -20 ~ 85℃
Control signal: digital signal (1/0)
Delay time: about 2.3 to 3 seconds
Sensing angle: less than 100-degree cone angle
Farthest detection distance: about 7 meters
Sensor Schematic:

4. Project Wiring Diagram:

5. Code Description:

Read the digital signal (high/low level) of the human body infrared sensor from the specified digital pin, which is used to detect whether there is a person or animal moving nearby. If a person or animal moving nearby is detected, it outputs a high level 1; otherwise, it outputs a low level 0.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
". -
First drag out "
" from "
" and put it into "
", change " Integer " to "Byte", change "item" to "pirStat"; then drag out "
" from "
" and put it into "
".

- First drag out "
" from "
", then drag out "
" from "
", pin is 15.

- First drag out "
" from "
", then drag out "
" from "
".

- First drag out "
" from "
"; then drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it on the left side of " = "; finally drag out "
" from "
" and put it on the right side of " = ", change the number 0 to 1.

- Drag out "
" and "
" respectively from "
" and put them into "
", the red LED pin is 0, the active buzzer pin is 2; then drag out "
" from "
", set the delay to 500 milliseconds.

- Copy the code block "
" once and put it into "
", change both " HIGH " to " LOW ".

- Copy the code block "
" once, change the number 1 on the right side of "=" to 0, delete the code block "
" and the 2 delay blocks of 500 milliseconds.

Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that: if the human body infrared sensor detects that someone is moving nearby, the buzzer will continuously emit an alarm, and the LED will continuously blink.

Project 17 OLED Display¶
1. Project Introduction:
In life, we can use modules such as displays to do various experiments. You can also DIY various small objects. For example, use a temperature sensor and a display to make a temperature tester, or use an ultrasonic module and a display to make a distance tester. Below, we will use the LCD_128X32_DOT module as the display and connect it to the ESP32 control board. We will use the ESP32 board to control the LCD_128X32_DOT display to show various English text, common symbols, and numbers.
Note: We have upgraded the LCD screen in the accessories to the more commonly used OLED screen. The documentation is being updated continuously. If you find that the code does not run correctly, please contact customer service to fix it.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | OLED Screen*1 |
![]() |
![]() |
|
| Male-Female Dupont Wires*4 | USB Cable*1 |
3. Component Knowledge:

LCD_128X32_DOT: An LCD module with a resolution of 128*32 pixels, whose driver chip is ST7567A. The module uses IIC communication, and it can display not only English letters and symbols, but also Chinese characters and patterns. When in use, you can also set it in the code to display English letters and symbols in different sizes.
LCD_128X32_DOT Schematic:

LCD_128X32_DOT Technical Parameters:
Display pixels: 128*32 characters
Operating voltage: DC 5V
Operating current: 100mA (5V)
Module optimal operating voltage: 5V
Brightness and contrast can be controlled by program instructions
4. Project Wiring Diagram:

6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
- The display control position is as follows, drag it out directly for use:

- The complete code is as follows:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: the first line of the 128X32LCD module display shows "Hello World!", the second line shows "0123456789", and the third line shows "Using SoftI2C".

Project 18 Small Fan¶
1. Project Introduction:
In the hot summer, we need an electric fan to cool us down. So in this project, we will use the ESP32 to control a DC motor and a small fan blade to make a small electric fan.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|
| ESP32*1 | Breadboard*1 | DC Motor*1 | Breadboard Power Module*1 | 6-AA Battery Holder*1 |
![]() |
![]() |
![]() |
![]() |
![]() |
| IC L293D*1 | Fan Blade*1 | Several Jumper Wires | AA Battery(Bring your own)*6 | USB Cable*1 |
3. Component Knowledge:

L293D chip: The L293D is a DC motor driver IC, which can be used to drive DC motors or stepper motors in some robotic projects. It has 16 pins in total and can drive two DC motors at the same time. Input voltage range: 4.5 V ~ 36 V, output current per channel: MAX 600mA, it can drive inductive loads. In particular, its input terminals can be directly connected to the main control board, making it very convenient to be controlled by the main control board. When driving small DC motors, it can directly control two motors, and can realize forward and reverse rotation of the motors. To realize this function, you only need to change the high/low level of the input terminals. There are many motor driver boards using the L293D chip on the market, and of course we can also use it through simple connections ourselves.
L293D Pin Diagram:
|Pin No.| Pin Name | Description |
| :--: | :--: | :--: |
| 1 | Enable1 | This pin enables input pins Input 1(2) and Input 2(7) |
| 2 | In1 | Directly controls output 1 pin, controlled by digital circuit |
| 3 | Out1 | Connected to one end of Motor 1 |
| 4 | 0V | Ground pin connected to the circuit ground (0V) |
| 5 | 0V | Ground pin connected to the circuit ground (0V) |
| 6 |Out2 | Connected to the other end of Motor 1 |
| 7 | In2 | Directly controls output 2 pin, controlled by digital circuit |
| 8 | +V motor | Connected to the voltage pin running the motor (4.5V to 36V) |
| 9 | Enable2 |This pin enables input pins Input 3(10) and Input 4(15) |
| 10 | In3 | Directly controls output 3 pin, controlled by digital circuit|
| 11 | Out3 | Connected to one end of Motor 2 |
| 12 | 0V | Ground pin connected to the circuit ground (0V) |
| 13 | 0V | Ground pin connected to the circuit ground (0V) |
| 14 | Out4 | Connected to the other end of Motor 2 |
| 15 |In4 | Directly controls output 4 pin, controlled by digital circuit|
| 16 | +V | Connected to +5V to enable IC functions |
Breadboard Power Module:

Description:
This module can conveniently provide 3.3V and 5V power to the breadboard, with a DC2.1 input (DC7-12V), and also has a USB Type C interface power input.
Specifications:
Input voltage: DC socket: 7-12V; Type C USB: 5V
Current: 3.3V: max 500mA; 5V: max 500mA;
Maximum power: 2.5W
Dimensions: 53mmx26.3mm
Environmental attribute: ROHS
Interface Description:

Motor Wiring Description:
Because the current batch of motors uses a standard interface that cannot be directly inserted into the breadboard, please use two Dupont wires to insert into the white interface to complete this experiment.

Schematic:

4. Project Wiring Diagram:

(Note: First connect the wires, then install a small fan blade on the DC motor.)
5. Code Description:


These 2 command blocks can both be used to set the DC motor (small fan) to not rotate.

Set the DC motor (small fan) to rotate counterclockwise.

Set the DC motor (small fan) to rotate clockwise.

Set ledc channel 0, frequency to 1200, PWM resolution to 8, duty cycle to 256; bind ledc channel 0 to the specified ENA_pwm pin IO0 for output.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
" , INA pin is 2, INB pin is 15, change "HIGH" to "LOW" all.

- Drag out "
" from "
" and put it into "
" , analog output pin is 0, channel is CHO(LT0), assign the value 0.

- Copy the code block "
" once, change the "LOW" after INB to "HIGH", change the value 0 after analog output pin 0 to 250; then drag out "
" from "
", set the delay to 5000 milliseconds.

- Copy the code block "
" once, change the value 250 after analog output pin 0 to 0, change the delay of 5000 milliseconds to 2000 milliseconds.

- Copy the code block "
" once, change INA "LOW" INB "HIGH" to INA "HIGH" INB "LOW", keep the others unchanged.

Complete code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, connect the external power supply. After powering on, you will see that: the small fan first rotates counterclockwise for 5 seconds, stops for 2 seconds, then rotates clockwise for 5 seconds, stops for 2 seconds, and repeats in this pattern.

Project 19 Servo¶
1. Project Introduction:
A servo is a motor that can rotate very precisely. It has been widely used in toy cars, remote-control helicopters, airplanes, robots, and other fields. In this project, we will use the ESP32 to control the rotation of the servo.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Servo*1 |
![]() |
![]() |
|
| Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

Servo: A servo is a position-servo driver, mainly composed of a shell, a circuit board, a coreless motor, gears, and a position detector. Its working principle is that a signal is sent to the servo by the receiver or microcontroller. There is a reference circuit inside, which generates a reference signal with a period of 20ms and a width of 1.5ms. The obtained DC bias voltage is compared with the voltage of the potentiometer to obtain the voltage difference output. The IC on the circuit board judges the rotation direction, and then drives the coreless motor to start rotating. The power is transmitted to the swing arm through the reduction gears, and the position detector sends back a signal to determine whether the positioning has been reached. It is suitable for control systems that require the angle to change continuously and can be maintained. When the motor speed is constant, the potentiometer is driven to rotate through the cascaded reduction gears, so that the voltage difference becomes 0 and the motor stops rotating. Generally, the rotation angle range of a servo is from 0 degrees to 180 degrees.
The pulse period for controlling the servo is 20ms, and the pulse width is 0.5ms ~ 2.5ms, corresponding to positions from -90° to +90°. The following takes a 180° servo as an example:

Servos have various specifications, but they all have three connecting wires, which are brown, red, and orange (different brands may have different colors). Brown is GND, red is the positive power supply, and orange is the signal line.

4. Project Wiring Diagram:
When powering the servo, please note that the power supply voltage should be 3.3V-5V. Please make sure that there is no error when connecting the servo to the power supply.

5. Code Description:

Set the rotation angle and delay of the servo on the specified pin.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, angle is 0, delay 200 milliseconds.

- First drag out "
" from "
" and change from 1 to 10 with step 1 to from 0 to 180 with step 1; then drag out "
" from "
" and put it into "
" , pin is 15; then drag out "
" from "
" and put it at "Angle 0 "; delay 15 milliseconds.

- Copy the code block "
" once, change from 0 to 180 with step 1 to from 180 to 0 with step -1.

Complete code:

6. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that: the servo will rotate from 0° to 180°, then reverse direction so that it rotates from 180° to 0°, and repeat these actions in an infinite loop.

Project 20 Stepper Motor¶
1. Project Introduction:
Stepper motors are accurate in positioning and are the most important components in mechanical equipment such as industrial robots, 3D printers, and large lathes. In this project, we will use the ESP32 to control the ULN2003 stepper motor driver board to drive the stepper motor to rotate.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | ULN2003 Stepper Motor Driver Board*1 |
![]() |
![]() |
![]() |
| Breadboard Power Module*1 | 6-AA Battery Holder*1 | Stepper Motor*1 |
![]() |
![]() |
![]() |
| Several Male-Female Dupont Wires | AA Battery(Bring your own)*6 | USB Cable*1 |
3. Project Knowledge:

Stepper Motor: It is a motor controlled by a series of electromagnetic coils. It can rotate by precise degrees (or steps) as needed, allowing you to move it to a precise position and hold that position. It does this by powering the coils inside the motor for a very short time, but you must keep powering the motor to keep it at the position you want. There are two basic types of stepper motors, unipolar steppers and bipolar steppers. In this project, we are using the unipolar stepper motor 28-BYJ48.

28BYJ-48 Stepper Motor Working Principle:
A stepper motor is mainly composed of a stator and a rotor. The stator is fixed, as shown in the figure below, the part wound with the A, B, C, and D coil groups. When the coil group is energized, it generates a magnetic field; the rotor is the rotating part, the part in the middle of the stator in the figure below, and its two poles are permanent magnets.
The rotation principle of single-step 4-beat: at first, coil group A conducts, and the two poles of the rotor face coil group A directly; then coil group A disconnects and coil group B conducts, and the rotor rotates clockwise to coil group B, the rotor turns one step; B disconnects, C conducts, and the rotor turns to coil group C; C disconnects, D conducts, and the rotor turns to coil group D; D group disconnects, A group conducts, and the rotor turns to coil group A. In this way, the rotor has turned half a circle, 180 degrees. Then repeat once more, B-C-D-A, and the rotor turns back to coil group A. In this way, the rotor has turned one full circle, a total of 8 steps. As shown in the figure below, this is the principle of single-beat rotation of a stepper motor A - B - C - D - A ....
If you want the stepper motor to rotate counterclockwise, just reverse the beat order: D - C - B - A - D .....

The half-step 8-beat rotation principle: 8 beats use the single-double beat form, A - AB - B - BC - C - CD - D - DA - A ...... , so that one beat of operation makes the rotor turn only half a step. For example, when coil group A conducts, the rotor turns to face coil group A directly; then coil groups A and B conduct together, so the place where the magnetic field is strongest is in the middle of coil groups A and B, and the two poles of the rotor will turn to the middle of coil groups A and B, i.e., rotate half a step clockwise.
Stepper Motor Parameters:
The stepper motor we provide needs to rotate 32 steps for the rotor to turn one full circle, and it also goes through a 1:64 reduction gear set to drive the output shaft, so the output shaft needs: 32 * 64 = 2048 steps to turn one full circle.
Voltage 5V, 4-phase stepper motor, the step angle of the 4-beat mode is 11.25, the step angle of the 8-beat mode is 5.625, and the reduction ratio is 1:64.
ULN2003 Stepper Motor Driver Board: The ULN2003 stepper motor driver converts weak signals into stronger control signals, thereby driving the stepper motor.
The schematic below shows how to connect a unipolar stepper motor to the pins of the ESP32 using the ULN2003 stepper motor driver board interface, and shows how to use four TIP120 interfaces.

4. Project Wiring Diagram:
Jumper the power module to 5V, connect the stepper motor driver board VCC to the breadboard 5V, and GND to the breadboard GND;
Connect the development board pin 5v to the breadboard 5V, GND to the breadboard GND, or power it directly via USB.
| Development Board Pin | Motor Driver Board Pin |
|---|---|
| 15 | IN1 |
| 16 | IN2 |
| 17 | IN3 |
| 18 | IN4 |

5. Code Description:

Initialize the pins of the stepper motor, the setting of steps and speed.

Set the number of steps the stepper motor moves, the positive and negative values are related to the rotation direction.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin 1# is 15, pin 2# is 16, pin 3# is 17, pin 4# is 18, set the number of steps to 100, set the speed to 200.

- First drag out "
" from "
", set the number of moving steps to -2048; then drag out "
" from "
", set the delay to 1000 milliseconds.

- Copy the code block "
" once, change -2048 to 2048.

Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, connect the external power supply. After powering on, you will see that: the four LEDs D1, D2, D3, and D4 on the ULN2003 driver module light up, the stepper motor rotates, and this state is maintained in a loop.

Project 21 Relay¶
1. Project Introduction:
In daily life, we generally use alternating current to drive electrical equipment, and sometimes we use switches to control appliances. If a switch is connected directly to an AC circuit, once there is a leakage, people will be in danger. From the perspective of safety, we specially designed this relay module with an NO (normally open) terminal and an NC (normally closed) terminal. In this lesson, we will learn a relatively special and useful switch, which is the relay module.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Relay Module*1 | Red LED*1 |
![]() |
![]() |
![]() |
![]() |
| 3P to Dupont Line Male Single*1 | USB Cable*1 | 220Ω Resistor*1 | Several Jumper Wires |
3. Component Knowledge:
Relay: It mainly uses the HK4100F-DC 5V-SHC relay component. The relay has 3 terminals for external circuits, which are the NO, COM, and NC terminals (silk-screened on the back).
Normally Open (NO): This pin is normally open, unless a signal is provided to the signal pin of the relay module. Therefore, the common contact pin disconnects its connection through the NC pin and establishes a connection through the NO pin.
Common Contact (COM): This pin is used to connect other modules/components, such as an LED.
LED:
Normally Closed (NC): This NC pin is connected through the COM pin to form a closed circuit. The relay module can be controlled by a development board such as the ESP32 to switch between closed and open.
When the relay has no control signal connected, the COM terminal and the NC terminal are connected, and the COM terminal and the NO terminal are disconnected. When controlling, connect G to the GND of the control board, V to the 5V of the control board, and S to the digital port of the control board. When the S signal terminal is set to high level, the relay turns on, the relay COM terminal and NC terminal disconnect, and the COM terminal and NO terminal connect; when the S signal terminal is set to low level, the relay turns off, the relay COM terminal and NC terminal connect, and the COM terminal and NO terminal disconnect.
- Operating voltage: 5V (DC)
- Operating current: ≤50MA
- Maximum power: 0.25W
- Input signal: digital signal
- Contact current: <3A
Relay Schematic:

4. Project Wiring Diagram:

5. Code Description:

Set the specified pin to "HIGH" or "LOW". Selecting "HIGH" means setting the pin to a high level, with voltage and current, so the relay pulls in; selecting "LOW" means setting the pin to a low level, with no voltage and no current, so the relay opens.
6. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", pin is 15, set to "LOW". -
Drag out "
" from "
", pin is 15, set to "HIGH". -
Drag out "
" from "
", set the delay to 500 milliseconds. -
Copy the code block "
" once, change "HIGH" to "LOW".
Complete code:

7. Project Phenomenon:
After the code is uploaded successfully, power it on via the USB cable, and you will see that: the relay will cycle on and off, turning on for 1 second while the LED lights up for 1 second, and turning off for 1 second while the LED goes out for 1 second. At the same time, you can hear the sound of the relay turning on and off, and you can also see the indicator light on the relay showing the change of state.

Project 22 Dimming Light¶
1. Project Introduction:
A potentiometer is a three-terminal resistor with a sliding or rotating contact, which forms an adjustable voltage divider. Its working principle is to change the position of the sliding contact on a uniform resistor. In a potentiometer, the entire input voltage is applied across the entire length of the resistor, and the output voltage is the voltage value between the fixed contact and the sliding contact. In this project, we will learn to use the ESP32 to read the value of the potentiometer, and combine it with an LED to make a dimming light.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Adjustable Potentiometer*1 | Red LED*1 |
![]() |
![]() |
![]() |
|
| 220Ω Resistor*1 | USB Cable*1 | Several Jumper Wires |
3. Component Knowledge:

Adjustable Potentiometer: The adjustable potentiometer is a type of resistor and analog electronic component, with two states 0 and 1 (high level and low level). The analog value is different, and its data state presents a linear state such as 1 to 1024.
ADC: ADC is an electronic integrated circuit used to convert analog signals (such as voltage) into digital or binary form composed of 1s and 0s. The range of the ADC on our ESP32 is 12 bits, which means the resolution is 2^12=4096, and it means a range (3.3V) will be evenly divided into 4096 parts. The range of analog values corresponds to the ADC value. Therefore, the more bits the ADC has, the denser the analog partition, and the higher the precision of the final conversion.

Section 1: The analog quantity in the range of 0V—(3.3/4095)V corresponds to the digital 0;
Section 2: The analog quantity in the range of (3.3/4095)V—2*(3.3/4095)V corresponds to the digital 1;
......
The following analog will be divided accordingly. The conversion formula is as follows:

DAC: The reversibility of this process requires a DAC, a digital-to-analog converter. Digital I/O ports can output high and low levels (0 or 1), but cannot output intermediate voltage values, which is where the DAC is useful. The ESP32 has two 8-bit precision DAC output pins, GPIO25 and GPIO26, which can divide VCC (here 3.3V) into 2^8=256 parts. For example, when the digital quantity is 1, the output voltage value is 3.3/256×1V, and when the digital quantity is 128, the output voltage value is 3.3/256 ×128=1.65V. The higher the precision of the DAC, the higher the precision of the output voltage value.
The conversion formula is as follows:

ADC on the ESP32 Board:
The ESP32 has 16 pins that can be used to measure analog signals. The GPIO pin sequence numbers and analog pin definitions are shown in the table below:

DAC on the ESP32 Board:

4. Read the Analog Value of the Potentiometer:
We connect the potentiometer to the analog IO port of the ESP32 to read the analog value of the potentiometer. Please refer to the following wiring diagram for wiring:

Code Description:

Read the analog signal of the rotary potentiometer from the specified analog pin, and the range of the analog signal is: 0 to 4095.
For detailed understanding, please refer to the link: https://vimsky.com/examples/usage/arduino-language-functions-analog-io-analogread-ar.html 。

Map the analog signal of the rotary potentiometer (0 to 4095) to the brightness of the LED (0 to 255).
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
"; then drag out "
" from "
", pin is 36. -
Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the analog value of the potentiometer, and when you turn the potentiometer handle, the analog value changes.

5. Wiring Diagram of the Dimming Light:
In the previous step, we read the analog value of the potentiometer. Now we need to convert the ADC value of the potentiometer into the brightness of the LED, to make a light with adjustable brightness. See the wiring diagram below:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: when you turn the potentiometer handle, the brightness of the LED will change accordingly.

Project 23 Flame Alarm¶
1. Project Introduction:
Fire is a terrible disaster, and fire alarm systems are very useful in houses, commercial buildings, and factories. In this project, we will use the ESP32 to control a flame sensor, a buzzer, and an LED to simulate a fire alarm device. This is a meaningful maker activity.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Flame Sensor*1 | Red LED*1 |
![]() |
![]() |
![]() |
![]() |
| Active Buzzer*1 | 220Ω Resistor*1 | 10KΩ Resistor*1 | Several Jumper Wires |
![]() |
![]() |
![]() |
|
| NPN Transistor (S8050)*1 | 1kΩ Resistor*1 | USB Cable*1 |
3. Component Knowledge:

Flame Sensor (Infrared Receiving Triode): A flame emits a certain amount of IR light, which is invisible to the human eye, but our infrared receiving triode can detect it and remind the microcontroller (such as ESP32) that a fire has been detected. The infrared receiving triode can detect flames and then convert the flame brightness into a fluctuating level signal. The short pin of the infrared receiving triode is the negative pole, and the other long pin is the positive pole. We should connect the short pin (negative pole) to 5V, and connect the long pin (positive pole) to the analog pin, a resistor, and GND. As shown in the figure below:

Note: The flame sensor should avoid direct irradiation from sunlight, car headlights, and incandescent lamps, and should not face heat sources (such as radiators, heaters) or air conditioners, to avoid false alarms caused by large changes in ambient temperature. It is also easily affected by radio frequency radiation interference.
4. Read the Analog Value of the Flame Sensor:
We first use a simple code to read the analog value of the flame sensor and print it out. Please refer to the following wiring diagram for wiring:

Code Description:

Read the analog signal of the flame sensor from the specified analog pin, and the range of the analog signal is: 0 to 4095.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
"; then drag out "
", pin is 36. -
Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the analog value read by the flame sensor. When the flame approaches the flame sensor, the analog value increases; conversely, the analog value decreases.

5. Wiring Diagram of the Flame Alarm:
Next, we will use the flame sensor, buzzer, and LED to make an interesting project - a fire alarm device. When the flame sensor detects a flame, the LED blinks and the buzzer alarms.

6. Project Code:
(Note: The threshold value 500 in the code can be reset according to the actual situation)

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: when the flame sensor detects a flame, the LED blinks and the buzzer alarms; otherwise, the LED does not light up and the buzzer does not sound.

Project 24 Night Light¶
1. Project Introduction:
Sensors or components are ubiquitous in our daily lives. For example, some public street lights automatically turn on at night and automatically turn off during the day. Why? In fact, these all use a photosensitive component, which can sense the intensity of external ambient light. At night, when the outdoor brightness decreases, the street lights automatically turn on; during the day, the street lights automatically turn off. The principle is very simple, and in this experiment we use the ESP32 to control an LED to realize this street light effect.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Photoresistor*1 | Red LED*1 |
![]() |
![]() |
![]() |
![]() |
| 220Ω Resistor*1 | 10KΩ Resistor*1 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:

Photoresistor: It is a photosensitive resistor. The principle is that the photoresistor receives brightness (light) on its surface and lowers the resistance, and the resistance value of the photoresistor changes with the intensity of the detected ambient light. With this characteristic, we can use the photoresistor to detect light intensity. The photoresistor and its electronic symbol are as follows:

The following circuit is used to detect changes in the resistance value of the photoresistor:

In the above circuit, when the resistance of the photoresistor changes due to changes in light intensity, the voltage between the photoresistor and resistor R2 also changes. Therefore, by measuring this voltage, the light intensity can be obtained. This project uses the circuit on the left side of the figure above for wiring.
4. Read the Analog Value of the Photoresistor:
We first use a simple code to read the analog value of the photoresistor and print it out. Please refer to the following wiring diagram for wiring:

Code Description:

Read the analog signal (light intensity) of the photoresistor from the specified analog pin, and the range of the analog signal is: 0 to 4095.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
"; then drag out "
", pin is 36. -
Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the analog value read by the photoresistor. When the light intensity in the environment where the photoresistor is located is gradually weakened, the analog value gradually increases; conversely, the analog value gradually decreases.

5. Wiring Diagram of the Light-Controlled Light:
We made a small dimming light before. Now let us make a light-controlled light. Their principles are the same, i.e., obtain the analog value of the sensor through the ESP32, and then adjust the brightness of the LED.

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: when the light intensity in the environment where the photoresistor is located is weakened, the LED becomes brighter, and conversely, the LED becomes dimmer.

Project 25 Human Body Induction Light¶
1. Project Introduction:
Human body induction lights are generally used in dark corridor areas. With the development of technology, the use of human body induction lights is very common in our real life. Corridors in residential communities, bedrooms in rooms, garages in underground cities, bathrooms, and other areas all use human body induction lights. Human body induction lights in real life are generally composed of a human body infrared sensor, a light, a photoresistor sensor, etc.
In this project, we will learn how to use a human body infrared sensor, an LED, and a photoresistor to make a human body induction light.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Photoresistor*1 | Red LED*1 |
![]() |
![]() |
![]() |
![]() |
| 220Ω Resistor*1 | 10KΩ Resistor*1 | Several Jumper Wires | USB Cable*1 |
![]() |
![]() |
||
| Human Body Infrared Sensor*1 | 3P to Dupont Line Male Single*1 |
3. Project Wiring Diagram:

4. Project Code:

5. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: when your hand covers the light-sensing part of the photoresistor to simulate a dark state, and then you wave your other hand in front of the human body infrared sensor, the LED lights up for 5 seconds; if the light-sensing part of the photoresistor is not covered, then waving your hand in front of the human body infrared sensor will leave the LED in the off state.

Project 26 Joystick Controlling RGB Light¶
1. Project Introduction:
A joystick module is a component with two analog inputs and one digital input. It is widely used in game operations, robot control, drone control, and other fields. In this project, we use the ESP32 and the joystick module to control RGB. In this way, you can gain a deeper understanding of the principle and operation of the joystick module in practice.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Joystick Module*1 | RGB LED*1 |
![]() |
![]() |
![]() |
![]() |
| 220Ω Resistor*3 | Several Jumper Wires | USB Cable*1 | Male-Female Dupont Wires*5 |
3. Component Knowledge:

Joystick Module: It mainly uses a PS2 handle joystick component. In fact, the joystick module has 3 signal terminal pins, simulating 3-dimensional space. The pins of the joystick module are GND, VCC, and signal terminals (VRx, VRy, SW). The signal terminals X and Y simulate the X axis and Y axis of space. When controlling, the X and Y signal terminals of the module are connected to the analog ports of the control board, and the coordinates of the object in the X and Y axes of space are controlled by controlling 2 analog input values. The signal terminal SW simulates the Z axis of space, and it is generally connected to a digital port for use as a button.
VCC is connected to the power output terminal V/VCC (3.3/5V) of the control board, and GND is connected to the G/GND of the control board. In the original state, the read voltage is about 1.65V/2.5V. For the X axis direction, when it gradually moves in the arrow direction, the read voltage value increases and can reach the maximum voltage; when it gradually moves in the opposite direction of the arrow, the read voltage value gradually decreases to the minimum voltage. For the Y axis direction, when it is gradually pressed along the arrow direction on the module, the read voltage value increases and can reach the maximum voltage; when it is gradually pressed in the opposite direction of the arrow, the read voltage value gradually decreases to the minimum voltage. For the Z axis direction, the signal terminal B is connected to a digital port, outputting 0 in the original state and 1 when pressed. In this way, we can read two analog values and the high/low level of one digital port to determine the working state of the joystick on the module.
Module Parameters:
- Input voltage: DC 3.3V ~ 5V
- Output signal: X/Y dual-axis analog value + Z-axis digital signal
- Applicable range: suitable for controlling the movement of control point coordinates in a plane, control of two-degree-of-freedom servos, etc.
- Product features: exquisite appearance, superior joystick feel, simple operation, sensitive response, and long service life.
4. Read the Value of the Joystick Module:
We must use the analog IO ports of the ESP32 to read values from the X/Y pins of the joystick module, and use a digital IO port to read the digital signal of the button. Please wire according to the following wiring diagram (because the accessory has been replaced, B=SW in the figure below):

Code Description:

Read the analog values of the joystick module in the X axis and Y axis directions.

Read the button value of the joystick module in the Z axis direction.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
", change hello to X: . -
First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
", pin is 36, select x. -
Copy the code block "
" once, change X: to Y:, select y, pin is 39. -
First copy the code block "
" once, change Y: to Z:; then drag out "
" from "
", then drag out "
" from "
", pin is 14. -
Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the current analog value and digital value of the joystick. Moving the joystick or pressing the joystick cap will change the analog value and digital value in the serial monitor window.


5. Wiring Diagram of Joystick Module Controlling RGB:
We just read the value of the joystick module. Here we need to do something with the joystick module and RGB, and connect according to the figure below:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: ① if the joystick moves to the far left in the X direction, the RGB lights red; ② if the joystick moves to the far right in the X direction, the RGB lights green; ③ if the joystick moves to the top in the Y direction, the RGB lights white; ④ if the joystick moves to the bottom in the Y direction, the RGB lights blue; ⑤ if the joystick cap is pressed, the RGB goes out.


Project 27 Temperature and Humidity Meter¶
1. Project Introduction:
In winter, the humidity in the air is very low, i.e., the air is very dry, and combined with the cold, the human skin is prone to cracking from excessive dryness. So we need to use a humidifier to add humidity to the air at home. But how do we know that the air is too dry? We need a device to detect air humidity. In this lesson, we will learn the use of the temperature and humidity sensor. We use the temperature and humidity sensor to make a temperature and humidity meter, and also combine it with the LCD 128X32 DOT to display the temperature and humidity values.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | OLED Screen*1 | Temperature and Humidity Sensor*1 |
![]() |
![]() |
||
| Several Dupont Wires | USB Cable*1 |
3. Component Knowledge:

Temperature and Humidity Sensor: It is a temperature and humidity composite sensor with calibrated digital signal output, with a humidity accuracy of ±5%RH, a temperature accuracy of ±2℃, a humidity range of 20-90%RH, and a temperature range of 0~50℃. The temperature and humidity sensor applies dedicated digital module acquisition technology and temperature and humidity sensing technology to ensure that the product has extremely high reliability and excellent long-term stability. The temperature and humidity sensor includes a resistive humidity-sensing element and an NTC temperature-measuring element, which is very suitable for temperature and humidity measurement occasions that do not require high precision and real-time performance. The operating voltage is in the range of 3.3V-5.5V.
The temperature and humidity sensor has three pins, which are VCC, GND, and S. S is the data output pin. It uses serial communication.
Different batches may also have three pins: + - out: + connects to power, - connects to GND, and OUT is the data output pin.
Single-bus Format Definition of the Temperature and Humidity Sensor:
| Name | Single-bus Format Definition |
|---|---|
| Start signal | The microprocessor pulls the data bus (SDA) low for a period of at least 18ms (maximum not exceeding 30ms) to notify the sensor to prepare data. |
| Response signal | The sensor pulls the data bus (SDA) low for 83µs, and then pulls it high for 87µs to respond to the host's start signal. |
| Humidity | The high humidity byte is the integer part of the humidity data, and the low humidity byte is the decimal part of the humidity data |
| Temperature | The high temperature byte is the integer part of the temperature data, and the low temperature byte is the decimal part of the temperature data. If Bit8 of the low temperature byte is 1, it indicates a negative temperature, otherwise it is a positive temperature |
| Check bit | Check bit = humidity high byte + humidity low byte + temperature high byte + temperature low byte |
Temperature and Humidity Sensor Data Timing Diagram:
After the user host (MCU) sends a start signal once, the temperature and humidity sensor switches from low-power mode to high-speed mode. After the host start signal ends, the temperature and humidity sensor sends a response signal, sends out 40-bit data, and triggers a signal acquisition. The signal transmission is shown in the figure.

The temperature and humidity sensor can easily add temperature and humidity data to your DIY electronic projects. It is perfect for remote weather stations, home environment control systems, and farm or garden monitoring systems.
Parameters of the Temperature and Humidity Sensor:
- Operating voltage: +5 V
- Temperature range: 0-50 °C, error: ± 2 °C
- Humidity range: 20-90% RH, error: ± 5% RH
- Digital interface
Schematic of the Temperature and Humidity Sensor:

4. Read the Temperature and Humidity Values:

Code Description:

This reads the temperature and humidity detected by the temperature and humidity sensor. The temperature and humidity sensor has 3 models, selected according to different models. Here the DHT11 model is selected.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
", change hello to RH: . -
First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
", pin is 13, select "Get humidity". -
Copy the code block "
" once, change RH: to %. -
Copy the code block "
" once, change RH: to Temp:, select "Get temperature", change % to C, change the bottom "No wrap" to "Auto wrap". -
Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You will see that: the serial monitor window will print the current temperature and humidity data of the current environment, as shown in the figure below.

5. Wiring Diagram of the Temperature and Humidity Meter:
Now we start to use the LCD_128X32_DOT to print the value of the temperature and humidity sensor, and we will see the corresponding value on the LCD_128X32_DOT screen. Let us start this project. Please wire according to the following wiring diagram:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: the LCD 128X32 DOT screen displays the corresponding temperature value and humidity value detected by the temperature and humidity sensor in the environment.

Project 28 Distance Meter¶
1. Project Introduction:
The HC-SR04 ultrasonic sensor is a very affordable distance sensor, mainly used for object avoidance in various robot projects. It is also used as a water level sensor and even as a parking sensor. We regard the ultrasonic sensor as the eyes of a bat. In the dark, bats can still identify objects and directions in front through ultrasonic waves. In this project, we use the ESP32 to control the ultrasonic sensor and LED to simulate an ultrasonic distance meter.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Ultrasonic Sensor*1 | Several Dupont Wires |
![]() |
![]() |
![]() |
![]() |
| Red LED*4 | 220Ω Resistor*4 | Several Jumper Wires | USB Cable*1 |
3. Component Knowledge:
HC-SR04 Ultrasonic Sensor: Like a bat, it uses sonar to determine the distance to an object, and it provides precise non-contact range detection, high accuracy, and stable readings. Its operation is not affected by sunlight or black materials, just like a precision camera (acoustically, soft materials like cloth are hard to detect). It comes with an ultrasonic transmitter and receiver.

In front of the ultrasonic sensor are two metal cylinders, which are transducers. Transducers convert mechanical energy into electrical signals. In the ultrasonic sensor, there are a transmitting transducer and a receiving transducer. The transmitting transducer converts electrical signals into ultrasonic pulses, and the receiving transducer converts the reflected ultrasonic pulses back into electrical signals. If you look at the back of the ultrasonic sensor, you will see an IC behind the transmitting transducer. This is the IC that controls the transmitting transducer. There is also an IC behind the receiving transducer, which is a quad operational amplifier that amplifies the signal generated by the receiving transducer into a signal sufficient to be transmitted to the microcontroller.
Timing Diagram:
The figure shows the timing diagram of the HC-SR04. To start the measurement, the Trig of the SR04 must accept a high (5V) pulse of at least 10us, which will start the sensor to emit 8 cycles of 40kHz ultrasonic pulses and wait for the reflected ultrasonic pulses. When the sensor detects the ultrasonic wave from the receiver, it will set the Echo pin to high (5V) and delay for a period (width) proportional to the distance. To obtain the distance, measure the width of the Echo pin.

Time = echo pulse width, in us (microseconds)
Distance in cm = time / 58
Distance (inches) = time / 148
4. Read the Ultrasonic Sensor Distance Value
We will start with a simple ultrasonic distance measurement and print the measured distance.

The HC-SR04 ultrasonic sensor has four pins: Vcc, Trig, Echo, and GND. The Vcc pin provides the power to generate the ultrasonic pulses, connected to Vcc/+5V. The GND pin is connected to ground/GND. The Trig pin is where the control board sends a signal to start the ultrasonic pulse. The Echo pin is where the ultrasonic sensor sends information about the duration of the ultrasonic pulse travel to the control board. Wire as shown in the figure below:

Code Description:

Read the distance detected by the ultrasonic sensor.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
" and put it into "
", change " Integer " to "String"; then drag out "
" from "
" and put it into "
", change item to distance.

- First drag out "
" from "
"; then drag out "
" from "
", Trig pin is 13, Echo pin is 14.

- First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
", change hello to Distance: .

- First drag out "
" from "
", change "Auto wrap" to "No wrap"; then drag out "
" from "
".

- Copy the code block "
" once, change "No wrap" to "Auto wrap", change Distance: to cm.

- Drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the distance value between the ultrasonic sensor and the object.

5. Wiring Diagram of the Ultrasonic Distance Meter:
Next, we will use the ESP32 to control the ultrasonic sensor and 4 LEDs to simulate an ultrasonic distance meter. Wire as shown in the figure below:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, open the serial monitor, and set the baud rate to 115200. You can see that: the serial monitor window will print the distance value between the ultrasonic sensor and the object. In addition, when we move our hand in front of the ultrasonic sensor, the corresponding LED will light up.

Project 29 Temperature Meter¶
1. Project Introduction:
A thermistor is a resistor whose resistance depends on temperature and temperature changes, and is widely used in devices such as gardening and home alarm systems. Therefore, we can use this characteristic to make a temperature meter.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | OLED Screen*1 | Thermistor*1 |
![]() |
![]() |
![]() |
![]() |
| 10KΩ Resistor*1 | Several Dupont Wires | USB Cable*1 | Several Jumper Wires |
3. Component Knowledge:
Thermistor: A thermistor is a temperature-sensitive resistor. When the thermistor senses a change in temperature, its resistance changes. We can use this characteristic of the thermistor to detect temperature intensity. The thermistor and its electronic symbol are shown below.

The relationship between the resistance value of the thermistor and temperature is:

In the formula:
Rt is the resistance of the thermistor at temperature T2;
R is the nominal resistance of the thermistor at temperature T1;
EXP[n] is e to the power of n;
B is the temperature index;
T1 and T2 are Kelvin temperatures (absolute temperatures), Kelvin temperature = 273.15 + Celsius temperature. For the parameters of the thermistor, we use: B=3950, R=10KΩ, T1=25℃. The circuit connection method of the thermistor is similar to that of the photoresistor, as shown below:

We can use the value measured by the ADC converter to obtain the resistance value of the thermistor, and then use the formula to obtain the temperature value. Therefore, the temperature formula can be derived as:

4. Read the Value of the Thermistor:
First, we learn to read the current ADC value, voltage value, and temperature value of the thermistor and print them out. Please wire according to the following wiring diagram:

Code Description:

Read the temperature value of the analog temperature sensor (thermistor).
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
"; then drag out "
" from "
"; change "Auto wrap" to "No wrap", change "hello" to "Temperature: ". -
First drag out "
" from "
"; then drag out "
" from "
", pin is 36; change "Auto wrap" to "No wrap". -
Copy the code block "
" once, change "No wrap" to "Auto wrap", change "Temperature:" to " ℃ "; then drag out "
" from "
", set the delay to 100 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You will see that: the serial monitor window will continuously display the temperature value of the current environment detected by the thermistor. Try pinching the thermistor with your index finger and thumb (do not touch the wire) for a short time, and you should see the temperature value increase.

5. Wiring Diagram of the Temperature Meter:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: the LCD 128X32 DOT screen displays the temperature value of the current environment detected by the thermistor.

Project 30 Password Lock¶
1. Project Introduction:
For commonly used digital button sensors, one button uses one IO port. Sometimes when we need more buttons, it will occupy too many IO ports. To save the use of IO ports, multiple buttons are made into a matrix type, and through the control of row and column lines, fewer IO ports control multiple buttons. In this project, we will learn to use the ESP32 and a film 4*4 matrix keypad to control a servo and a buzzer.
2. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Servo*1 |
![]() |
![]() |
![]() |
| Film 4×4 Matrix Keypad*1 | USB Cable*1 | Several Jumper Wires |
![]() |
![]() |
![]() |
| NPN Transistor (S8050)*1 | Active Buzzer*1 | 1KΩ Resistor*1 |
3. Component Knowledge:
Film 4×4 Matrix Keypad: A keypad is a device that integrates many keys. As shown in the figure below, a film 4x4 keypad integrates 16 keys.

Just like the LED matrix integration, in the film 4x4 matrix keypad, each row of keys is connected with one pin, and each column of keys is the same. Such connection can reduce the occupation of processor ports. The internal circuit is shown below.
The usage is similar to the matrix LED, i.e., using the row scanning or column scanning method to detect the state of the keys on each column or each row. Take the column scanning method as an example, send a low level to column 4 (Pin4), detect the level state of rows 1, 2, 3, and 4, and determine whether keys A, B, C, and D are pressed. Then send low levels to columns 3, 2, and 1 in turn, and detect whether other keys are pressed. Then, you can obtain the state of all keys.
4. Read the Key Value of the Film 4*4 Matrix Keypad:
We first use a simple code to read the key value of the film 4*4 matrix keypad and print it out. The wiring diagram is shown below:

Code Description

Initialize the row pins and column pins of the film 4*4 matrix keypad, define the keypad, etc.

Get the key value of the film 4*4 matrix keypad.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
Drag out "
" from "
", the row pins are: 22, 21, 19, 18; the column pins are: 17, 6, 4, 0. -
First drag out "
" from "
", then drag out "
" from "
". -
Drag out "
" from "
", set the delay to 500 milliseconds.
Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You will see that: when you press the keys on the film 4×4 matrix keypad, the serial monitor window will print the corresponding key value, as shown in the figure below.

5. Wiring Diagram of the Password Lock:
In the previous experiment, we already know the key values of the film 4×4 matrix keypad. Next, we use the film 4×4 matrix keypad as a keypad to control the servo and the buzzer.

7. Project Code:

8. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: when you press the key "3" on the film 4*4 matrix keypad with your hand, the servo will rotate 180°, and the buzzer will sound; then when you release it, the servo returns to its original position, and the buzzer stops sounding.

Project 31 Infrared Remote Control Controlling Sound and LED¶
1. Project Introduction:
Infrared remote control is a low-cost, easy-to-use wireless communication technology. IR light is very similar to visible light, except that its wavelength is slightly longer. This means that infrared is undetectable to the human eye, which is perfect for wireless communication. For example, when you press a button on a TV remote control, an infrared LED will turn on and off repeatedly at a frequency of 38,000 times per second, transmitting information (such as volume or channel control) to the infrared photoreceptor on the TV.
We will first explain how the common infrared communication protocols work. Then we will start this project with a remote control and an infrared receiving component.
2. Project Components:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | Infrared Receiver*1 | RGB LED*1 |
![]() |
![]() |
![]() |
![]() |
| Active Buzzer*1 | 220Ω Resistor*3 | 10KΩ Resistor*1 | Infrared Remote Control*1 |
![]() |
![]() |
![]() |
![]() |
| NPN Transistor (S8050)*1 | 1kΩ Resistor*1 | USB Cable*1 | Several Jumper Wires |
3. Component Knowledge:
Infrared (IR) Remote Control: It is a device that can emit infrared light signals. When different buttons are pressed, the infrared emission tube at the front of the remote control emits infrared rays with different commands. Infrared remote control technology is widely used, such as in TVs, air conditioners, etc. Therefore, in today's technologically advanced society, infrared remote control technology makes it convenient for you to switch TV programs and adjust air-conditioning temperatures.
The remote control we use is shown below, and this infrared remote control uses NEC encoding.

Infrared (IR) Receiver: It is the VS1838B infrared receiving sensor component, which can receive infrared light, so it can be used to detect the infrared light signals emitted by the infrared remote control.

The infrared receiver is a device that integrates receiving, amplifying, and demodulating. The received infrared light signal is demodulated within its internal IC (converting the infrared light signal back to binary), and the output is a digital signal, which is then transmitted to the microcontroller. It can receive standard 38KHz modulated remote control signals.
Infrared signal modulation process diagram:

4. Decode the Infrared Signal:
We connect the infrared receiving component to the ESP32 according to the following wiring diagram.

Code Description:

The infrared receiver receives the key value signal of the infrared remote control and initializes the pin.

The serial port automatically wraps and prints the received hexadecimal key value signal of the infrared remote control.
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
Drag out "
" from "
", pin is 0. -
First drag out "
" from "
" and put it into "
"; then drag out "
" from "
" and put it at the number 0 in "
", change "No wrap" to "Auto wrap".

Complete code:

Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, click the icon
to enter the serial monitor, and set the baud rate to 115200. You will see that: point the infrared remote control transmitter at the infrared receiving head, press the key on the infrared controller, and the serial monitor will print the currently received key code value. Press the same key multiple times to make sure you have the correct code value for that key. If you see FFFFFFFF, please ignore it.

Write down the key code value associated with each key of the infrared remote control, because you will need this information later.

5. Wiring Diagram of the Infrared Remote Control:

6. Project Code:

7. Project Phenomenon:
Compile and upload the code to the ESP32. After the code is uploaded successfully, power it on via the USB cable, and you will see that: pressing keys 1 to 7 on the infrared remote control will each make the buzzer sound once, while the RGB lights red, green, blue, yellow, magenta, cyan, and white respectively. Pressing any other key (other than keys 1-7) makes the RGB go out.

Project 32 Bluetooth¶
This chapter mainly introduces how to perform simple data transmission with a mobile phone through the Bluetooth of the ESP32.
1. Project Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | USB Cable*1 | Smartphone/Tablet(Bring your own)*1 |
In this project, we need to use a Bluetooth application called Serial Bluetooth Terminal to assist the experiment. If you have not installed it yet, please click to install: https://www.appsapk.com/serial-bluetooth-terminal/ . Below is its logo.

2. Component Knowledge:
Bluetooth is a short-distance communication system, which can be divided into two types, namely Bluetooth Low Energy (BLE) and Classic Bluetooth. There are two modes of simple data transmission: master mode and slave mode.
Master Mode: In this mode, work is done on the master device, and it can connect with slave devices. We can search and select nearby slave devices to connect. When a device initiates a connection request in master mode, it needs information such as the address and pairing password of other Bluetooth devices. After pairing is completed, it can connect with them directly.
Slave Mode: A Bluetooth module in slave mode can only accept connection requests from the host, but cannot initiate connection requests. After connecting with the host device, it can send data to the host device and can also receive data from the host device. Data interaction can occur between Bluetooth devices, with one device in master mode and the other device in slave mode. When they perform data interaction, the Bluetooth device in master mode searches and selects nearby devices to connect. When establishing a connection, they can exchange data. When a mobile phone exchanges data with the ESP32, the mobile phone is usually in master mode, and the ESP32 is in slave mode.

3. Project Wiring:
Use a USB cable to connect the ESP32 board to the USB port on the computer.

4. Project Code:
Reminder: Drag this code out from "
" together, and change " ESP32BT " to " ESP32test ".

5. Project Phenomenon:
Compile and upload the code to the ESP32 main control board. After uploading successfully, open the serial monitor and set the baud rate to 115200.
Please confirm that your phone has Bluetooth enabled, and that the "Serial Bluetooth Terminal" Bluetooth application is installed.


The phone automatically searches for nearby Bluetooth devices, click "ESP32 test" to pair, a pairing dialog appears, click "Pair", and then the "ESP32 test" device is connected.



Open the software APP and click on the left side of the terminal. Select "Devices".


Select ESP32test in Classic Bluetooth mode, and a connection success prompt as shown in the figure below will appear.


Now, data can be transmitted between your phone and computer through the ESP32.
Type "Hi!" in the text box in the serial monitor, and when the phone receives it, reply "Hi!" to your phone; the phone sends "Hello!", and when the computer receives it, reply "Hello!" to your computer.


Project 33 WiFi Working Mode¶
In today's era of rapid technological development, the method of uniformly controlling smart devices through mobile phones has gradually gained people's favor. This method uses a microcontroller to establish a connection between the mobile phone and the smart devices through a WiFi module and the Internet, so as to realize remote control of the smart devices. Our development board comes with a WiFi module. In this chapter, we will focus on the WiFi development of the ESP32.
The ESP32 has 3 different WiFi working modes: Station mode, AP mode, and AP+Station mode.
Special reminder: In this project, only the WiFi Station mode of the ESP32 is explained。
Project 33.1: WiFi Station Mode
1. Experimental Components:
![]() |
![]() |
|---|---|
| USB Cable x1 | ESP32x1 |
2. Experimental Wiring:
Use a USB cable to connect the ESP32 board to the USB port on the computer.

3. Component Knowledge:
Station Mode: When the ESP32 selects Station mode, it acts as a WiFi client. It can connect to a router network and communicate with other devices on the router through a WiFi connection. As shown in the figure below, the PC and the router are already connected. If the ESP32 wants to communicate with the PC, it needs to connect the PC and the router.

4. Project Code:
You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
" , set the baud rate to 115200. -
Drag out "
" from "
".
Complete code:

Special reminder: Because the WiFi name and password are different in different places, before running the program code, the user needs to enter their own WiFi name and password in the box shown in the figure below。

5. Project Phenomenon:
After confirming that your own WiFi name and password are entered correctly, compile and upload the code to the ESP32 board. After uploading successfully, click the icon
to enter the serial monitor, and set the baud rate to 115200. When the ESP32 successfully connects to WiFi, the serial monitor will print the IP address assigned to the ESP32 by WiFi. Then the serial monitor window will display as follows: (If the serial monitor window does not display the following information after opening the serial monitor and setting the baud rate to 115200, you can press the reset button of the ESP32
)

Project 34 WiFi Test¶
1. Experimental Introduction:
In this experiment, we first use the WiFi Station mode of the ESP32 to read the WiFi IP address, and then connect to WiFi through the APP to read the characters sent by each function button on the APP.
2. Experimental Components:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | USB Cable*1 | Smartphone/Tablet(Bring your own)*1 |
3. Experimental Wiring:
Use a USB cable to connect the ESP32 board to the USB port on the computer.

4. Install APP:
Only supports Android system devices (phone/tablet) APP:
5. Code Description:

Input the WiFi name and password, connect to the WiFi hotspot, and read the IP address assigned by WiFi.

The APP keys send data, and through wireless WiFi, the ESP32 receives the relevant data, i.e., reads the WiFi data.
6. Project Code:
Special note:Ensure that the computer network, the mobile phone/tablet network, the ESP32 board, the router, and the WiFi name and password entered in the code are all on the same local area network (WiFi).

You can open the code we provide, or you can write the code yourself, as follows:
-
Drag out "
" from "
". -
Drag out "
" from "
" and put it into "
", set the baud rate to 115200. -
First drag out "
" from "
" and put it into "
", change " Integer " to "String"; then drag out "
" from "
" and put it into "
", delete "hello".

-
Drag out "
" from "
". -
First drag out "
" from "
", then drag out "
" from "
".

- First drag out "
" from "
", then drag out "
" from "
".

Complete code:

Special note: You need to first change the user WiFi name (SSID name) and user WiFi password (PASSWD password) in the project code
to your own WiFi name and WiFi password.
7. Experimental Phenomenon
Special note:Ensure that the computer network, the mobile phone/tablet network, the ESP32 board, the router, and the WiFi name and password entered in the code are all on the same local area network (WiFi).
Open the serial monitor and set the baud rate to 115200, so that the serial monitor prints the detected WiFi IP address, then open the WiFi APP. Enter the detected WIFI IP address in the text box in front of the WIFI button (for example, the IP address detected by the serial monitor above: 192.168.8.210), and then click the connect button. If the connection is successful, it will display as shown in the figure below: Connected.

Tap each function button on the APP with your hand, and then the serial monitor will print the corresponding characters received.

Note: If the serial monitor window does not display the following information after opening the serial monitor and setting the baud rate to 115200, you can press the reset button of the ESP32
. If it still does not work, please reopen the serial monitor.
Project 35 WiFi Smart Home¶
1. Experimental Description:
In the previous experiments, we have understood the three modes of the ESP32: WiFi Station mode, WiFi AP mode, and WiFi AP+Station mode. In this chapter's experiment, we will use the WiFi Station mode of the ESP32 to control multiple sensors/modules to work by connecting to WIFI through the APP, achieving the effect of a WiFi smart home.
2. Experimental Equipment:
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| ESP32*1 | Breadboard*1 | DC Motor*1 | Relay Module*1 |
![]() |
![]() |
![]() |
![]() |
| Servo*1 | Temperature and Humidity Sensor*1 | Ultrasonic Sensor*1 | Several Dupont Wires |
![]() |
![]() |
![]() |
![]() |
| Smartphone/Tablet(Bring your own)*1 | Breadboard Power Module*1 | 6-AA Battery Holder*1 | Fan Blade*1 |
![]() |
![]() |
![]() |
|
| AA Battery(Bring your own)*6 | MicroUSB Cable*1 | Several Jumper Wires |
3. Experimental Wiring Diagram:
| Relay | ESP32 Board | Temperature and Humidity Sensor | ESP32 Board |
|---|---|---|---|
| Gnd | Gnd | - | G |
| Vcc | 3.3V | + | 5V |
| IN | IO32 | out | IO15 |
| Ultrasonic Sensor | ESP32 Board | 130 Fan Module | ESP32 Board |
|---|---|---|---|
| Vcc | 5V | G | G |
| Trig | IO14 | V | 5V |
| Echo | IO27 | INA | IO18 |
| Gnd | GND | INB | IO19 |
| Servo | ESP32 Board |
|---|---|
| Red wire | 5V |
| Brown wire | G |
| Orange wire | IO4 |

4. Project Code:
See the example source code in the compressed package for details
Special note: You need to first change the user WiFi name and user WiFi password in the experimental code
to your own WiFi name and WiFi password.
5. Experimental Phenomenon:
Special note:Ensure that the computer network, the mobile phone/tablet network, the ESP32 board, the router, and the WiFi name and password entered in the code are all on the same local area network (WiFi).
After confirming that the WiFi name and WiFi password in the program code are modified correctly, compile and upload the code to the ESP32 board.
Open the serial monitor and set the baud rate to 115200, so that the serial monitor prints the detected WiFi IP address. (Note: If the serial monitor window does not display the following information after opening the serial monitor and setting the baud rate to 115200, you can press the reset button of the ESP32
If there is still no output, you can close the serial monitor and reopen it, select the baud rate 115200, and then press the EN key on the board to try.

Download and install the APP on your phone or tablet, and enter the IP address from the serial monitor into the app.

You can refer to the "Wifi Smart Home" in the video tutorial for details.
Project 36 MQTT Internet of Things¶
1. Experimental Description:
In the previous experiments, we have mastered the basics of WiFi and built a prototype of a smart home project within a local area network.
This lesson will focus on explaining the relevant knowledge of the Internet of Things, and on this basis further improve the smart home project, ultimately realizing a remote anti-theft alarm system that supports cross-network segments.
2. Internet of Things Knowledge:
Internet of Things technology is now widely used in industries, medical care, daily life, and other fields, mainly reflected in the ability of terminals such as mobile phones and computers to obtain and control various devices in real time. In addition to the main board and various sensors we came into contact with in the course, it also involves a communication technology: MQTT. This lesson will use MQTT communication technology to realize real-time interaction between mobile phones and the human body infrared sensor.
The core of the Internet of Things is to enable mobile phones, computers, and hardware devices to communicate with each other.
In this tutorial, we can understand the whole process as a "message delivery link":
Phone App → MQTT Server → ESP32 Development Board → LED Light / Relay / Sensor

Among them, the MQTT server is a free test server provided by Qiguopai, deployed on the Internet, and both the app and the ESP32 board connect to this server via WiFi.
You can understand it as a "message relay station":
-
The App and the Esp32 agree on an identification number;
-
The App sends the identification number + message to the MQTT server;
-
The server then forwards the message to the Esp32 board with this identification number;
2. Experimental Equipment:
![]() |
![]() |
![]() |
|---|---|---|
| ESP32*1 | Breadboard*1 | Human Body Infrared Sensor*1 |
![]() |
![]() |
|
| LED Bulb*1 | 220Ω or 1K Resistor | |
![]() |
![]() |
![]() |
| Smartphone/Tablet(Bring your own)*1 | Several Dupont Wires | Several Jumper Wires |
3. Experimental Wiring Diagram:
| Human Body Infrared Sensor | ESP32 Board |
|---|---|
| + | 3.3V |
| - | GND |
| OUT | IO35 |
| LED Bulb | ESP32 Board |
|---|---|
| Negative pole | GND |
| Positive pole | IO23 |
3. Experimental Code:
Open the code in the project material package, then install the Internet of Things protocol library PubSubClient. For code analysis, you can watch the video explanation.
If you want to learn app development, you can download the following source code. If you are learning microcontroller development, you only need to download the installation package.

4. Experimental Phenomenon:
When someone enters the detection range of the human body infrared sensor, the LED light will light up and send data to the mobile phone APP.
Refer to the video tutorial for the complete demonstration


5. Extended Thinking:
-
Can more sensors be connected? For example, a gas sensor can detect in real time whether there is a gas leak in the kitchen;
-
Connect an external 6V power adapter to solve the long-term power supply problem;
-
3D print a storage box, so that it has a beautiful appearance and looks more like a marketable product.








































