In this lesson we will learn how to do simple system, which will unlock the lock using an electronic key (Label).
In the future, you can refine and expand the functionality. For example, add the function "adding new keys and removing them from memory". In the base case, consider a simple example, when a unique key identifier is pre-specified in the program code.
In this tutorial we will need:
To implement the project, we need to install the libraries:
2) Now you need to connect the Buzzer, which will give a signal if the key worked and the lock opens, and the second signal when the lock closes.
We connect the buzzer in the following sequence:
Arduino | Buzzer |
---|---|
5V | VCC |
GND | GND |
pin 5 | IO |
3) A servo will be used as the unlocking mechanism. Any servo can be chosen, depending on the dimensions you require and the forces that the servo creates. The servo has 3 pins:
More clearly, you can see how we connected all the modules in the picture below:
Now, if everything is connected, then you can proceed to programming.
Sketch:
#include
Let's analyze the sketch in more detail:
In order to find out the UID of the card (Labels), you need to write this sketch to arduino, assemble the circuit described above, and open the Console (Monitoring of the serial port). When you bring the tag to the RFID, a number will be displayed in the console
The resulting UID must be entered in the following line:
If (uidDec == 3763966293) // Compare the Uid of the label, if it is equal to the specified one, then the servo opens the valve.
For each card, this identifier is unique and does not repeat. Thus, when you present a card whose ID you have set in the program, the system will open access using a servo.
Video:
In this article I will show you how to do code lock from arduino. To do 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 turns off, the servo will be set to 0°. When numbers are entered, * will light up on the display.
If the code is entered incorrectly, the display will show "Enter cod.". If the code is correct, a beep will sound, the servo will turn 180°, the display will read "Open."
the green LED will turn on,
and red will turn off. After 3 seconds, the servo will return to initial position, the red LED will turn on and the green LED will turn off, the display will write "Close.",
then the display will write "Enter code.". Now about the scheme. First we connect the arduino with wires with breadboard(power contacts).
Then we connect a 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
That's all. Enjoy code lock!
List of radio elements
Designation | Type | Denomination | Quantity | Note | Shop | My notepad |
---|---|---|---|---|---|---|
E1 | Arduino board | Arduino Nano 3.0 | 1 | 5V | To notepad | |
E8, E9 | Resistor | 220 ohm | 2 | smd | To notepad | |
E6 | Light-emitting diode | AL102G | 1 | Red | To notepad | |
E7 | Light-emitting diode | AL307G | 1 | Green | To notepad | |
E3 | LCD display | With I2C interface | 1 | Green backlight | To notepad | |
E5 | Servo | SG90 | 1 | 180 degrees | To notepad | |
E2 | Buzzer | 5V | 1 | Bu | To notepad | |
E4 | Keyboard | 4x4 | 1 | matrix | To notepad | |
No | BreadBoard | 640 points | 1 | without soldering |
After rummaging through Chinese flea markets and ebay, I didn’t find anything cheap and more or less serious and decided to make it myself. I will make a reservation right away that the Arduino platform was chosen for its simplicity, since there was no experience at all with microcontrollers.
Idea
On the door, on the outside of the door, there must be a keypad on which the password is entered, with inside fixed the rest of the structure. A reed switch is used to control the complete closing of the door. Leaving the office, a person presses “*” on the keyboard and, without waiting for the door to close, the door closer goes about his business, when the door is completely closed, the reed switch will close and the lock will be closed. The door is opened by entering a 4-digit password and pressing "#".Accessories
Arduino UNO = $18Arduino protoshield + breadboard = $6
L293D = $1
Bundle of wires 30pcs for bredboard = $4
2 RJ45 sockets = $4
2 RJ45 plugs = $0.5
central lock actuator = 250 rubles.
Reed switch = torn free of charge from the old window.
Espagnolette metal gigantic sizes = free
Case from an old D-LINK hub made of 1.5 mm iron = free
Power supply from the same D-LINK hub for 12 and 5v = also free
A bunch of screws and nuts for attaching all this stuff to the case = 100 rubles.
Control panel from burglar alarm= free.
Total:$33.5 and 350 rubles.
Not so little, you say, and you will definitely be right, but you have to pay for pleasure! And it's always nice to collect something with your own hands. In addition, the design can be greatly reduced in price if you use a bare MK without an Arduino.
Assembly preparation
I would like to say a few words about the purchase of a key element of the actuator design. At a local auto shop, they offered me two types of actuators: "with two wires and with five." According to the saleswoman, they were exactly the same and the difference in the number of wires meant absolutely nothing. However, as it turned out later, this is not so! I chose a device with two wires, it was powered by 12v. The five-wire design features limit switches to control the movement of the lever. I realized that I bought the wrong one only when I took it apart and it was too late to change it. The stroke of the lever turned out to be too short to properly push the latch, therefore, it was necessary to modify it a little, namely, to remove two rubber washers shortening the stroke of the actuator lever. To do this, the body had to be sawn along with an ordinary hacksaw, because the second washer was inside. The blue duct tape to us, as always, helped us later on when assembling it back.To control the actuator motor, the L293D motor driver was used, which can withstand a peak load of up to 1200 mA, in our case, when the actuator motor was stopped, the peak load increased to only 600 mA.
Contacts from the keyboard, speaker and two LEDs were removed from the control panel from the security alarm. The remote control and the main device were supposed to be connected using a twisted pair and RJ45 connectors
Programming.
Just like experience Arduino programming I haven't had it yet. I took advantage of other people's developments and articles from the arduino.cc website. Who cares, can look at this ugly code :)Photo and video
Arduino and actuator
power unit
Keyboard
Espagnolette (connected to the actuator with a metal needle and on which heat shrink is put on for beauty)
Video of the device operation process:
Today's lesson is about how to use an RFID reader with Arduino to create a simple locking system, in simple words - an 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, are read or written using 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).
The tutorial will use an RFID tag with 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 "Unlocked" message will not appear - see photo below.
The castle is closed
The castle is open
Details needed to create this project:
- RFID Reader RC522
- OLED display
- Bread board
- wires
Additional details:
- Battery (power bank)
The total cost of the project components was approximately $15.
Step 2: RFID Reader RC522
Each RFID tag has a small chip (white card in the photo). If you point a 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. It is possible to read an RFID card like this from up to 20mm away.
The same chip 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. With the exception of 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 is of interest is the identification of a particular card by its UID. The RFID reader and these two RFID cards cost about $4.
Step 3OLED Display
The tutorial uses a 0.96" 128x64 I2C OLED monitor.
This is a very good display to use with Arduino. It's 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 in size. 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 except for Vcc and GND. If you're new to Arduino and want to use an inexpensive and simple display in your project, start here.
Step 4: Putting All the Parts Together
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 run at 3.3V, we connect the VCC from both modules to the positive breadboard rail. This rail is then connected to the 3.3V output from the Arduino Uno. Then we connect both grounds (GND) to the breadboard ground bus. We then 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. So we are going to use the Arduino UNO hardware SPI pins.
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 analog Pin 5 and the SDA on the display to 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(Management of libraries). 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 should recognize. This is an array of integers:
int code = (69,141,8,136); // UID
We then 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 the reader has a tag, we read its UID and print it on 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 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 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 with this reader or create more interesting projects, for example, so that data from a USB drive is read only after unlocking.
This project is modular, i.e. you can connect / disconnect different elements and get different functionality. The pictures above show a variant with full functionality, namely: In the firmware settings, you can select any of the three types (setting lock_type) Any of these elements can be excluded from the system: The lock is designed to operate on battery power in low power saving mode (Enable Disable: setting sleep_enable), namely: When the system is awake, press the change password button (hidden button). We fall into password change mode: When the system is not sleeping (woke up by the button or sleep is disabled), press * to enter the password entry mode Step 6: Final Result
Enter a password from numbers ( MAXIMUM 10 NUMBERS!!!)
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: