Electronic lock for arduino uno. Automatic smart lock and Arduino

This project is modular, i.e. you can connect / disconnect different elements and get different functionality. The pictures above show the option with full functionality, namely:

  • Locking mechanism... Serves for OPENING and CLOSING the door. This project covers the use of three different mechanisms:
    • Servo. There are big ones, there are small ones. Very compact, and with a heavy bolt is a great option
    • Electric drive of the car door lock. A big and powerful thing, but it eats just insane currents
    • Solenoid latch. A good option, since it slams itself

    In the firmware settings, you can choose any of three types (setting lock_type)

  • Button inside... Serves for OPENING and CLOSING the door from the inside. Can be placed on the door handle (palm or finger side), on the door itself, or on the jamb
  • Button outside... Serves for CLOSING the door, as well as for AWAKENING from energy saving. Can be placed on the door handle (palm or finger side), on the door itself, or on the jamb
  • End stop to close the door. Serves to automatically close the lock when the door is closed. They can be:
    • Tact button
    • Hall sensor + magnet on the door itself
    • Reed switch + magnet on the door itself
  • Secret access reset button... Serves to reset the password / enter a new password / memorize a new key / combination, etc. May be hidden somewhere in the case
  • Light-emitting diode to indicate work. RGB LED, red and green colors are used (when mixed, they give yellow):
    • Lights up green - the lock is OPEN. Burns so as not to forget to close the door
    • Solid yellow - the system has woken up and is awaiting password entry
    • Blinking red - the battery is dead

Any of these elements can be excluded from the system:

  • We remove the end switch. In the firmware in the settings, we also disable it (setting tail_button). Now to close the lock, you need to press the button
  • We remove the outer button. In the firmware in the settings, we also disable it (setting wake_button). Now the system does not need to be woken up, it wakes up by itself (energy consumption is slightly higher). And also we no longer have a close button on the front of the door, and we need a limit switch. Either the lock is the heck
  • We remove the inner button. This option is suitable for cabinets and safes. You don't need to change anything in the settings
  • We remove the LED. You don't need to change anything in the settings
  • The access reset button can be unsoldered after the first use, or you can rewrite the code for yourself
  • Door closed, pressed OUTSIDE - wake up, wait for password / RFID tag / electronic key / fingerprint
  • The door is closed, the system has woken up, waiting for the password to be entered. The time can be adjusted (setting sleep_time)
  • The door is closed, a password / tag / key has been entered, etc. - open
  • Door closed, pressed INSIDE - open
  • Door open, pressed OUTSIDE - close
  • Door open, pressed INSIDE - close
  • The door is open, the END is pressed - close

The lock provides for battery operation in low power saving mode (turn on turn off: setting sleep_enable), namely:

  • Wake up every few seconds, follow the EVENT (optional if there is no button outside. You can enable it in the setting wake_button)
  • Every few minutes, monitor the voltage of Akum (on / off setting battery_monitor)
  • If Akum is discharged (voltage is set in the setting bat_low):
    • open the door (optional, can be configured in the firmware open_bat_low)
    • prohibit further opening and closing
    • when the buttons are pressed, blink red LED
    • stop monitoring the EVENT (i.e. enter password / tag, etc.)

When the system is awake, press the change password button (hidden button). We fall into password change mode:
Enter the password from numbers ( MAXIMUM 10 DIGITS !!!)

  • When you press *, the password is saved in memory and the system exits from changing the password
  • When you press #, the password is reset (you can enter it again)
  • If you do not press anything for 10 seconds, we will automatically exit the password change mode, the password will remain old

When the system is awake (woke up by buttons or sleep is disabled), press * to enter the password entry mode
If the system sleeps and periodically wakes up to check the EVENT, then press * and hold until the red LED lights up
Password input mode:

  • Password processing is done in such a way that the correct password is counted only when the correct sequence of numbers is typed, that is, if the password is 345, then any numbers can be entered until the sequence 345 appears, i.e. 30984570345 will open the lock as it ends in 345.
  • If the password is entered correctly, the door will open
  • If you do not press anything, after 10 seconds the system will return to normal (standby) mode
  • If you press #, we will immediately exit the password entry mode
  • If you press the secret button for changing the password in the password input mode, then we will also exit from it

I, like most who have it, associate DACHA with the words: rest, barbecue, comfort and other movements pleasant to the spirit and body, but there is also a downside: a garden, digging, repairs, construction, etc.

For 10 years my family and I have been trying to improve and create maximum comfort in our country house. We build, repair, etc. A house, a barn, a bathhouse ... ... and finally it came to a street fence, a gate and a gate. Doing so is conscientious, budget and convenience.

After discussing some details, it was decided that the gate should be automatic and that the gate should have some properties of the ACS. With the gate, the issue was resolved by purchasing a set of automation (drive, rail, remote control, etc.), and with the gate, it was necessary to solve some problems, about them below.

The tasks were as follows:

  1. The lock was supposed to work in conjunction with a previously installed video intercom (open the gate without leaving the house)
  2. Be able to open the door with a regular key and without a key from the street and yard.
  3. Will keep within the remaining budget up to 5000 rubles.

Searches in runet presented the following price range from 7000 to infinity. The purchase of a ready-made solution disappeared and an alternative with ample opportunities was conceived, namely, to cut the door yourself!

After some calculations and calculations, it was decided to buy an electromechanical lock for about 2000 rubles, a waterproof keyboard for 350 rubles, and an MK that will steer here. Since there were several Arduino nano boards, relays and loose pieces and a few wires in stock, the difference between the cost of the finished kit was more than 4000 tr. For me, a great bonus for the wallet and self-development.

Well, now, from words to action:

After purchasing all the necessary components, he began to saw.

Keyboard connection diagram

Additional LED indication (white, green, red) of the panel with the keypad signals (enter, correct password open the door, refused).

  • pin 9 yellow
  • pin 10 green
  • pin 11 red

The plexiglass panel (lattice) was cut into a box of chocolates and a smile by the neighbors in the office. But the smallest cutter turned out to be a little fatter, I had to work with a file.

Well, here's the weekend, I moved to the dacha.

To open an electromechanical lock, you need 12 volts. The power supply supplying the MK was 5 V., the solution was to put a step-up dc-dc converter from the sky for the lock. I started to check everything, it works, but when voltage was applied to the solenoid of the lock, the dunya rebooted, short circuit to the power supply. Further more, after connecting the outdoor panel from the video intercom to the lock, when the button was pressed to open the door, nothing happened, a small current to the lock. Pulling new wires is not an option, they were already concreted at the exit from the house. I decided to add another relay for the panel and put an additional 12 V power supply. for the castle. After parsing / collecting, everything worked, MK stopped rebooting. I hid the whole thing in a waterproof junction box, hid the wires, glue, silicone and you're done!

Today's lesson on how to use an RFID reader with an Arduino to create a simple locking system, in simple words - an RFID lock.

RFID (English Radio Frequency IDentification) is a method of automatic identification of objects, in which data stored in so-called transponders, or RFID tags, are read or written by means of radio signals. Any RFID system consists of a reader (reader, reader or interrogator) and a transponder (aka RFID tag, sometimes the term RFID tag is also used).

This tutorial will use an RFID tag from an Arduino. The device reads the unique identifier (UID) of each RFID tag that we place next to the reader and displays it on the OLED display. If the UID of the tag is equal to the predefined value that is stored in the Arduino memory, then we will see the message “Unlocked” on the display. If the unique identifier is not equal to the predefined value, the message "Unlocked" will not appear - see the photo below.

The lock is closed

The lock is open

Details required to create this project:

  • RFID Reader RC522
  • OLED display
  • Bread board
  • Wires

Additional details:

  • Battery (powerbank)

The total cost of the project components was approximately $ 15.

Step 2: RFID reader RC522

Each RFID tag has a small chip (white card pictured). If you aim the flashlight at this RFID card, you can see a small chip and a coil that surrounds it. This chip does not have a battery to generate power. It receives power from the reader wirelessly using this large coil. An RFID card like this can be read from up to 20mm away.

The same chip exists in the tags of the RFID key fob.

Each RFID tag has a unique number that identifies it. This is the UID that is shown on the OLED display. Except for this UID, each tag can store data. This type of card can store up to 1,000 data. Impressive, isn't it? This feature will not be used today. Today, all that interests is the identification of a particular card by its UID. The cost of the RFID reader and these two RFID cards is around US $ 4.

Step 3: OLED display

This tutorial uses a 0.96 "128x64 I2C OLED monitor.

This is a very good display for use with Arduino. It is an OLED display and that means it has low power consumption. The power consumption of this display is about 10-20mA and it depends on the number of pixels.

The display has a resolution of 128 by 64 pixels and is tiny. There are two display options. One of them is monochrome, and the other, like the one used in the tutorial, can display two colors: yellow and blue. The top of the screen can only be yellow and the bottom blue.

This OLED display is very bright and has a great and very nice library that Adafruit has developed for this display. In addition to this, the display uses an I2C interface, so connecting to the Arduino is incredibly easy.

You only need to connect two wires, excluding Vcc and GND. If you are new to Arduino and want to use an inexpensive and simple display in your project, start here.

Step 4: connect all the details

The communication with the Arduino Uno board is very simple. First, connect power to both the reader and the display.

Be careful, the RFID reader must be connected to the 3.3V output of the Arduino Uno or it will get corrupted.

Since the display can also run at 3.3V, we connect the VCC from both modules to the positive rail of the breadboard. This bus is then connected to the 3.3V output from the Arduino Uno. Then we connect both grounds (GND) to the grounding bus of the breadboard. Then we connect the GND bus of the breadboard to the Arduino GND.

OLED Display → Arduino

SCL → Analog Pin 5

SDA → Analog Pin 4

RFID Reader → Arduino

RST → Digital Pin 9

IRQ → Not connected

MISO → Digital Pin 12

MOSI → Digital Pin 11

SCK → Digital Pin 13

SDA → Digital Pin 10

The RFID reader module uses the SPI interface to communicate with the Arduino. Therefore, we are going to use the hardware SPI pins from the Arduino UNO.

The RST pin goes to digital pin 9. The IRQ pin remains disconnected. The MISO pin goes to digital pin 12. The MOSI pin goes to digital pin 11. The SCK pin goes to digital pin 13, and finally the SDA pin goes to digital pin 10. That's it.

RFID reader connected. Now we need to connect the OLED display to the Arduino using the I2C interface. So the SCL pin on the display goes to the analog pin of Pin 5 and SDA on the display to the analog Pin 4. If we now turn on the project and place the RFID card next to the reader, we can see that the project is working fine.

Step 5: Project Code

In order for the project code to be compiled, we need to include some libraries. First of all, we need the MFRC522 Rfid library.

To install it, go to Sketch -> Include Libraries -> Manage libraries(Library management). Find MFRC522 and install it.

We also need the Adafruit SSD1306 library and the Adafruit GFX library for mapping.

Install both libraries. The Adafruit SSD1306 library needs a little modification. Go to folder Arduino -> Libraries, open the Adafruit SSD1306 folder and edit the library Adafruit_SSD1306.h... Comment out line 70 and uncomment line 69 because the display has a resolution of 128x64.

First, we declare the value of the RFID tag that the Arduino needs to recognize. This is an array of integers:

Int code = (69,141,8,136); // UID

Then we initialize the RFID reader and display:

Rfid.PCD_Init (); display.begin (SSD1306_SWITCHCAPVCC, 0x3C);

After that, in the loop function, we check the tag on the reader every 100ms.

If there is a tag on the reader, we read its UID and print it to the display. We then compare the UID of the tag we just read with the value stored in the code variable. If the values ​​are the same, we print the UNLOCK message, otherwise we will not display this message.

If (match) (Serial.println ("\ nI know this card!"); PrintUnlockMessage ();) else (Serial.println ("\ nUnknown Card");)

Of course, you can change this code to store more than 1 UID value so that more RFID tags are recognized by the project. This is just an example.

Project code:

#include #include #include #include #define OLED_RESET 4 Adafruit_SSD1306 display (OLED_RESET); #define SS_PIN 10 #define RST_PIN 9 MFRC522 rfid (SS_PIN, RST_PIN); // Instance of the class MFRC522 :: MIFARE_Key key; int code = (69,141,8,136); // This is the stored UID int codeRead = 0; String uidString; void setup () (Serial.begin (9600); SPI.begin (); // Init SPI bus rfid.PCD_Init (); // Init MFRC522 display.begin (SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) // Clear the buffer.display.clearDisplay (); display.display (); display.setTextColor (WHITE); // or BLACK); display.setTextSize (2); display.setCursor (10,0); display.print ("RFID Lock"); display.display (); ) void loop () (if (rfid.PICC_IsNewCardPresent ()) (readRFID ();) delay (100);) void readRFID () (rfid.PICC_ReadCardSerial (); Serial.print (F ("\ nPICC type:") ); MFRC522 :: PICC_Type piccType = rfid.PICC_GetType (rfid.uid.sak); Serial.println (rfid.PICC_GetTypeName (piccType)); // Check is the PICC of Classic MIFARE type! = PICMType22 && piccType! = MFRC522 :: PICC_TYPE_MIFARE_1K && piccType! = MFRC522 :: PICC_TYPE_MIFARE_4K) (Serial.println (F ("Your tag is not of type MIFARE Classic.")); return;) clearUID (); return;) clearUID (); Scanned PICC "s UID:"); printDec (rfid.uid.uidByte, rfid.uid.size); uidString = String (rfid.uid.uidByte) + "" + String (rfid.uid.uidByte) + "" + String (rfid.uid.uidByte) + "" + String (rfid.uid.uidByte); printUID (); int i = 0; boolean match = true; while (i

Step 6: the final result

As you can see from the lesson - for a little money, you can add an RFID reader to your projects. You can easily create a security system using this reader or create more interesting projects, for example, so that data from a USB disk is read only after unlocking.

The host of the youtube channel “AlexGyver” was asked to make an electronic lock with his own hands. Welcome to the cycle of videos about electronic locks on arduino. In general terms, the wizard will explain the idea.

There are several options for creating an electronic lock system. Most often they are used to lock doors and drawers, cabinets. And also for the creation of hiding places and secret safes. Therefore, you need to make a mock-up that is convenient to work with and you can clearly and in detail show the structure of the system from the inside and outside. Therefore, I decided to make a frame with a door. For this you need a square bar 30 x 30. Plywood 10mm. Door hinges. Initially, I wanted to make a plywood box, but I remembered that everything in the room was littered with spare parts. There is nowhere to put such a box. Therefore, a layout will be made. If someone wants to put himself an electronic lock, then, looking at the layout, you can easily repeat everything.

Everything you need for a castle can be found in this Chinese store.

The goal is to develop the most efficient circuits and firmware for electronic locks. You will be able to use these results to install these systems on your doors, drawers, cabinets and hiding places.

The door is ready. Now you need to figure out how to open and close electronically. For these purposes, a powerful solenoid latch from aliexpress is suitable (link to the store above). If you apply voltage to the terminals, it will open. The resistance of the coil is almost 12 ohms, which means that at a voltage of 12 volts, the coil will consume about 1 ampere. A lithium battery and a boost module can cope with this task. We adjust to the appropriate voltage. Although a little more is possible. The latch is attached to the inside of the door at a distance so that it does not catch on the edge and can slam shut. The latch should be a counterpart in the form of a metal box. It is inconvenient and wrong to use it without it. We'll have to put a step, at least to create the appearance of normal work.

In idle mode, the latch opens normally, that is, if there is a handle on the door, give an impulse, open the door by the handle. But if you spring it up, this method is no longer suitable. The boost converter cannot handle the load. To open the spring-loaded door you will have to use a larger battery and a more powerful converter. Either the mains power supply and hammer on the autonomy of the system. There are oversized hecks in Chinese stores. They are suitable for boxes. Power can be supplied using a relay or a transistor mosfet, or a power switch on the same transistor. A more interesting and less expensive option is a servo drive connected to a connecting rod with any locking element - a latch or a more serious valve. He may also need a piece of steel spoke that acts as a connecting rod. Such a system does not need a lot of current. But it takes up more space and more cunning control logic.

There are two types of servos. Small, weak and powerful, with which you can safely push into holes in serious metal pins. Both options shown work on both doors and drawers. You will have to tinker with the box, making a hole in the sliding wall.

Second part

Imagine a RF-key operated door lock.

The lock works like this: They brought OUR key (RFID-tag) - the lock closed, brought the key again - the lock opened. To visualize the operation of the lock, six two-color LEDs (ruler) are used. When closing, a red light runs through, when opening, a green one. If you bring ANYONE'S key, the red LEDs will flash.

As an actuator, I decided to use the car's central locking drive. You can buy a new one, you can use it, the difference in price is not big, so I used a new one, it is more reliable. The drive rod is connected to the latch. The espagnolette is still Soviet, strong. And I do not need a powerful "anti-vandalism".

The "machine" is controlled by two wires. One polarity extends the stem, reverse polarity retracts the stem. At 12 volts, the current is 6 amps, a lot ...
There are no limit switches in the "machine".

Proceeding from the fact that the lock circuit (as conceived) has a guaranteed power supply, a 12 volt battery, to ensure the operation of the lock, in the event of a loss of ~ 220. Developed a bridge control scheme for the "machine". A special feature of the circuit is its nonlinearity, which ensures reliable operation of the lock mechanism, and at the same time - a gentle mode of operation of the "machine" and key transistors.

In the diagram (above), the "Close" shoulder is highlighted in red, and the "Open" shoulder is highlighted in green. The shoulders are powered separately, through resistors (located in the power supply). Separation of power supply of the bridge arms, introduced to eliminate false alarms.

Explanation: Through 33-ohm resistors (on the power supply diagram), a voltage of 12 volts charges the capacitors (2000 microfarads, in each arm). When the control voltage comes from the controller Arduino_ProMini- 168 to the "Close" input (or similarly to "Open"), through the PVT322 optocoupler - the corresponding key arm opens. In this case, the following happens: At the moment of opening the keys, the energy from the capacitors powerfully "pulls" the motor of the "machine". As the capacitors are discharged (this happens quickly), the motor of the "car" is powered by a current limited by resistors (33 Ohm). Due to this, at the end of the process of "closing" - "opening" the lock, the stem moves rather slowly.

This way of controlling the motor is optimal.

Transformer power supply circuit. In general, the lock circuit is powered by a 12-volt, 2.8 -A / H battery. And the power supply circuit maintains the battery at a nominal level. The Network LED indicates normal operation of the power supply.

All diodes are 1N4007 (I forgot to indicate on the diagram, but the person asked the question - which ones?).

(1) assembled overcurrent limiter. Resistor R 1 the upper current threshold is set at 300 mA.
On the integrated stabilizer LM317 (2) assembled voltage regulator. The stabilization voltage is adjusted by a resistorR 2 ... The battery voltage should be 13.7 volts.

The battery voltage is supplied at three points.
Through resistors (33-Ohm each) on (X), (Y) - power supply of the arms of the keys of the "driver" of the motor of the "car".

I collect most of my devices from what came to hand. This project is no exception. As a body I use a body :) from electronic ballast:

LEDs No.-2 ... No.-7 are two-color. They are arranged in a line. They are used to visualize the "opening" and "closing" processes of the lock. Embellishment.