Introduction: Very Simple Arduino Electric Lock

Picture of Very Simple Arduino Electric Lock

This is a instructable for a very simple Arduino controlled electric lock.

The key idea here is to be very simple as this was more of a proof of concept prototype type of thing.

The Arduino is used as a switch to control the lock itself, and is set to interface with a Computer.

The Computer sends serial data to the Arduino in which allows the electronic lock to be opened.

The Computer itself allows many different ways of opening this lock such as just pushing a button, reading a bar code scanner, and even over Bluetooth with a Windows Mobile device.

I used this simple project as a fun way of learning the basics of a few different things,
such as Arduino programming, Bluetooth integration, Bar code scanners and Serial communication

Step 1: Parts

Picture of Parts

Well first you need a Arduino, i used a Diecimila but any type would work.

The lock i am using is La Gard ENV 1300 type lock, i bought like 6 of them for 10 bucks on EBay.
You can not use just any type of lock, like a regular door lock, it must be electronic based.

It needs to work in the following manner: Inside this lock is a deadbolt, now what keeps this deadbolt closed is a very simple electromagnet. When you put power through this electromagnet it allows the lock to be open. If it does not have this simple electromagnet inside then it will not work . A simple door lock that uses a key and pins and tumbler will not work.

I included a picture of the inside of the lock where you can see how it works: Power goes to the electromagnet which pulls back a pin that releases and frees a wedge. This wedge then allows the door to be unlocked.

Theoretically you could create your own electromagnetic lock, or use a simple motor or something but that is for a different instructable.

You will also need a basic transistor: I used a 2N2222 from radio shack

Now if you want to open it through other means than just the computer your need:

A Bluetooth phone, i am using a Touch Pro with Windows Mobile

A bar code scanner, i am using a Symbol CS1504

In the last picture you see a door knob, this door knob has a wooden square knob glued to the bottom to fit in the square peg on the lock, its used to open the lock.

Step 2: Arduino

Picture of Arduino

The wiring of the Arduino is very simple.

Its just a very simple set up with a transistor. 2N2222 from radio shack
Now i tried it with a few resistors and was having some problems so i just went without them.
Feel free to correct me on that.

The transistor is connected as so:
The signal from the Digital port is connected to the transistors base.
The power from the Arduino is going through the lock back out and to the collector on the transistor
Then it is going out the emitter to the Ground on the Arduino

The code is very simple it takes any data from the serial port and sends signal to the port, delays then ends the signal.

Once again, very simple:

/*
Test to use serial port to open/close lock
*/
int inByte = 0;

void setup()
{
  //Start serial
  Serial.begin(9600);
  pinMode(3,OUTPUT);
}

void loop()
{
//check for connection
if (Serial.available() > 0)
  {
  inByte = Serial.read();
   digitalWrite(3,HIGH);
   delay(1000);
   digitalWrite(3,LOW);
 }
}

Its just like it looks, any serial data it picks up on that port it opens the lock for 1000 milliseconds.

Very Simple

Step 3: LockApp

Picture of LockApp

Now i created a application and split it into parts:

Button - where you push the button and it sends data to the Arduino to open

Bar code - it access a bar code scanner data and checks for a specific code, if it see it it opens the lock

Blue Tooth - Using a WinMo phone it it picks up the correct data through the blue tooth serial connection it opens the lock

Settings - where you tell it what COM ports each device is using

Each one sends data to the Arduino in the same fashion,
It pulls the COM port from the settings menu,
opens a connection,
sends data,
closes port
Update status

Like so:
C#:

infoLabel1.Text = "OPENING";
try
 {
                SerialPort port2 = new SerialPort(lockCom.Text, 9600);
                port2.Open();
                port2.Write("open");
                port2.Close();
                for (int i = 0; i < 100; i++)
 {
                    infoLabel1.Text = "OPEN";
 }
                infoLabel1.Text = "LOCKED";
}
            catch (System.Exception exp)
{
                infoLabel1.Text = "CONNECTION PROBLEM";
}

So on the button Tab if you hit Open it run the above code.


Step 4: Barcode

Picture of Barcode

Now on the Barcode tab, the code first calls the barcode scanner a Symbol CS1504

Motorola has a c++ SDK out for this model, but i dont feel like converting or dealing with it so i hunt down a C# library that is already done, i find: http://boss.bekk.no/display/BOSS/BarcodeLibrary

This library is very simple to work with:

try
            {
                BarcodeLibrary.BarcodeFunctions barcode = new BarcodeLibrary.BarcodeFunctions(barscanCom.Text);

                barcode.Interrogate();

                List scannedCodes = new List();

                scannedCodes = barcode.GetBarcodes();

                if (scannedCodes.Count != 0)
                {
                    TESTCODE = scannedCodes[0].Code;
                    barcode.ClearBarcodes();

                    if (CODE == TESTCODE)
                    {
                        bsLabel.Text = "ACCEPTED";
                        SerialPort port = new SerialPort(lockCom.Text, 9600);
                        port.Open();
                        port.Write("open");
                        port.Close();
                        for (int i = 0; i < 100; i++)
                        {
                            infoLabel2.Text = "OPEN";
                        }
                        infoLabel2.Text = "LOCKED";
                    }
                    else
                    {
                        bsLabel.Text = "DENIED";
                    }
                }
                else
                {
                    bsLabel.Text = "NO CODES DETECTED";
                }
            }
            catch (System.Exception exp)
            {
                bsLabel.Text = "Barcode Scanner Problem";
            }

It calls the Scanner and retrieves JUST THE FIRST CODE saved on the scanner (i was to lazy to search through them all) and once it picks it up it deletes all the saved codes.

It then compares and if it is valid it uses the previously explained code (to lazy to make it into a function) to open the lock.

Very easy.


Step 5: Bluetooth and BlueLock

Picture of Bluetooth and BlueLock

Now its Bluetooth's turn, i created a very simple program for Windows Mobile that asks for the COM ports for bluetooth and sends data to it when you hit send.

Once you hit send on this code, called blueLock
you then hit Scan and Open on the PC and it will scan for the data from the device and open the lock.

blueLock Windows Mobile code:

public Form1()
        {
            InitializeComponent();
            string[] ports = SerialPort.GetPortNames();
            comboBox1.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)
                comboBox1.Items.Add(ports[i]);
            comboBox2.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)
                comboBox2.Items.Add(ports[i]);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SerialPort port = new SerialPort(comboBox1.SelectedItem.ToString(), 9600);
            port.ReadTimeout = 1000;
            port.Open();
            port.Write("Test");
            port.Close();
        }

the Bluetooth Code from lockApp:

private void btButton_Click(object sender, EventArgs e)
        {
            btLabel.Text = "Scanning";
            try {
            SerialPort port = new SerialPort(btInputCom.Text, 9600);
            port.Open();
            blue = port.ReadByte();
            port.Close();
            if (blue != 0)
            {
                btLabel.Text = "SUCESS!";
                SerialPort port2 = new SerialPort(lockCom.Text, 9600);
                port2.Open();
                port2.Write("open");
                port2.Close();
            }
            else
            {
                btLabel.Text = "ERROR";
            }
            }
            catch (System.Exception exp)
            {
                btLabel.Text = "Barcode Scanner Problem";
            }

        }

Step 6: Ending

Picture of Ending

The idea behind this was simplicity as you hopefully as noticed to get a better understanding of Arduino, Bluetooth, Barcode, Serial Connections and hardware communication



Comments

BurhanH2 (author)2017-10-02

how to you know lock fail open or fail lock?

RKlenka (author)BurhanH22017-10-02

You can't under the current set up. There is nothing electronically set up from the lock to tell you if it is locked or unlocked. Only that you sent the command to it. I'm sure there are ways to do so, a different lock, a extra sensor, ect. But testing if it actually locked or unlocked, short of just manually testing, was not included in this instructable.

BurhanH2 (author)RKlenka2017-10-30

Thanks for your respond, its possible if i use dropbolt(lockdoor) 5 wires with NC NO dan COM, i can get value if fail lock or fail open?, thanks

itsmecris191 (author)2017-09-15

Hi sir. can i use electric rim lock for this project ? thank you

RKlenka (author)itsmecris1912017-09-15

They should work very similarly, but those locks use a lot more power than the small one I used. But the idea should be the same.

itsmecris191 (author)RKlenka2017-09-15

but it will work ? when i use the electric rim lock thankyou sir !

help me guys

LuisM260 (author)2016-08-08

Great tutorial! Do you think I can make it on the inverse, in terms of making the arduino open the door when power is out?

the thing is, I want to install sth similar, running on batteries and with a WiFi shield to send the signal ("please, open the lock") via Internet. But I don't want the door to keep locked once the battery runs out. I prefer the door opening in this case (yes, the whole thing would be useless by then, but you can change the batteries). So I thought that maybe, if with the 12v I could make the lock keep closed instead of opening, then I could bypass the problem of not being able to ever open the door again because I've run out of batteries.

I still have to do my research and see if I can definately power this whole system with a handful of AA batteries.

Thank you

RKlenka (author)LuisM2602016-08-30

You could but it would eat up batteries pretty fast. Here the spring keeps the door lock, and when it gets power it charges the electromagnet that pulls back the pin to unlock. If you invert it you would have to flip that some how where the power is always on pushing the pen to keep it locked.

What i would do is have a way to supply backup power to the unit. For example i have a electronic lock that i use on a door in the house. The batteries are kept inside the locked area, so if the power goes out there isnt a way to access it from the outside. So what the company did was put a connector hidden on the outside, so if the power went out i just had to connect a battery to the front to power it long enough to open the door.

JosephJ27 (author)2016-04-19

Will this work if I use a Single Door Magnetic Lock?

RKlenka (author)JosephJ272016-04-20

If its a simple electronic one that just needs a current of some kind to open then it should work fine.

JosephJ27 (author)RKlenka2016-04-21

Thanks. Its just a simple magnetic door lock.

JosephJ27 (author)RKlenka2016-04-21

Thanks. Its just a simple magnetic door lock.

derrickg7 (author)2016-02-13

If I wanted to use multiple barcode ( s ) to open one lock could I

daznovia (author)2014-03-18

would it works with a 12v working voltage operated electric door lock ?

RKlenka (author)daznovia2014-09-18

It should, you would just have to adjust all the resisters and stuff accordingly.

mkanoap (author)RKlenka2015-06-24

You would need to provide a separate 12 volt supply to the lock, not use the 5volts from the arduino. Depending on the amount of current (not voltage) the lock uses, you may need a mosfet instead of a transistor.

lights0123 (author)mkanoap2015-06-27

A mosfet is a type of transistor.

mkanoap (author)lights01232015-06-28

You are correct. I should have said "a mosfet instead of a basic transistor like this."

kingsleyumoh (author)2014-05-09

Its an awesome project. sir please what if you want to use a hand shape scan to control the lock?.

RKlenka (author)kingsleyumoh2014-09-18

Idea is the same. You just need a hand shape scanner to send something to the Arduino (or to the computer that passes it on) or could just make a Arduino powered hand scanner.

shadinfrada (author)2014-09-18

This is probably a stupid question, but could you this this for Windows Phone 8? And would you need a bluetooth module to control this from that?

RKlenka (author)shadinfrada2014-09-18

WP8 is a little tricky when it comes to bluetooth but it should be possible on WP8, though it wont work on WP7.

You can either do it through a computer like i did, or with a bluetooth module on the Arduino.

You should be able to also do with through a wifi based method as well.

gluvit (author)2014-05-12

This is great

rhymer28 (author)2013-07-05

Sir did you use any data base server to store the barcode?tnx.

RKlenka (author)rhymer282013-07-05

Not in this one. Though you could if you wanted to i guess. I think i just scanned the barcode before hand and saved it as CODE to have it to compare with. So no, i did not use a database to store the barcode.

nelo_007 (author)2013-01-22

hola amigo me interesa el diagrama electronico me lo puedes proporcionar y las cosas que utilizaste para poder hacer este proyecto saludos

nickstewartroc (author)2011-02-21

Can you guys help me out, I can't seem to find the right lock anywhere! I've looked for a week now, and nothing, any that I do find are with keypad and 80 dollars, Thanks,
Nick

RKlenka (author)nickstewartroc2012-01-31

Yea this lock is rather tricky, they cost more when they include the electronics:
This one looks like it has two but they might be different: http://www.ebay.com/itm/Lot-LaGard-Smart-Link-Electronic-Safe-Lock-Parts-Locksmith-/300655167002?pt=LH_DefaultDomain_0&hash=item460071c61a
same as above: http://www.ebay.com/itm/Lot-LaGard-Smart-Link-Electronic-Safe-Lock-Parts-Locksmith-/300655167023?pt=LH_DefaultDomain_0&hash=item460071c62f
I guess just keep checking for La gard locks: http://www.ebay.com/sch/i.html?_nkw=la+gard+locks
you could check with local locksmith and see if they have any of the lock units they dont want.

RKlenka (author)nickstewartroc2011-02-21

here is the cheapest one i can find at 45:
http://cgi.ebay.com/Gard-Combo-Guard-Electronic-lock-Kaba-Mas-3750-/120688325588?pt=LH_DefaultDomain_0&hash=item1c1995b3d4
not that many on ebay right not it seams:
http://cgi.ebay.com/SecuRam-Chrome-Electronic-Safe-Lock-LaGard-S-G-Amsec-/260738355156?pt=LH_DefaultDomain_0&hash=item3cb5378fd4

I guess just keep waiting and looking, what your paying most for is the keypad when we only need the lock, i guess you could contact them and ask if they would just sell you the lock.

tmhawley (author)2012-01-30

This is the exact project i'm trying to do. However, I can not find any of the dang locks for under 20$ and as I'm trying to do this for multiple doors this would be pricey. By chance anyone has any recent links to cheap electronic locks? All i can find are electronic door strikes and expensive keypad all in one electric door locks. Thanks for suggestions!

kelevra88 (author)2012-01-13

How did you create the application ??

RKlenka (author)kelevra882012-01-16

In Visual Studio 2008 with the code i listed above, should world in the Express editions as well

febbie (author)2011-09-25

can you give us a more detailed connection of the transistor with the arduino...i am really confuse on where to connect the ground and as well as the wires going to the lock.i hope you could help us..

febbie (author)febbie2011-10-10

thank you for being so helpful..we deeply aappppreeciiateeee iiiittt!!
we'll let you know what happened to our project when the right time comes..:)

RKlenka (author)febbie2011-09-26

I rewrote some parts and added a new diagram let me know if that helps

raziiq (author)2009-12-17

 Well First of all, its an amazing project. This is exactly what i am looking for.  I need a little of your help in this project.

I got the Arduino end of the Project, and the program is also simple, thanks for that. But i couldnt understand the Hardware part (The Lock part ) of the project. What actually going inside the lock is a bit fuzzy in my mind, can you please explain that in more detail.

Thanks in advance.


RKlenka (author)raziiq2009-12-17

Sure, the idea was to find a electronic lock that would unlock when power (5v) is sent to it or taken from it. That was all i had to do was to send it a signal with and it would unlock.

This lock i found on ebay, it i remember correctly is that it was used in a bank to secure the cash drawer.

How it works is that it has a dead bolt(the big grey bar sticking out) that is kept locked by a small gray wedge. This wedge has a hole in it, a pin is stuck through this hole and into a electro-magnent and a spring to keep the pin in place. When there is no power the spring pushes the pin through the hole in the wedge. The wedge then can not be open becouse the pin is in the way. But when given power the electro-magenet pulls the pin into the magents housing freeing the wedge so it can be unlocked. when power is removed the spring pushes the pin back into place with the wedge.

This lock though must be turned (the door knob in the pictures) to move the dead bolt, the dead bolt does not open on its own.

You can find a few like this on ebay, just make sure your buying the lock unit and not the keypad unless, your want the keypad. I got 4 of these for like 5 bucks.

raziiq (author)RKlenka2009-12-17

Thank you for that kind explanation. I thought you added something to that ordinary lock. So basically lock has got all the things like Spring and wedge by default and you are controlling the current using the pins of Arduino, so basically Arduino is acting like a switch here.

BTW do you know the actual name of this door lock??

I found this lock, but dont know if its gonna work like your lock or not?

cgi.ebay.com/Slightly-Used-Schlage-Deadbolt-Door-Lock_W0QQitemZ280437876852QQcmdZViewItemQQptZLH_DefaultDomain_0

RKlenka (author)raziiq2009-12-17

Nope the one you listed is just a plain old deadbolt lock, try ebaying for electronic lock, start at the cheapest price and your find some:
http://cgi.ebay.com/DAMAGED-HIGH-SECURITY-GUN-SAFE-ELECTRONIC-LOCK-LA-GARD_W0QQitemZ290381081936QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item439c0fad50
or
http://cgi.ebay.com/Lagard-3600-electronic-safe-lock_W0QQitemZ300378252492QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item45eff064cc
or
http://cgi.ebay.com/Lagard-3600-electronic-safe-lock_W0QQitemZ300378252446QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item45eff0649e
or
http://cgi.ebay.com/Sargent-Greenleaf-Used-Electronic-Safe-Lock-For-Parts_W0QQitemZ320462290269QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item4a9d0a7d5d

The lock i have is a La Gard ENV 1300

falcon74 (author)RKlenka2010-09-16

Hi RKlenka,

Firstly, thanks for sharing an excellent project, pretty neat and well done.
Just wondering however, as to are these the $8.99 locks that are found all over eBay now ? All of those other links do not show up, as they are obviously quite dated (9-10 months old).

cheers,
F74

RKlenka (author)falcon742010-09-17

Added a image collage if that helps.

Some EBay links:
http://cgi.ebay.com/LG-High-Security-Electronic-Lock-Keypad-Mod-3260-/280561484827?pt=LH_DefaultDomain_0&hash=item4152c4841b

http://cgi.ebay.com/AMSEC-ESL10-ELECTRONIC-SAFE-LOCK-/110585396489?pt=LH_DefaultDomain_0&hash=item19bf673d09

http://cgi.ebay.com/LAGARD-Electronic-lock-6-digit-CODE-3800-type-GUN-SAFE-/220667625063?pt=LH_DefaultDomain_0&hash=item3360d0be67

and maybe even this one
http://cgi.ebay.com/Diebold-Lubricated-Lock-17408A-Keyless-Electronic-NEW-/110582245802?pt=LH_DefaultDomain_0&hash=item19bf3729aa

and if all else fails i might have a few somewhere still

raziiq (author)RKlenka2010-10-17

After some hectic months with my Uni Study now i have some free time to try this project, but the problem is i still cant find myself an electronic Lock, the ones i searched on the internet are really expensive.

raziiq (author)RKlenka2009-12-17

 Thank you for your instant reply. I ll look at these locks, thanks :)

Hoping for your kind support in future 

shelley_fox (author)2010-02-04

Hi, this is a great little project and I'm really looking forward to trying it out!  Could you please give me the specs for the transistor that you've got in there?  Also, is there any way that you could include a little schematic of how it is wired in, I can't quite make out how you've done your connections from the pictures.

Thank you!

RKlenka (author)shelley_fox2010-02-12

It is using a 2N2222 transistor there like 3 bucks for a box of 10 or something at radio shack, 

The signal from the Digital port is connected to the transistors base.
The power from the Arduino is going through the lock back out and to the collector on the transitor
Then it is going out the emitter to the Ground on the Arduino

Ill try and get a schematic up

lemonie (author)2009-11-23

Can you take the plate of to show the mechanics of the electromagnetic lock?

L

RKlenka (author)lemonie2009-11-23

Yes i will add it to the parts area

lemonie (author)RKlenka2009-11-23

I see it - thanks

L

About This Instructable

113,186views

172favorites

License:

More by RKlenka:Powermat your carTransparent lockscreen for Windows Phone 7 MangoPowermat your phone (in this case my HTC Arrive)
Add instructable to: