Electronic lock with Arduino card. Unusual combination lock on Arduino. Setting up the fingerprint sensor

25.11.2020 Memory cards

Progress does not stand still and “Smart locks” are increasingly appearing on the doors of apartments, garages and houses.

A similar lock opens when you press a button on your smartphone. Fortunately, smartphones and tablets have already entered our everyday life. In some cases, "smart locks" are connected to " cloud services"like Google Drive and open it remotely. In addition, this option makes it possible to give access to opening the door to other people.

This project will implement a DIY version of a smart lock on Arduino, which can be controlled remotely from anywhere in the world.

In addition, the project has added the ability to open the lock after identifying a fingerprint. For this purpose, a fingerprint sensor will be integrated. Both door opening options will be powered by the Adafruit IO platform.

A lock like this can be a great first step in your Smart Home project.

Setting up the fingerprint sensor

To work with a fingerprint sensor, there is an excellent library for Arduino, which greatly simplifies the process of setting up the sensor. This project uses Arduino Uno. An Adafruit CC3000 board is used to connect to the Internet.

Let's start with connecting the power:

  • Connect the 5V pin from the Arduino board to the red power rail;
  • The GND pin from the Arduino connects to the blue rail on the solderless circuit board.

Let's move on to connecting the fingerprint sensor:

  • First connect the power. To do this, the red wire is connected to the +5 V rail, and the black wire to the GND rail;
  • The white wire of the sensor connects to pin 4 on the Arduino.
  • The green wire goes to pin 3 on the microcontroller.

Now let's move on to the CC3000 module:

  • We connect the IRQ pin from the CC3000 board to pin 2 on the Arduino.
  • VBAT - to pin 5.
  • CS - to pin 10.
  • After this, you need to connect the SPI pins to the Arduino: MOSI, MISO and CLK - to pins 11, 12 and 13, respectively.

Well, at the end you need to provide power: Vin - to the Arduino 5V (red rail on your circuit board), and GND to GND (blue rail on the breadboard).

A photo of the fully assembled project is shown below:

Before developing a sketch that will load data onto Adafruit IO, you need to transfer data about your fingerprint to the sensor. Otherwise, he will not recognize you in the future;). We recommend calibrating the fingerprint sensor using the Arduino separately. If this is your first time working with this sensor, we recommend that you familiarize yourself with the calibration process and detailed instructions for working with the fingerprint sensor.

If you haven't already done so, please create an account with Adafruit IO.

After this, we can move on to the next stage of developing a “smart lock” on Arduino: namely, developing a sketch that will transmit data to Adafruit IO. Since the program is quite voluminous, in this article we will highlight and consider only its main parts, and then we will provide a link to GitHub, where you can download the full sketch.

The sketch begins by loading all the necessary libraries:

#include

#include

#include

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_CC3000.h"

#include

#include >

After this, you need to slightly correct the sketch by inserting the parameters of your WiFi network, specifying the SSID and password:

#define WLAN_SECURITY WLAN_SEC_WPA2>

In addition, you must enter your name and AIO key to log into your Adafruit IO account:

#define AIO_SERVERPORT 1883

#define AIO_USERNAME "adafruit_io_name"

#define AIO_KEY "adafruit_io_key">

The following lines are responsible for interacting and processing data from the fingerprint sensor. If the sensor was activated (the fingerprint matched), there will be "1":

const char FINGERPRINT_FEED PROGMEM = AIO_USERNAME "/feeds/fingerprint";

Adafruit_MQTT_Publish fingerprint = Adafruit_MQTT_Publish(&mqtt, FINGERPRINT_FEED);

In addition, we need to create an instance of the SoftwareSerial object for our sensor:

SoftwareSerial mySerial(3, 4);

After this we can create an object for our sensor:

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

Inside the sketch we indicate which fingerID should activate the lock in the future. This example uses 0, which corresponds to the ID of the first fingerprint used by the sensor:

int fingerID = 0;

After this, we initialize the counter and delay in our project. Essentially we want the lock to automatically engage once opened. This example uses a delay of 10 seconds, but you can adjust this value to suit your needs:

int activationCounter = 0;

int lastActivation = 0;

int activationTime = 10 * 1000;

In the body of the setup() function, we initialize the fingerprint sensor and ensure that the CC3000 chip is connected to your WiFi network.

In the body of the loop() function we connect to Adafruit IO. The following line is responsible for this:

After connecting to the Adafruit IO platform, we check the last fingerprint. If it matches and the lock is not activated, we send "1" to Adafruit IO for processing:

if (fingerprintID == fingerID && lockState == false) (

Serial.println(F("Access granted!"));

lockState = true;

Serial.println(F("Failed"));

Serial.println(F("OK!"));

lastActivation = millis();

If within the loop() function the lock is activated and we have reached the delay value indicated above, we send “0”:

if ((activationCounter - lastActivation > activationTime) && lockState == true) (

lockState = false;

if (! fingerprint.publish(state)) (

Serial.println(F("Failed"));

Serial.println(F("OK!"));

You can download the latest version of the code on GitHub.

It's time to test our project! Don't forget to download and install all the necessary libraries for Arduino!

Make sure you have made all the necessary changes to the sketch and upload it to your Arduino. After that, open the Serial Monitor window.

When Arduino connects to WiFi networks, the fingerprint sensor will blink red. Place your finger on the sensor. The ID number should be displayed in the serial monitor window. If it matches, the message "OK!" will appear. This means that the data has been sent to the Adafruit IO servers.

Diagram and sketch for further configuration of the lock using the example of an LED

Now let's move on to the part of the project that is directly responsible for controlling the door lock. To connect to wireless network and activating/deactivating the lock, you will need an additional Adafruit ESP8266 module (the ESP8266 module does not have to be from Adafruit). Using the example below, you can evaluate how easy it is to exchange data between two platforms (Arduino and ESP8266) using Adafruit IO.

In this section we will not work directly with the lock. Instead, we will simply connect the LED to the pin where the lock will be connected later. This will give us the opportunity to test our code without delving into the details of the lock design.

The scheme is quite simple: first install the ESP8266 on the breadboard. After this, install the LED. Don't forget that the long (positive) leg of the LED is connected through a resistor. The second leg of the resistor is connected to pin 5 on the ESP8266 module. We connect the second (cathode) of the LED to the GND pin on the ESP8266.

The fully assembled circuit is shown in the photo below.


Now let's look at the sketch we are using for this project. Again, the code is quite large and complex, so we will only look at its main parts:

We start by connecting the necessary libraries:

#include

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

Configuring WiFi settings:

#define WLAN_SSID "your_wifi_ssid"

#define WLAN_PASS "your_wifi_password"

#define WLAN_SECURITY WLAN_SEC_WPA2

We also configure Adafruit IO parameters. Same as in the previous section:

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883

#define AIO_USERNAME "adafruit_io_username"

#define AIO_KEY "adafruit_io_key"

We indicate which pin we connected the LED to (in the future this will be our lock or relay):

int relayPin = 5;

Interaction with the fingerprint sensor, as in the previous section:

const char LOCK_FEED PROGMEM = AIO_USERNAME "/feeds/lock";

Adafruit_MQTT_Subscribe lock = Adafruit_MQTT_Subscribe(&mqtt, LOCK_FEED);

In the body of the setup() function we indicate that the pin to which the LED is connected should operate in OUTPUT mode:

pinMode(relayPin, OUTPUT);

Within the loop() loop, we first check if we are connected to Adafruit IO:

After this, we check what signal is being received. If "1" is transmitted, we activate the pin that we declared earlier, to which our LED is connected. If we receive "0", we transfer the contact to the "low" state:

Adafruit_MQTT_Subscribe *subscription;

while ((subscription = mqtt.readSubscription(1000))) (

if (subscription == &lock) (

Serial.print(F("Got: "));

Serial.println((char *)lock.lastread);

// Save the command to string data

String command = String((char *)lock.lastread);

if (command == "0") (

digitalWrite(relayPin, LOW);

if (command == "1") (

digitalWrite(relayPin, HIGH);

Find latest version You can download the sketch on GitHub.

It's time to test our project. Don't forget to download all the required libraries for your Arduino and check if you have made the correct changes to the sketch.

To program the ESP8266 chip, you can use a simple USB-FTDI converter.

Upload the sketch to the Arduino and open the Serial Monitor window. At this point we just checked if we were able to connect to Adafruit IO: available functionality we'll look further.

Testing the project

Now let's start testing! Go to your Adafruit IO's user menu, under the Feeds menu. Check whether the fingerprint and lock channels are created or not (in the print screen below these are the fingerprint and lock lines):


If they do not exist, you will have to create them manually.

Now we need to ensure data exchange between the fingerprint and lock channels. The lock channel must take the value "1" when the fingerprint channel takes the value "1" and vice versa.

To do this, we use a very powerful Adafruit IO tool: triggers. Triggers are essentially conditions that you can apply to configured channels. That is, they can be used to interconnect two channels.

Create a new reactive trigger from the Triggers section in Adafruit IO. This will provide the ability to exchange data between the fingerprint sensor and lock channels:


This is what it should look like when both triggers are configured:

All! Now we can actually test our project! We put our finger on the sensor and see how the Arduino began to wink with an LED that corresponds to data transmission. After this, the LED on the ESP8266 module should start blinking. This means that it has started receiving data via MQTT. The LED on the circuit board should also turn on at this moment.

After the delay you set in the sketch (the default is 10 seconds), the LED will turn off. Congratulations! You can control the LED with your fingerprint from anywhere in the world!

Setting up an electronic lock

We have reached the last part of the project: directly connecting and controlling an electronic lock with using Arduino and a fingerprint sensor. The project is not easy, you can use all the sources in the form in which they are presented above, but connect a relay instead of an LED.

To connect the lock directly, you will need additional components: a 12 V power supply, a jack for connecting power, a transistor (V in this example IRLB8721PbF MOSFET is used, but another one can be used, for example, a TIP102 bipolar transistor. If you are using a bipolar transistor, you will need to add a resistor.

Shown below electrical diagram connecting all components to the ESP8266 module:


Note that if you are using a MOSFET transistor, you will not need a resistor between pin 5 of the ESP8266 module and the transistor.

The fully assembled project is shown in the photo below:


Power the ESP8266 module using the FTDI module and connect the 12V power supply to the jack. If you used the pins recommended above for connection, you won’t have to change anything in the sketch.

Now you can put your finger on the sensor: the lock should work in response to your fingerprint. The video below shows the automatic smart lock project in action:

Further development of the Smart Lock project

Our project has released remote control of a door lock using a fingerprint.

Feel free to experiment, modify the sketch and binding. For example, you can replace an electronic door lock with a relay to control the power of your 3D printer, robotic arm or quadcopter...

You can develop your smart House". For example, remotely activate an irrigation system on Arduino or turn on the lights in a room... Don't forget that you can simultaneously activate an almost unlimited number of devices using Adafruit IO.

Leave your comments, questions and share personal experience below. New ideas and projects are often born in discussions!

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

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

This tutorial will use an RFID tag with 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 ID is not equal to a predefined value, the "Unlocked" message will not appear - see photo below.

The castle is closed

The lock is open

Parts needed to create this project:

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

Additional details:

  • Battery (powerbank)

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

Step 2: RFID Reader RC522

Each RFID tag contains a small chip (white card shown in photo). If you shine a flashlight on this RFID card, you can see the small chip and the 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. It is possible to read an RFID card like this from up to 20mm away.

The same chip also exists in RFID key fob tags.

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 thousand data. Impressive, isn't it? This feature will not be used today. Today, all that is of interest is identifying a specific card by its UID. Cost of RFID reader and these two RFID cards is about 4 US dollars.

Step 3: OLED Display

The lesson uses a 0.96" 128x64 I2C OLED monitor.

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

The display has a resolution of 128 by 64 pixels and is tiny in size. There are two display options. One of them is monochrome, and the other, like the one used in the lesson, can display two colors: yellow and blue. The top of the screen can only be yellow, and the bottom can only be 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 except 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: Connecting all the parts

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

Be careful, the RFID reader must be connected to the 3.3V output from the Arduino Uno or it will be damaged.

Since the display can also operate 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 breadboard grounding bus. We then connect the breadboard GND bus 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 SPI interface to communicate with Arduino. So we are going to use hardware SPI pins from 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.

The RFID reader is 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 the SDA pin on the display to the analog Pin 4. If we now turn on the project and place the RFID card near the reader, we can see that the project is working fine.

Step 5: Project Code

In order for the project code to compile, 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 display.

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 on the display. We then compare the UID of the tag we just read with the value that is stored in the code variable. If the values ​​are the same, we will display 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 the project recognizes more RFID tags. 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.setTextColor(WHITE);

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)); && 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(); 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(); boolean match = true;

Step 6: Final Result





As you can see from the lesson, for 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 drive is read only after unlocking.

The other day I was watching The Amazing Spider-Man and in one scene Peter Parker remotely opens and closes a door from his laptop. As soon as I saw this, I immediately realized that I also needed such an electronic lock for my front door.

  • After some fiddling around, I assembled a working model of a smart lock. In this article I will tell you how I assembled it.

Step 1: List of Materials

  • To assemble an electronic lock on Arduino you will need the following materials:
  • Electronics:
  • 5V wall adapter

Components:

  • 6 latch screws
  • cardboard
  • wires
  • Tools:
  • soldering iron
  • glue gun
  • drill

drill

The idea is that I can open or close the door without a key, and without even going near it. But this is just the basic idea, because you can also add a knock sensor so that it reacts to a special knock, or you can add a voice recognition system!

A servo lever connected to the bolt will close it (0°) and open it (60°) using commands received via the Bluetooth module.

Step 3: Wiring Diagram


Let's first connect the servo to the Arduino board (note that although I used an Arduino Nano board, the Uno board has exactly the same pinout).

  • The brown wire of the servo is grounding, we connect it to the ground on the Arduino
  • the red wire is a plus, we connect it to the 5V connector on the Arduino
  • orange wire is the servo drive source pin, connect it to pin 9 on the Arduino

I advise you to check the operation of the servo before proceeding with the assembly. To do this, in the Arduino IDE program, select Sweep in the examples. After making sure that the servo is working, we can connect the Bluetooth module. You need to connect the rx pin of the Bluetooth module to the tx pin of the Arduino, and the tx pin of the module to the rx pin of the Arduino. But don't do it yet! Once these connections are soldered, you will not be able to upload any codes to the Arduino, so download all your codes first and only then solder the connections.

Here is the connection diagram between the module and the microcontroller:

  • Rx module – Tx board Arduino
  • Tx module – Rx board
  • Vcc (positive terminal) of the module is 3.3v of the Arduino board
  • Ground is connected to Ground (grounding to grounding)

If the explanation seems unclear to you, please follow the wiring diagram provided.

Step 4: Test

Now that we have all the working parts, let's make sure that the servo can move the latch. Before mounting the latch onto the door, I assembled a test sample to make sure the servo was powerful enough. At first it seemed to me that my servo was weak and I added a drop of oil to the latch, after which it worked fine. It is very important that the mechanism slides well, otherwise you risk being locked in your room.

Step 5: Electrical Housing



I decided to put only the controller and Bluetooth module in the case and leave the servo outside. To do this, draw the outline of the Arduino Nano board on a piece of cardboard and add 1 cm of space around the perimeter and cut it out. After this, we also cut out five more sides of the body. You will need to cut a hole in the front wall for the controller's power cord.

Case side dimensions:

  • Bottom – 7.5x4 cm
  • Cover – 7.5x4 cm
  • Left side wall – 7.5x4 cm
  • Right side wall – 7.5x4 cm
  • Front wall – 4x4 cm (with a slot for the power cord)
  • Back wall – 4x4 cm

Step 6: Application

To control the controller, you need an Android or Windows gadget with built-in Bluetooth. I did not have the opportunity to test the application on Apple devices; maybe some drivers will be needed.

I'm sure some of you have the opportunity to check this out. For Android, download the Bluetooth Terminal application, for Windows, download TeraTerm. Then you need to connect the module to your smartphone, the name should be linvor, the password should be 0000 or 1234. Once the pairing is established, open the installed application, go to options and select “Establish a connection (insecure).” Now your smartphone is an Arduino serial interface monitor, which means you can exchange data with the controller.

If you enter 0, the door will close and the message “Door is closed” will appear on the smartphone screen.
If you enter 1, you will see the door open and the screen will say "Door Open".
On Windows, the process is the same, except that you need to install the TeraTerm application.

Step 7: Install the latch


First you need to connect the servo to the latch. To do this, you need to cut off the plugs from the mounting holes of the drive housing. If we put the servo down, the mounting holes should be flush with the bolt. Then you need to place the servo lever in the latch slot, where the latch handle was. Check how the lock moves in the body. If everything is fine, secure the servo arm with glue.

Now you need to drill pilot holes for the screws in the door. To do this, attach the latch to the door and use a pencil to mark the holes for the screws on the door leaf. Drill holes for screws approximately 2.5 cm deep in the marked places. Attach the latch and secure it with screws. Check servo operation again.

Step 8: Power


To complete the device, you will need a power supply, a cord, and a mini-usb plug to connect to the Arduino.
Connect the ground pin of the power supply to the ground pin of the mini usb port, connect the red wire to the red wire of the mini usb port, then run the wire from the lock to the door hinge, and from there to the socket.

Step 9: Code

#include Servo myservo; int pos = 0; int state; int flag=0; void setup() ( myservo.attach(9); Serial.begin(9600); myservo.write(60); delay(1000); ) void loop() ( if(Serial.available() > 0) ( state = Serial.read(); flag=0; ) // if the state is "0" the DC motor will turn off if (state == "0") ( myservo.write(8); delay(1000); Serial. println("Door Locked"); else if (state == "1") ( myservo.write(55); delay(1000); Serial.println("Door UnLocked"); ) )

Step 10: Completed Arduino-Based Lock

Enjoy your remote control lock and don't forget to "accidentally" lock your friends in the room.

In this article I will tell you how to make a combination lock from Arduino. For this we need red and green LEDs, a buzzer, an Arduino nano, an LCD display with an I2C converter, a servo drive and a 4x4 matrix keyboard. When turned on, the display will write "Enter code."

the red LED will turn on,

and the green light will go out, the servo will be set to 0°. As you enter numbers, * will light up on the display.

If the code is entered incorrectly, the display will write “Enter code.”. If the code is correct, a beep will sound, the servo will rotate 180°, and the display will read "Open."

the green LED will turn on,

and the red one will turn off. After 3 seconds, the servo will return to its initial position, the red LED will turn on and the green LED will go out, the display will write “Close.”,

then the display will write "Enter code.". Now about the scheme. First, we connect the Arduino with wires to the breadboard (power contacts).

Then we connect the matrix keyboard to contacts D9 - D2.

Then the servo. We connect it to pin 10.

Red LED to pin 11.

Green - to pin 12.

Buzzer - to pin 13.

Now upload the sketch.

#include #include #include #include iarduino_KB KB(9, 8, 7, 6, 5, 4, 3, 2); LiquidCrystal_I2C lcd(0x27, 16, 2); Servo servo; int pass = (3, 6, 1, 8); int in; int r = 11; int g = 12; void setup() ( KB.begin(KB1); pinMode(r, OUTPUT); pinMode(g, OUTPUT); lcd.init(); lcd.backlight(); digitalWrite(g, LOW); digitalWrite(r, HIGH ); servo.attach(10); lcd.setCursor(0, 0); void loop() (lcd.clear(); lcd.print("Enter code."); while ( !KB.check(KEY_DOWN)) ( delay(1); ) in = KB.getNum; lcd.setCursor(0, 0); check(KEY_DOWN)) ( delay(1); ) in = KB.getNum; lcd.print("*"); while (!KB.check(KEY_DOWN)) ( delay(1); ) in = KB.getNum; lcd.print("*"); while (!KB.check(KEY_DOWN)) ( delay(1); ) in = KB.getNum("*"); if (in == pass) ( if (in == pass) ( if (in == pass) ( if (in == pass) ( lcd.clear(); lcd.setCursor(0, 0); lcd.print("Open."); tone( 13, 400, 750); digitalWrite(r, LOW); delay(3000); lcd.setCursor(0, 0); print("Close."); tone(13, 300, 700); digitalWrite(g, LOW); delay(1000);

) ) ) ) )

That's all. Enjoy the combination lock!

List of radioelements Designation Type Denomination QuantityNoteShop
My notepad E1

Arduino board

1 Arduino Nano 3.0 5V
To notepad E8, E9

Resistor

2 220 Ohm 5V
SMD E6

Light-emitting diode

1 AL102G 5V
Red E6

E7

1 AL307G 5V
Green E3LCD display1 With I2C interface 5V
Green backlight E5Servo1 SG90 5V
180 degrees E2Arduino Nano 3.01 Buzzer 5V
Bu E4Keyboard1 4X4 5V
Matrix NoBreadBoard1 640 points

No soldering

The host of the YouTube channel “AlexGyver” was asked to make an electronic lock with his own hands. Welcome to the series of videos 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.

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. This task can also be handled lithium battery and boost module. 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 network source power supply and neglect the autonomy of the system. IN Chinese stores There are large 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 need 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