Face Detection with Arduino – Security System 2022 Project: Facial recognition is a very useful tool incorporated in many modern devices to detect human faces for tracking, biometrics, and recognizing human activities.

In this project, I have used the OpenCV’s Harr cascade classifiers for detecting human faces and the pan/tilt servo mechanism to track the user’s face using Arduino UNO.

How does it work?

Face Detection with Arduino – Security System IoT Project 2022: It identifies and localizes human faces and ignores any background objects like curtains, windows, trees, etc. OpenCV uses a Harr cascade of classifiers where each frame of the video is more responsible stages of classifiers and if the frame passes through all the classifiers, the face is present else the frame is discarded from the classifier i.e the face isn’t detected.

The OpenCV returns the cartesian coordinates of the image upon detection together with the peak and width. From these coordinates, the middle coordinates of the image are often calculated using x+width/2 and y+height/2.

Also Read: Tips for Authorizing Google Adsense Account – 2022

Apps And Online Services

  • Python version- 3.10
  • Arduino IDE
  • Open Cv

Components And Supplies

  • Arduino UNO
  • USB Camera or You can access a laptop or mobile Camera
  • SG90 Micro-Servo motor
  • Jumper Wires
  • Bread Board

Detecting the face

The function used for face detection is with the ‘scale factor’ value as 1.1(default) and the ‘min neighbor’ value as 6. This returns the cartesian coordinates of the image along with the height and width. Increasing the ‘min neighbor’ can improve facial detection but sacrifices execution speeds which would lead to a delayed response from the servo. Thus, the value 6 seemed optimal.

In order to have precise facial recognition, a plain background would be recommended as I faced some false detection due to the curtains in the background.


Connect additional 9V supply to Arduino.

Sending Serial data to Arduino

I found this part challenging as I tried many ways to send the coordinates sequentially to the Arduino but the response was slow. After spending hours figuring it out, I began looking for similar projects online until I found them at last and worked finally.

It made me aware of the Serial function Serial.parseInt() which takes integer inputs from an incoming serial of bytes(check here). My approach to sending the serial data is similar to the one used in that project.

The python sends the center coordinates in a single string. Ex: “X100Y200”, the value 100 after X represents center x-coordinate and 200 represents center-y coordinate.

Arrangement of Servo

Face Detection with Arduino: I have attached the horizontal moving servo on the shaft of the vertical moving servo in which the camera is mounted. All the attachments are made using simple rubber bands(I would not recommend it as I made use of existing material available at home).

As I am using 2 servos for tracking, an additional 9V supply would be recommended (by means of an adapter) to the Arduino to provide sufficient current for both the servos. In the absence of it, I have noticed some sort of vibration in them without making them move.

Libraries and Installations

This project requires pyserial and OpenCV libraries which I have downloaded using pip. My current python and OpenCV version is 3.8 and 4.4.0, so make sure you have a similar or a higher version. Also, make sure that the XML file for face detection is saved in the same directory which contains the python script.

The python script also requires some modification by entering the correct COM port of your Arduino before execution.

Also Read:

Also Read: Apple iPhone 13 Pro Max (256GB) – Latest Release

Also Read: Dashain 2021| Know Everything About Dashain This Year


Please enter your comment!
Please enter your name here