ArduinoArduino Projects

Arduino Image processing CCTV camera system application designing and programming

Arduino image processing


Arduino Image processingIn this tutorial you will learn how  to use image processing,  Arduino Uno and PIR  sensor to create your own Arduino based CCTV camera device. “Visual Basic” will be used to create the image processing program in this tutorial application works in conjunction with the Arduino Uno connected PIR sensor. Once both the PIR sensor and the image processing application detect the human, a picture is automatically  captured and stored in a folder.

Visual will be used for the image processing software. It’s really easy to model image processing applications in The Frontal face XML archive is used in this application for human identification.Once the computer application detects the human face and also receives a signal from the Arduino, a picture will be taken automatically and stored in the desired folder.

The Amazon Purchase links are given below:

Pir motion sensor:
the best camera with night vision: “Must purchase this one”:
Arduino Uno:
Mega 2560:
lm7805 Voltage Regulator:
330-ohm resistors pack:
female DC power jack socket:
470uf capacitors:
5×7 cm Vero board:
female headers:
connection wires:
Super Starter kit for Beginners:
Jumper Wires:
Bread Board:
12v Adaptor:
PCB plate:
Variable Supply:
Digital Multimeter:
Vero Board / stripboard:
Soldering iron kit: “best” You guys should definitely purchase this:
Solder wire:
Wire Stripper:

PCB small portable drill machine:


Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Circuit Diagram:

Arduino image processing

As you can see, the circuit diagram is really simple, all you need is to link the PIR sensor to the Arduino Uno pin number and the Arduino 5v and ground VCC and ground respectively.

Arduino Programming:

It’s very simple to program Arduino. First I define the PIR sensor pin. The PIR sensor is attached to the number 4 pin of the Arduino. You can use any other Pin if you want. Then the flag variable type integer is specified. Initially this parameter is set to Zero. Use the variable flag to stop unnecessary code repetition.

int pirsensor = 4; // pir sensor connected with 4
int flag = 0; 

If used before the name of the function, the word void means that this function has no type of return. If you look, the parenthesis will also be null, meaning that this function does not take any argument as the output. So there is no return form for the void setup function and it does not take any argument as the output.

For this reason, we use a Serial.begin() function to enable the Serial communication, this is an integrated function and takes one argument as the output, which is the baud rate. Using the pinMode function, the PIR sensor is set to output. Only once the controller is turned on, the void setup function is executed.

void setup()
  pinMode(pirsensor, INPUT); 
  digitalWrite(pirsensor, LOW); 
  Serial.println("hi how are you"); 

The role of the void loop runs endless times before you stop it. There is also no return form for the void loop function and it does not take any argument as the output.

As you can clearly see, the void loop function consists of only two if conditions, the purpose is to find out if the PIR sensor has been detected in motion and send the desired message using the Serial.print function to the computer  application.You may have noticed one thing that changes the status of the flag every time. This is simply to stop the unnecessary repetition and only send the message once the human is detected.

void loop()

  if( (digitalRead(pirsensor) == HIGH)&& (flag == 0))
    Serial.print("intruder detected"); 
    flag = 1; 
  if( (digitalRead(pirsensor) == LOW)&& (flag == 1))
    Serial.println("no Intruder"); 
    flag = 0; 


Computer Image Processing Application programming:

Imports Emgu.CV
Imports Emgu.CV.Util

Imports Emgu.CV.Structure
Imports System.Diagnostics

Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    Dim count As Integer = 0

    Dim facedetected As Integer
    Dim facepresent As Integer
    Dim web As Capture = New Capture(0) ' camera number

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    End Sub

    Private Sub wait(ByVal interval As Integer)
        Dim sw As New Stopwatch
        Do While sw.ElapsedMilliseconds < interval
            ' Allows UI to remain responsive
    End Sub

    Sub faces()
        Dim photo As Image(Of Bgr, Byte)

        photo = web.RetrieveBgrFrame

        Dim currentCenter As New Point()

        Dim facedetection As New CascadeClassifier("C:\data\haarcascades\haarcascade_frontalface_default.xml") ' this one is for the face detection

        facedetected = 0

            Dim image As Image(Of Gray, Byte) = photo.Convert(Of Gray, Byte)()

            For Each face As Rectangle In facedetection.DetectMultiScale(image, 1.1, 8, Size.Empty, Size.Empty) ' default 1.1, 8  ( while best values are 1.2 and 17 after checking)

                photo.Draw(face, New Bgr(Color.White), 4)

                currentCenter.X = CInt(CDbl(face.X + face.X + face.Width) / 2.0)
                currentCenter.Y = CInt(CDbl(face.Y + face.Y + face.Height) / 2.0)

                Label2.Text = (currentCenter.X).ToString
                Label3.Text = (currentCenter.Y).ToString

                Dim f = New MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5)
                photo.Draw("Human detected", f, currentCenter, New Bgr(0, 255, 0)) ' New Point(10, 80) 

                Dim f2 = New MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.7, 0.7)
                photo.Draw("human detectioin and tracking system", f2, New Point(10, 20), New Bgr(0, 255, 255)) ' New Point(10, 80)

                Label4.Text = face.ToString

                facedetected = 1  ' we are storing 1 if faces are detected.


            PictureBox1.Image = photo.ToBitmap

        Catch ex As Exception

        End Try

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "com5"
        SerialPort1.BaudRate = "9600"
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        count = count + 1
        TextBox1.Text = count

        Dim photosave As Image(Of Bgr, Byte)
        photosave = web.RetrieveBgrFrame
        photosave.Save("E:\youtube tutorials\1 image processing security system\pictures\  fahad" + TextBox1.Text + ".jpg")

    End Sub

    Private Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived


            Dim mydata As String = ""
            mydata = SerialPort1.ReadExisting()

            If TextBox2.InvokeRequired Then
                TextBox2.Invoke(DirectCast(Sub() TextBox2.Text &= mydata, MethodInvoker))
                TextBox2.Text &= mydata
            End If
        Catch ex As Exception
        End Try
    End Sub


    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If (InStr(TextBox2.Text, "intruder detected") And (facedetected = 1)) Then
            count = count + 1
            TextBox1.Text = count

            Dim photosave As Image(Of Bgr, Byte)
            photosave = web.RetrieveBgrFrame
            photosave.Save("E:\youtube tutorials\1 image processing security system\picture pir\  fahad" + TextBox1.Text + ".jpg")
            TextBox2.Text = ""
        End If
    End Sub
End Class

Watch Video Tutorial

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button