Arduino Projects

Arduino Image Processing based Entrance lock Control System

Arduino Image Processing Project Description:

 

Arduino Image Processing- This Project is based on Image Processing using Visual Basic 2010 Express Edition, Arduino Uno or Mega, and a 12 Volt Electronic Lock. The purpose of this project is to automatically control the Entrance Lock using Human detection. The humans are tracked in RealTime using the frontal Face XML file, once the human face is detected, then we find the X and Y coordinates of the human face and then send a command to the Arduino Uno or Mega Board to open the Entrance Lock. These commands are sent serially from the Visual Basic application.

The same application can be used to track Eyes, nose, human body, hands, and so on, depending on the type of the XML file we are using. All you need is just to replace the Frontal Face XML file with the one you want. This way you can use this Project to track almost anything you want.

You can also create your custom XML files for tracking a specific object. I will cover this in another Tutorial.

In this project, the EmguCV plays a key role. For the detailed discussions, application designing and program explanation watch a video at the end of this article.


Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

WebCam:

12v Electronic Door Lock / Elock / Solenoid Lock:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*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!


Softwares used in the Arduino Image Processing:

  1. Visual Basic 2010 Express Edition
  2. Arduino IDE

About the Electronic Lock:

image processing

Electronic Locks come in different shapes and sizes. But the working principle of all the Electronic Locks is exactly the same. The difference can only be in the voltage and current it requires to energize the coil of the electronic lock. Inside the electronic lock is the coil which creates the magnetic field when the desired voltage is applied.

The Electronic Locks usually has two wires, the voltage wire, and the GND wire. The Electronic lock that we will be using in this project has two wires. The electronic lock can be checked by applying the voltage across the two wires of the electronic lock.


As this project is based on the Automatic entrance controlled system using image processing, in order to control this Electronic Lock automatically we will need a driver circuit for this Electronic Lock. This electronic Lock can be controlled automatically using a relay, an NPN transistor or a MOSFET. As in this project our only aim to open and close the electronic lock, and as we are not using any PWM or fast switching, so in this project Relay is the best choice. Using relay will also provide Isolation.

Arduino Image Processing, Electronic Lock Circuit Diagram:

image processing

The circuit diagram as you can see is very simple. The electronic lock is controlled using an SPDT “Single Pole Double Throw” type relay, which is a 12v relay. As you can see in the circuit diagram the 12v wire from the power supply is connected with the electronic lock, it really doesn’t matter which wire you connect it to. The other wire of the electronic lock is connected with the normally open contact of the relay. While the ground of the power supply is connected with the common contact of the relay.

This relay is controlled using the relay driver. The relay driver simply consists of the 2n2222 NPN transistor and a 10k resistor.  The selection of the transistor depends on the coil current of the electronic lock. To find the current, first you will need to find the resistance of the electronic lock coil, the voltage is already known which is 12v, then using the Ohm’s law

V = IR

The current can be calculated. Now depending on the current value select any NPN transistor whose collector current is greater than the calculated value. For the best performance select a transistor whose collector current is 3 times greater than the calculated value.

As you can see in the circuit diagram above, this relay is controlled using the digital pin 13 of the Arduino, and make sure you connect the ground of the Arduino with the emitter of the 2n2222 NPN transistor.


Arduino Image Processing Arduino Programming:

int elock = 13; // machine gun trigger motor connected here 

void setup()
{

  Serial.begin(9600); 

    pinMode(elock, OUTPUT);
   
  // keep elock off by default

  digitalWrite(elock, LOW);
  
}

void loop()
{
 
 // data from computer, as per the image processing. signals from computer for the left and right movement of the machine gun and trigger. 
 
  while(Serial.available() > 0) // 
  {
    char received = Serial.read();

  if(received == 'd') // human not in front
 {

    digitalWrite(elock, LOW); 

 }
 
   if(received == 'c') // HUMAN FACE ON front
 {

digitalWrite(elock, HIGH);

 }
 
  }
}

Vb.net Arduino Image Processing Application Programming:

For the Arduino Image Processing application designing, you will need to install the following two Softwares:

Microsoft Visual Basic 2010 express Edition and

EmguCv

The EmguCv installation and setup watch the video available at the end of this Article.

This is how the final form looks like.


image processing
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 facedetected As Integer

Dim facepresent As Integer

Dim detectTimecount As Integer

Dim web As Capture = New Capture(0)

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

‘ cars()
faces()
End Sub

Sub faces()

Dim photo As Image(Of Bgr, Byte)
photo = web.RetrieveBgrFrame
Dim currentCenter As New Point()

‘ Dim eyedetection As New CascadeClassifier(“C:\data\haarcascades\haarcascade_eye.xml”) ‘ ‘ this one is for eye detection
Dim facedetection As New CascadeClassifier(“C:\data\haarcascades\haarcascade_frontalface_default.xml”) ‘ this one is for the face detection

facedetected = 0

Try
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)

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

Dim f = New MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5)
photo.Draw(“Human detected and scanning….”, 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 detection “, f2, New Point(10, 20), New Bgr(0, 255, 255)) ‘ New Point(10, 80)

Label3.Text = face.ToString

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

Next

PictureBox1.Image = photo.ToBitmap

Catch ex As Exception

End Try

If facedetected = 1 Then
lblfacedetect.Text = “Scanning…”
Timer3.Enabled = True

Else
lblfacedetect.Text = “no Human…”
Timer3.Enabled = False
detectTimecount = 0
facepresent = 0

‘ SerialPort1.Open()
‘ SerialPort1.Write(“d”)
‘ SerialPort1.Close()

End If

‘ new addition end

If detectTimecount >= 3 Then ‘ HUMAN FACE IN CENTER

‘ detectTimecount = 0
SerialPort1.Open()
Label4.Text = “Human detected”
SerialPort1.Write(“c”) ‘ the human is on front
SerialPort1.Close()

End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = “com8”
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 Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
detectTimecount = detectTimecount + 1
Label4.Text = detectTimecount
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
SerialPort1.Open()
SerialPort1.Write(“d”) ‘ no human
SerialPort1.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.Write(“c”) ‘ the human is on front
SerialPort1.Close()
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.Write(“c”) ‘ the human is on front
SerialPort1.Close()
End Sub
End Class

Arduino Image Processing Video Tutorial:

Other Arduino Image Processing Based Projects:

Arduino image processing Eye Pupil Tracking, how to make Haarcascade XML file

Arduino Image processing CCTV camera system using VB.net

OCR Optical Character recognition using VB.net and Arduino

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button