Membrane lock for a door using Arduino. Automatic smart lock and Arduino


The host of the YouTube channel “AlexGyver” was asked to make an electronic lock with his own hands. Welcome to the video series about electronic locks on arduino. The master will explain the idea in general terms.

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

You will find everything you need for a castle in this Chinese store.

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

The door is ready. Now we need to figure out how to open and close electronically. A powerful solenoid latch from aliexpress is suitable for these purposes (link to the store above). If you apply voltage to the terminals, it will open. The coil resistance is almost 12 ohms, which means that at a voltage of 12 volts the coil will consume about 1 ampere. Both a lithium battery and a boost module can cope with this task. 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 the edge and can slam shut. The latch should have a counterpart in the form of a metal box. Using it without this is inconvenient and incorrect. We'll have to install a step, at least to create the appearance of normal operation.

In idle mode, the latch opens normally, that is, if there is a handle on the door, we apply a pulse and open the door by the handle. But if you use a spring, this method is no longer suitable. The boost converter cannot cope with the load. To open the spring-loaded door you will have to use larger batteries and a more powerful inverter. Or use a network power source and forget about system autonomy. Chinese stores have large size latches. They are suitable for drawers. Power can be supplied using a relay or mosfet transistor, 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 bolt. You may also need a piece of steel knitting needle to act as a connecting rod. Such a system does not require high current. But it takes up more space and has more cunning control logic.

There are two types of servos. Small weak ones and large powerful ones that can be easily pushed 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 retractable wall.

Second part

I, like most people who have one, associate Cottage with the words: relaxation, barbecue, comfort and other pleasant movements for the spirit and body, but there is also a downside: gardening, digging, repairs, construction, etc.

For 10 years, my family and I have been trying to improve and create maximum comfort in our dacha. We build, repair, etc. House, barn, bathhouse…..and finally it came to the street fence, gate and gate. Do this according to conscience, budget and convenience.

After discussing some details, it was decided that the gate should be automatic and the gate should have some of the properties of an access control system. With the gate, the issue was resolved by purchasing an automation kit (drive, rack, remote control, etc.), but with the gate it was necessary to solve some problems, more about them below.

The tasks were the following:

  1. The lock had 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 fit within the remaining budget up to 5000 rubles.

Searches in RuNet presented the following price range from 7000 to infinity. Purchasing a ready-made solution was no longer necessary and an alternative with wide possibilities was conceived, namely to cut down 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 a microcontroller that will drive here. Since there were several Arduino nano boards, relays and loose parts and some wires, the difference between the cost of the finished kit was more than 4000 rubles. For me, it’s a great bonus for your wallet and self-development.

Well, now from words to action:

After purchasing all the necessary components, I began sawing.

Keyboard connection diagram

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

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

A panel (grid) made of plexiglass, cut for a box of chocolates and a smile by office neighbors. But the smallest cutter turned out to be a little fatter, so I had to work with a needle file.

Well, it’s the weekend, I went to the dacha.

To open an electromechanical lock, you need 12 V. The power supply supplying the MK was 5 V, the decision was to install a boost dc-dc converter from the Middle Kingdom for the castle. I connected everything and started checking it, it works, but when voltage was applied to the lock solenoid, the Dunya rebooted, causing a short to the power supply. Further more, after connecting the calling panel from the video intercom to the lock, when you pressed the button to open the door, nothing happened, a small current to the lock. Running 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 install an additional 12 V power supply. for the castle. After parsing/assembling, everything worked, the MK stopped rebooting. I hid the whole thing in a moisture-proof junction box, hid the wires, glue, silicone and ready!

Introducing a door lock controlled by an RF key.

The lock works like this: Presented OUR key (RFID tag) - the lock closed, presented the key again - the lock opened. To visualize the operation of the lock, six two-color LEDs (line) were used. When closing, a red light flashes, when opening, a green light flashes. If you bring someone else's key, the red LEDs will blink.

I decided to use the car's central locking drive as an actuator. You can buy a new one, or a used one, 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 latch is still Soviet, strong. And I don’t need powerful “anti-vandalism”.

The “machine” is controlled via two wires. One polarity extends the rod, reverse polarity retracts the rod. At a voltage of 12 volts, the current is 6 amperes, a lot...
There are no limit switches in the "machine".

Based on the fact that the lock circuit (by design) has a guaranteed power supply, the battery is 12 volts, to ensure the operation of the lock, in the event of a loss of ~220 volts. Developed a bridge control circuit 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, gentle operation of the “machine” and key transistors.

In the diagram (above), the “Close” arm is highlighted in red, and the “Open” arm is highlighted in green. The arms are powered separately, through resistors (located in the power supply). Power separation of the bridge arms was introduced to eliminate false positives.

Explanation: Through 33-Ohm resistors (on the power supply diagram), a voltage of 12 volts charges the capacitors (2000-μF in each arm). When the control voltage arrives from the Arduino_ProMini controller, 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 discharge (this happens quickly), the motor of the “machine” is powered by a current limited by resistors (33 Ohms). Thanks to this, at the end of the process of “closing” - “opening” the lock, the rod moves quite slowly.

This method of engine control is optimal.

The power supply circuit is transformer. In general, the lock circuit is powered by a 12-volt, 2.8-Ah battery. And the power supply circuit maintains the battery at its nominal level. The Power LED indicates normal operation of the power supply.

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

(1) A maximum current limiter has been assembled. Resistor R 1 The upper current threshold is set to 300 mA.
On the integral stabilizer LM317 (2) voltage stabilizer assembled. The stabilization voltage is adjusted by a resistorR 2 . The battery voltage should be 13.7 volts.

Voltage from the battery is supplied to three points.
Through resistors (33-Ohm each) on (X), (Y) - power supply to the arms of the “driver” keys of the “machine” motor.

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

LEDs No.-2 ... No.-7 are two-color. They are located in a line. Used to visualize the processes of “opening” and “closing” the lock. Embellishment.

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

  • Locking mechanism. Serves to OPEN and CLOSE the door. This project explores the use of three different mechanisms:
    • Servo. There are big ones, there are small ones. Very compact, and coupled with a heavy deadbolt - an excellent option
    • Electric car door lock. It's a big and powerful thing, but it consumes crazy currents.
    • Solenoid latch. A good option because it closes itself

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

  • Button inside. Serves to OPEN and CLOSE the door from the inside. Can be placed on the door handle (palm side or finger side), on the door itself, or on the jamb
  • Button outside. Serves for CLOSING the door, as well as for WAKING up to save energy. Can be placed on the door handle (palm side or finger side), on the door itself, or on the jamb
  • End cap to close the door. Serves to automatically close the lock when the door is closed. It could be:
    • Tact button
    • Hall sensor + magnet on the door itself
    • Reed switch + magnet on the door itself
  • Secret access reset button. Used to reset the password/enter a new password/remember a new key/combination, etc. May be hidden somewhere in the case
  • Light-emitting diode to indicate operation. RGB LED, red and green colors are used (when mixed they give yellow):
    • The green light is on - the lock is OPEN. Lights up so you don't forget to close the door
    • Yellow is on - the system has woken up and is waiting for a password to be entered
    • Flashing red - low battery

Any of these elements can be excluded from the system:

  • We remove the limit switch. In the firmware in the settings we also disable it (setting tail_button). Now you have to press a button to close the lock.
  • Remove the external 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 on its own (energy consumption is slightly higher). And now we don’t have a close button on the front of the door, and we need a limit switch. Or the lock is a latch
  • Remove the internal 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 the code can be rewritten to suit your needs
  • Door closed, press OUTSIDE - wake up, wait for password/RFID tag/electronic key/fingerprint input
  • The door is closed, the system is awake, waiting for the password to be entered. The time can be adjusted (setting sleep_time)
  • The door is closed, a password/tag/key, etc. has been entered. - open
  • The door is closed, press INSIDE - open
  • The door is open, press OUTSIDE - close
  • The door is open, press INSIDE - close
  • The door is open, the LIMIT is pressed - close

The lock is designed to operate on battery power in a low energy saving mode (enable disable: setting sleep_enable), namely:

  • Wake up every few seconds, monitor the EVENT (optional if there is no button outside. You can enable it in the settings wake_button)
  • Monitor the battery voltage every few minutes (on/off setting battery_monitor)
  • If the battery is discharged (the 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 you press a button, the red LED flashes
    • stop monitoring the EVENT (i.e. password entry/label, etc.)

When the system is not sleeping, press the password change button (hidden button). We find ourselves in password change mode:
Enter a password consisting of numbers ( MAXIMUM 10 DIGITS!!!)

  • When you press *, the password is written to memory and the system exits the password change
  • 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 old password will remain

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

  • Password processing is done in such a way that the correct password is only counted when the correct sequence of numbers is entered, that is, if the password is 345, then you can enter any numbers until the sequence 345 appears, i.e. 30984570345 will open the lock because 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 password change button in password entry mode, you will also exit it






2024 gtavrl.ru.