Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino
Estimated reading time: 7 minutes
Following the previous tutorial on the “Face Detection Alarm”, in this tutorial, we will teach you how to use the Weili camera to create a “Face Detection Warning Light”. By applying artificial intelligence and the face recognition function of the Weili camera, the LED light will activate when a face is detected. Here are the materials needed for this tutorial:
  • Weili camera
  • LED light
  • Weili board and expansion board
StepsStep 1: Combine the Weili board with the expansion board
Step 2: Install the LED light on the Weili board Step 3: Connect the Weili camera to the computer Step 4: Adjust the Weili camera settings Step 5: Connect the Weili camera to the Weili board Step 6: Use Scratch for programming Step 7: Upload the program to the Weili board
Step 1
First, combine the Weili board with the expansion board.
Creating a Face Detection Warning Light with Scratch and Arduino
Step 2
Install the LED light in the fourth and fifth slots on the blue area above D4 on the Weili board.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Step 3
Use a Micro USB 2.0 cable to connect the Weili camera to your personal computer.
When the green, blue, and red LED lights are lit, it indicates that the Weili camera is successfully connected.
Creating a Face Detection Warning Light with Scratch and Arduino
Don’t forget to remove the lens cover!
Step 4
Open the CZL smart sensor tool, set the function to “face recognition”, and click apply.
Creating a Face Detection Warning Light with Scratch and Arduino
Once the settings are complete, aim the lens at a face for testing to see if it can successfully recognize faces. After testing, close the CZL smart sensor tool and unplug the Micro USB 2.0 cable from the Weili camera.
Step 5
Creating a Face Detection Warning Light with Scratch and Arduino
Connect the Weili camera to the “UART” slot on the Arduino expansion board.

Creating a Face Detection Warning Light with Scratch and Arduino

Step 6
Open Weili camera Junior for Scratch programming. The following steps will teach you how to build the “Face Detection Warning Light” step by step.
A. Initial Setup
Drag out the “Initialize” block from the “Control” section and the “Initialize SmartSensor” block from the “Smart Sensor” section.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Place the “Initialize SmartSensor” block into the “Initialize” block.

Creating a Face Detection Warning Light with Scratch and Arduino

Adjust the parameters of the “Initialize SmartSensor” block: “RX#” (input) to 0, and “TX#” (output) to 1. This step ensures that the Weili board and Weili camera can connect correctly.
B. Object Detection Loop Design
In this process, we will design a loop to make the LED light blink. First, drag out the “If() Then()” block from the “Control” section and place the “Detected Object” block from the “Smart Sensor” section into the “If” section. This means that if the Weili camera detects an object, it will perform the actions in the “Then” section.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Next, drag out another “If() Then()” block and place it in the “Then” section.

Creating a Face Detection Warning Light with Scratch and Arduino

Drag out the “() = ()” block from the “Logic” section and place the “Object Type” and “0” from the “Smart Sensor” section into the “() = ()” block.

Creating a Face Detection Warning Light with Scratch and Arduino

Note that the symbol in the “() = ()” block must be “equals”.

Creating a Face Detection Warning Light with Scratch and Arduino

Place the adjusted “() = ()” block into the second layer of the “If() Then()” block.

Creating a Face Detection Warning Light with Scratch and Arduino

Drag out two “Built-in LED State()” blocks from the “Input/Input” section and set their parameters to high and low.

Creating a Face Detection Warning Light with Scratch and Arduino

Place the two “Built-in LED State()” blocks into the “Then” section of the second layer “If() Then()” block.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Next, drag out the “Delay()(seconds)” block from the “Control” section. Since we want to create a blinking effect for the LED light, please set the “Delay()(seconds)” to 100 milliseconds, which will create a short delay of 100 milliseconds when the LED light turns on. (You can also set it according to your preference.) Place the “Delay()(seconds)” block between the two “Built-in LED State()” blocks.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Finally, drag out the “Repeat While()()” block from the “Control” section and place the “Detected Object” block from the “Smart Sensor” section into the “Repeat While()” section.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

Place the “Repeat While()()” block under the second “Built-in LED State()” block.

Creating a Face Detection Warning Light with Scratch and Arduino

The following is the entire “Face Detection Warning Light” Scratch program block group. Before uploading to the Weili board, please check if the structure is correct.

Creating a Face Detection Warning Light with Scratch and Arduino

Step 7
After completing the Scratch program code, upload the code to the Weili board.
A. Connect the Weili board to your personal computer
First, use a Micro USB 2.0 cable to connect the Weili board to your personal computer.

Creating a Face Detection Warning Light with Scratch and Arduino

B. Upload the program code
In the upper right corner of Weili camera Junior, select “Arduino UNO” from the “Select Hardware” dropdown menu to connect.

Creating a Face Detection Warning Light with Scratch and Arduino

Then select the appropriate COM port from the “Serial Port List” dropdown menu to connect. If there is no current connection, the “Serial Port List” will display “Not Connected”.

Creating a Face Detection Warning Light with Scratch and Arduino

If you cannot find the corresponding COM port, there is a “Refresh” button in the “Serial Port List” dropdown menu to update. The COM port will have different models depending on the device; the tutorial uses COM5.
When you see “Connected”, click “Return to Editor” to go back to Weili camera Junior.

Creating a Face Detection Warning Light with Scratch and Arduino

Finally, click the “Upload” button to upload the program code to the Weili board.

Creating a Face Detection Warning Light with Scratch and Arduino

When “Upload Successful” appears, you can start using the face detection warning light.

Creating a Face Detection Warning Light with Scratch and Arduino

Creating a Face Detection Warning Light with Scratch and Arduino

C. Save the project
First, click “Save As-Ctrl+Shift+S” in the “Project” dropdown menu in the upper right corner. You can also use the shortcut Ctrl+Shift+S.

Creating a Face Detection Warning Light with Scratch and Arduino

After clicking, a save window will appear immediately. Choose a save location, enter a project name, and press the save button. After saving, you can check if the file type is Scratch 3 Project (.sb3) at the save location.
Creating a Face Detection Warning Light with Scratch and Arduino
Practical Operation:Once you have completed the above steps, it’s time to play with the “Face Detection Warning Light”! Aim the Weili camera at a face and test if the LED light blinks on and off. You can also apply this “Face Detection Warning Light” in your daily life!
————
About Weili Creative
Weili Creative is an artificial intelligence education brand under the VIA Group, dedicated to providing youth artificial intelligence education solutions, integrating smart hardware, smart software platforms, curriculum systems, teacher training, competition activities, level examinations, and AI laboratory projects into one. The teaching targets cover all academic stages, and the teaching scenarios involve classroom teaching, club activities, and experimental teaching in a comprehensive and multi-scenario manner, creating customized comprehensive solutions for artificial intelligence education.
If you want to know more information
Feel free to call010-82695573
or click on the end of the article 【Leave a Message】
We will respond to your inquiries in a timely manner, thank you!

Creating a Face Detection Warning Light with Scratch and Arduino

  • Official Announcement | Latest Notice for the 2020-2021 “Youth Silicon Valley – National Youth Artificial Intelligence Education Achievement Exhibition Competition”

  • Congratulations | VIA Electronics officially joins the National Technical Committee for Information Technology Standardization (CELTSC) Education Technology Sub-Technical Committee

  • VIA Education collaborates with Youth Silicon Valley Charity: Striving for equal access to educational resources for everyone!

  • After four years of cultivation in the K12 field, Weili Creative constructs a campus artificial intelligence education evolution model

  • Good News | VIA Electronics becomes a co-organizer of the PAAT National Youth Programming Ability Level Examination

  • Weili Creative repositions: The first batch of artificial intelligence demonstration schools in Hebi, Henan has been established

  • Investment and Cooperation | Partners, look here, Weili Creative is actively recruiting partners!

Creating a Face Detection Warning Light with Scratch and Arduino

Leave a Comment

×