Very Simple Arduino Electric Lock





Introduction: 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

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

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

void loop()
//check for connection
if (Serial.available() > 0)
  inByte =;

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

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:

infoLabel1.Text = "OPENING";
                SerialPort port2 = new SerialPort(lockCom.Text, 9600);
                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

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:

This library is very simple to work with:

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


                List scannedCodes = new List();

                scannedCodes = barcode.GetBarcodes();

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

                    if (CODE == TESTCODE)
                        bsLabel.Text = "ACCEPTED";
                        SerialPort port = new SerialPort(lockCom.Text, 9600);
                        for (int i = 0; i < 100; i++)
                            infoLabel2.Text = "OPEN";
                        infoLabel2.Text = "LOCKED";
                        bsLabel.Text = "DENIED";
                    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

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()
            string[] ports = SerialPort.GetPortNames();
            comboBox1.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)
            comboBox2.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)

        private void button1_Click(object sender, EventArgs e)
            SerialPort port = new SerialPort(comboBox1.SelectedItem.ToString(), 9600);
            port.ReadTimeout = 1000;

the Bluetooth Code from lockApp:

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


Step 6: 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



    • Microcontroller Contest

      Microcontroller Contest
    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest

    We have a be nice policy.
    Please be positive and constructive.




    I want to use a normaly open push button what changes i need todo. Thanks


    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.

    thank you so much and Godbless you. this is exactly my project. but i have a different bar code scanner. how can i link my barcode reader to my arduino?. thanks again

    There are probably a few ways of doing it. This way used windows as a middleman which is not really the best way of doing so. I have not been keeping up with either Arduinos or scanners, but maybe you can do something over bluetooth.

    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

    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.

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

    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

    1 reply

    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.

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

    Thanks. Its just a simple magnetic door lock.

    Thanks. Its just a simple magnetic door lock.

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

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

    3 replies

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

    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.

    A mosfet is a type of transistor.