Face Detection Warning Light with Arduino and Scratch

Hello, everyone! For this project, we will show you how to make a warning light using VIA Pixetto vision sensor, an LED light, and an Arduino board. With the help of AI technology, the finished face detection warning light will flash when the vision sensor detects a face. This project is not only fun to make, but can also be used as an intelligent lamp.
Alright, let’s get started!

The guide will involve seven simple steps:
Step 1: Installing expansion board to an Arduino board
Step 2: Connecting the LED light to an Arduino board
Step 3: Connecting the VIA Pixetto to a PC
Step 4: Configuring the VIA Pixetto
Step 5: Connecting VIA Pixetto to an Arduino board thru expansion board
Step 6: Programming VIA Pixetto with blocks
Step 7: Uploading the code to the Arduino board

Step 1
We need to attach the expansion board onto the Arduino board via pin header connectors.

Installing expansion board to an Arduino board

Step 2
First, insert the LED light to the 4th and 5th position on the blue brick (located right above D4)

Step 3
You will need to connect your VIA Pixetto to your PC using a Micro USB 2.0 cable.
When you see that the green, blue and red LEDs are lit, this means the VIA Pixetto is successfully connected.

Connecting the VIA Pixetto to a PC

Do not forget to remove the lens cover.

Step 4
Open the VIA Pixetto Utility and configure the VIA Pixetto to detect faces by selecting the Face Detection function.

Configuring the VIA Pixetto

When you are finished configuring the VIA Pixetto, you can test it to make sure it can detect faces.

Configuring the VIA Pixetto

Step 5
First, connect the Grove cable to the VIA Pixetto vision sensor.

Connecting VIA Pixetto to an Arduino board thru expansion board

Then, attach the other end of the Grove cable to the Grove connector labeled ‘UART’ on the expansion board, which is in turn attached to the Arduino board.

Connecting VIA Pixetto to an Arduino board thru expansion board

Step 6
Open the VIA Pixetto Junior application and build the blocks for face detection which would activate the piezo buzzer.
A. First layer of blocks
Select the first layer from the Control category, which is the ‘setup’ block, then add the ‘initialize vision sensor’ block from the Vision Sensor category.
This block will relate information to VIA Pixetto.

Programming VIA Pixetto with blocks
Programming VIA Pixetto with blocks

Place the ‘initialize vision sensor’ block within the setup block.

Programming VIA Pixetto with blocks

Lastly, select pins 0 for RX, and pin 1 for TX. ‘RX’ means receive and
‘TX’ means transmit.
This makes sure there is a connection between the Arduino board and VIA Pixetto.
Note: We recommend using pins 0 and 1 for optimal reliability.
B. Second layer of blocks
Now, we create the blocks which make the piezo buzzer emit sounds.
The first step is to select the ‘If () Then’ block from the Control category to create an event.
Then, from the Vision Sensor category, select an ‘object is detected’ block and put it inside the ‘If () Then’ block. This makes VIA Pixetto report that it is detecting an object (face) using a command from the Arduino board.
The block inside is ‘object is detected’. If this condition is true, the block inside will activate the event.

Programming VIA Pixetto with blocks
Programming VIA Pixetto with blocks

To make this true, use another ‘If () Then’ block again to create an event. This will allow the VIA Pixetto to detect any faces.

Programming VIA Pixetto with blocks

Insert the second ‘If () Then’ block into the first ‘If () Then’ block to create an event. This will allow the VIA Pixetto to detect an object (face).

Programming VIA Pixetto with blocks

Next, select a ‘logic’ block from the Logic category. Then, select the ‘object type’ block and ‘0’ block from the Vision Sensor category.

Programming VIA Pixetto with blocks

Insert an ‘object type’ block and ‘0’ block into the ‘logic’ block. Then, set the ‘logic’ block to equal sign.

Programming VIA Pixetto with blocks

Put the ‘logic’ block inside the ‘If () Then’ block.

Programming VIA Pixetto with blocks

Next, from the ‘Inout’ category, pull out two of the ‘put bulit-in LED to logic state ()’ block. Set the state of the first block to high and the second to low.

Programming VIA Pixetto with blocks

Insert the ‘put bulit-in LED to logic state ()’ block into the second ‘If () Then’ block. This block makes sure that when the VIA Pixetto reports it has detected an object (face), the Arduino board will command the LED light to flash.

Programming VIA Pixetto with blocks

Next, add a ‘delay ()’ block. Select the ‘delay ()’ block from the Control category.

Programming VIA Pixetto with blocks

Set the ‘delay ()’ block to 100 milliseconds. The ‘delay ()’ block will provide a delay between each flash (the delay time can be adjusted according to personal preference).

Programming VIA Pixetto with blocks

Put the ‘delay ()’ block into the second ‘If () Then’ block between the ‘put bulit-in LED to logic state ()’ blocks.

Programming VIA Pixetto with blocks

From the Control category, select the ‘repeat while ()’ block. Then, select the ‘object is detected’ block from the Vision Sensor category.
These blocks will allow the LED light to continue to flash as long as the VIA Pixetto detects faces.

Programming VIA Pixetto with blocks

Insert the ‘object is detected’ block into the ‘repeat while ()’ block.

Programming VIA Pixetto with blocks

Lastly, put the ‘repeat while ()’ inside the second ‘If () Then’ block underneath the ‘delay ()’ block.

Programming VIA Pixetto with blocks

Review the composed blocks and make sure they are in order. Double check the pins, the frequency, and the time values to make sure they are correct.
If the pins are incorrectly selected within the different blocks, the LED light may not flash when it detects a face.

Programming VIA Pixetto with blocks

Step 7
After completing and reviewing the blocks, upload the code to the Arduino board.
A. How to connect the Arduino board to PC
First, connect the Micro USB 2.0 cable to the PC using a USB 2.0/3.0 port. Then, connect the other end of the cable to the Micro USB 2.0 port on the Arduino board.

Uploading the code to the Arduino board

B. How to upload the code
Click the ‘No Hardware’ dropdown arrow n the top of the VIA Pixetto Junior app, then select ‘Arduino UNO’ to begin establishing the connection.

Uploading the code to the Arduino board

Then click on the ‘Not Connected’ dropdown arrow, a pop-up screen will be displayed. Click the ‘Connect’ button to establish the connection.

Uploading the code to the Arduino board

You can use the refresh button if the USB connection is not found on the PC. The COM port should be set to COM7 (Note: The COM port may vary depending on your PC’s configuration).

Once connected, click on the ‘Go to Editor’ button to go back to the VIA Pixetto Junior application.

Uploading the code to the Arduino board

Click on the ‘Upload’ button on the right side of the VIA Pixetto Junior app to upload the code to the Arduino board.

Uploading the code to the Arduino board

Make sure the ‘Upload Success’ message is shown before unplugging the cable.

Uploading the code to the Arduino board
Uploading the code to the Arduino board

C. How to save your project
We can save our project after we have uploaded the code to the Arduino board.
First, click on the icon next to ‘Project’ to open its scrolling menu and select ‘Save Project As’.

Uploading the code to the Arduino board

When we click on ‘Save Project As’. A Save As window will pop-up on screen. We can name the project and create or find a suitable folder to save our project.

Uploading the code to the Arduino board

Now that we have connected the VIA Pixetto vision sensor, attached the LED Light, and uploaded the code to the Arduino board, it is time to do some test runs. Just point your VIA Pixetto at a person’s face to see if the alarm sounds. (Note: you can make your own outer case for your face detection alarm to protect the individual project components).
And we are done! We have successfully used VIA Pixetto’s face recognition abilities and a LED light to create an intelligent lamp that flashes when it sees a human face.

Have fun with this project and don’t forget to share your own blocks creations with us on Facebook and Instagram at #VIAPixetto!

Share this blog post!

Share on linkedin
Share on twitter
Share on facebook

Leave a Reply