01 Face Recognition
01 Face Recognition
In this section, miniAuto will use the ESP32-S3 vision module to recognize the
face. After the face is recognized, it will shake slightly and turn the green LED
on. This is a greeting.
1. Program Flowchart
1
2.2 Wiring
Connect the ESP32-S3 module to any I2C interface on the expansion board
with a 4PIN wire.
3. Program Download
Note:
The Bluetooth module must be removed before downloading the program, otherwise
Please turn the switch of the battery box to “OFF” when connecting the Type-B
download cable in case the download cable touches the power pin of the expansion board
2
3)Click the “Select Board”, and the software will automatically detect current
Arduino serial interface. Then click to connect.
4)Click to download the program to the Arduino, and then wait for the
download to complete.
3
2) After flashing, disconnect the Type-C cable. Turn on the miniAuto to run the
program.
4. Program Outcome
1) After powering miniAuto on, the RGB LED on the expansion board will turn
white.
2) When the face is recognized, the RGB LEDs of the ultrasonic sensor and
the expansion board will turn green. The car will simultaneously shake slightly
to indicate a greeting.
5. Program Analysis
The name of this program is “esp32_face_recognition.ino”. The
implementation logic of the program can be referred to the following flowchart:
4
5.1 Import Library File
Import the necessary Arduino, RGB, ultrasonic sensor, and ESP32-S3 vision
module communication header files for the game.
2) Variables and constants needed for executing the program are defined.
They are the PWM limiting constant, the RGB light static array with each
element of type CRGB, the non-blocking delay function recording variable, the
face detection switch, and the current face detection result.
3) The ESP32-S3 vision module class and ultrasonic class are instantiated.
5
5.3 Initial Settings
1) Initialize related hardware equipment in “setup()” function. The first is serial
interface, which sets the baud rate of communication to 9600 and the timeout
for reading data to 500ms.
Connect it to ledPin. Then set the color to white by calling “Rgb_Show” and
“ultrasound.Color” functions.
5) The buzzer pin is set to output mode. This controls the buzzer to make a
short sound and stop.
After initialization is complete, the program enters the “loop” function. The
"Facedetect_Task" function is called in a loop. After recognizing the face,
miniAuto shakes slightly and turns green light on to make a greeting.
The function is used to achieve the same effect as the “delay(ms)” function.
6
The “millis()” function obtains the current timestamp and assigns it
to “currentTime”. The difference between the current timestamp and the
previous timestamp is calculated. If the difference is greater than the set
time, “currentTime” is assigned to “previousTime”. Return “true”.
Otherwise, return “false”. This achieves the delay without affecting other tasks.
7
5.7 RGB LED Setting Function
This function sets the color of the RGB light on the expansion board. The
“rValue”, “gValue”, and “bValue” are written to the “rgbs” array. The
“FastLED.show()” function is called to set the color of the RGB light.
This function is used to initialize the motor pins. Call the “pinMode” function in
a “for” loop to set the motor IO port to output mode. Then, the
“Velocity_Controller” function is called to set the robot to stop.
The function sets the speed of each wheel of the robot. By analyzing the
kinematics of the robot's Mecanum wheels, the speed of each wheel can be
calculated. The calculated speed variables can be used as input parameters
for the “Motors_Set” function to adjust the motor speed and control the overall
movement of the robot. Please refer to relevant tutorials to learn about
kinematic analysis.
8
5.10 Motor Setting Function
This function adjusts the speed and direction of each wheel of the robot based
on the input parameter values. In the “for” loop, the robot's steering is adjusted
based on the calculated results. The “map” function maps the calculated
values from “0 to 100” to the range of “pwm_min to 255”. Next, the “digitalWrite”
and “analogWrite” functions sets the motor direction and speed.
9
6. FAQ
Q1:Since the code was upload, the color can not be recognized.
A:Please check that you have connected the 4-pin cable to the I2C interface.
Q2:Why the camera cannot recognize when I face it, but it can recognize
When flipped upside down?
A:Please flash another “bin” file to make the face recognized.
10