Arduino Image Processing based Entrance lock Control System
Description:
This tutorial is focused on Image Processing using Visual Basic 2010 Express Version, Arduino UNO or Mega and a 12 Volt Electronic Key. The aim of this tutorial is to use Human Detection to automatically control the Entrance Lock. Using the frontal Face XML folder, humans are monitored in RealTime, once the human face is identified, then we find the human face’s x and y coordinates and then send a command to open the Entrance Lock to the Arduino Uno or Mega Board. Such commands are sent from the Visual Basic software in serial form.
Depending on the type of XML file they use, the same program can be used to record ears, nose, human body, hands and so on. All you need is to replace the XML file of Frontal Face with the one you want. You can use this project to track virtually anything you want.
You can also create a custom XML file for a specific object tracking that I will cover in another Tutorial.
The EmguCV is playing a key role in this venture.
Software used in this project:
- Visual Basic 2010 Express Edition
- Arduino IDE
The Amazon Purchase links are given below:
WebCam night vision supported: best deal on Amazon: https://amzn.to/2teazro
electronic lock: https://amzn.to/37e93V0
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx
DISCLAIMER:
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!
About the Electronic Lock:
Electronic locks are available in various shapes and sizes. But the working theory is exactly the same for all the Digital Locks. The difference can only be in the voltage and current that the electronic lock coil requires to be energized. The coil that creates the magnetic field when the desired voltage is applied is inside the electronic lock.
There are two wires in the electronic switch, one is the voltage and the other is the GND cable. The digital lock used in this tutorial has two cables. You can test the electronic lock by applying the voltage across the electronic lock’s two wires.
Since this tutorial is based on the Image Processing Automatic Entry Control System, we will need a driver circuit for this Electronic Lock to control this Electronic Lock automatically. Using a relay, NPN transistor, or MOSFET, this lock can be operated automatically. As we only aim to open and close the electronic lock in this project and as we do not use any PWM or fast switching, Relay is the best choice in this project. Isolation will also be provided by the use of a relay.
image-processing Circuit Diagram:
As you can see, the circuit diagram is very simple. The electronic lock is controlled by means of a relay type SPDT “Single Pole Double Throw,” which is a 12v relay. As you can see in the circuit diagram, the electronic lock attaches the 12v wire from the power supply, it really doesn’t matter to which wire you connect it.The relay’s normally open connection is connected to the other electronic lock wire While the power supply ground is connected to the relay’s specific contact.
Using the relay motor, this relay is operated. A 2n2222 NPN transistor and 10k resistor are used in the relay driver. Please check the coil current of the electronic lock before choosing the transistor. To find the current, you must first find the resistance of the electronic lock coil, the voltage is already known to be 12v, then use the Ohm rule.
V = IR
You can measure the current. Use the NPN transistor whose measured value is the current of the collector. Pick a transistor whose collector current is 3 times higher than the calculated value for the best performance.
The Arduino electronic pin 13 controls the relay as shown in the above circuit diagram and ensures that the Arduino ground is connected to the 2n2222 NPN transistor emitter.
image processing Arduino Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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() { 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 Image Processing Application Programming:
You will need to install the following two software to design the image processing application. Edition and EmguCv are expressed by Microsoft Visual Basic 2010. That’s how it looks like the final form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
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 |