Menu
Is free
check in
the main  /  Problems / Electronic castle on Arduino Uno. Electronic lock do it yourself

Electronic castle on Arduino Uno. Electronic lock do it yourself

In this lesson, we will learn to make a simple system that will unsubscribe the castle on electronic key (Label).

In the future, you can refine and expand functionality. For example, add the "Add new keys and delete them from memory". In the basic case, consider a simple example when unique identificator The key is pre-set in the program code.

In this lesson we will need:

To implement the project, we need to install libraries:

2) Now you need to connect the buzzer that will serve the signal if the key worked and the lock opens, and the second signal when the lock closes.

The buzzer is connected in the following sequence:

Arduino. Buzzer
5V. VCC.
GND. GND.
pIN 5. IO.

3) A servo will be used as a unlocking mechanism. The servo can be selected any, depending on the size and effort required to you, which creates a servo. Servo Drive has 3 contacts:

More vividly you can see how we connected all modules in the picture below:

Now, if everything is connected, you can go to programming.

Sketch:

#Include. #Include. #Include. // Library "RFID". #Define ss_pin 10 #define RST_PIN 9 MFRC522 MFRC522 (SS_PIN, RST_PIN); unsigned long uiddec, uiddecmp; // For the label label in the decimal format SERVO SERVO; Void setup () (serial.begin (9600); serial.printLN ("Waiting for Card ..."); SPI.begin (); // Initialization of SPI / INIT SPI BUS. MFRC522.pcd_init (); // Initialization MFRC522 / INIT MFRC522 CARD. SERVO.ATTACH (6); SERVO.WRITE (0); // Install the server in the closed saving) void loop () (// Search for a new IF label (! MFRC522.PICC_ISNEWCardPresent ()) (Return; ) // Selecting if (! MFRC522.PICC_READCARDSERIAL ()) (RETURN;) uiddec \u003d 0; // issuance serial number Tags. for (byte i \u003d 0; i< mfrc522.uid.size; i++) { uidDecTemp = mfrc522.uid.uidByte[i]; uidDec = uidDec * 256 + uidDecTemp; } Serial.println("Card UID: "); Serial.println(uidDec); // Выводим UID метки в консоль. if (uidDec == 3763966293) // Сравниваем Uid метки, если он равен заданому то серва открывает. { tone(5, 200, 500); // Делаем sound signal, Opening SERVO.WRITE (90); // Rotate the serv at an angle of 90 degrees (unscrewing any mechanism: the valve, turn the key, etc.) Delay (3000); // Pause 3 seconds and the mechanism is locked. Tone (5, 500, 500); // Make a beep, closing) SERVO.WRITE (0); // Install the serv in closed saving)

We will examine the sketch in more detail:

In order to find out the UID cards (tags), you need to write this sketch in Arduino, collect the scheme set out above and open the console (monitoring of the serial port). When you bring the label to RFID, the number in the console

The resulting UID must be entered in the following line:

If (uiddec \u003d\u003d 3763966293) // Compare UID tags if it is equal to the specified, the servo opens the valve.

Each card has a unique identifier and is not repeated. In such a way, when you bring a card whose identifier you are set in the program, the system will open access using a servo.

Video:

In this article I will tell you how to make a code castle from Arduino. To do this, we will need red and green LEDs, a buzzer, Arduino Nano, LCD display With I2C converter, servo and matrix keyboard 4x4. When you turn on the display will write "Enter Code.",

turn on the red LED,

and the green will go out, the servo is set to 0 °. When entering numbers on the display will light up *.

If the code is entered incorrectly, the display will write "Enter Cod.". If the code is correct, the beep sounds, the servo drive turns 180 °, the display will write "Open."

will turn on the green LED,

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

then the display will write "ENTER CODE.". Now about the scheme. First connect Arduino with the wires with a batch board (power contacts).

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

Then servo. It is connected to contact 10.

Red LED to contact 11.

Green - to contact 12.

The buzzer is to contact 13.

Now load the sketch.

#Include. #Include. #Include. #Include. ovarduino_kb Kb (9, 8, 7, 6, 5, 4, 3, 2); LiquidCrystal_i2c LCD (0x27, 16, 2); SERVO SERVO; INT PASS \u003d (3, 6, 1, 8); int in; int r \u003d 11; int g \u003d 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); SERVO.WRITE (0); lcd.setcursor (0, 0);) void loop () (lcd.clear (); lcd.print ("ENTER CODE"); While ( ! KB.Check (key_down)) (Delay (1);) in \u003d kb.getnum; lcd.clear (); lcd.setcursor (0, 0); lcd.print ("*"); While (! Kb. check (key_down)) (delay (1);) in \u003d kb.getnum; lcd.print ("*"); While (! KB.Check (key_down)) (Delay (1);) in \u003d kb.getnum; lcd.print ("*"); while (! kb.check (key_down)) (delay (1);) in \u003d kb.getnum; lcd.print ("*"); if (in \u003d\u003d PASS) (IF (IN \u003d\u003d PASS) (if (in \u003d\u003d PASS) (if (in \u003d\u003d pass) (LCD.Clear (); LCD.Setcursor (0, 0); lcd.print ("Open"); Tone ( 13, 400, 750); SERVO.WRITE (180); DigitalWrite (R, Low); DigitalWrite (G, High); Delay (3000); lcd.clear (); lcd.setcursor (0, 0); LCD. Print ("Close"); Tone (13, 300, 700); SERVO.WRITE (0); DigitalWrite (G, Low); DigitalWrite (R, HIGH); Dela y (1000); )))))

That's all. Enjoy the code lock!

List of radio elements

Designation A type Nominal number NoteScoreMy notebook
E1 Arduino board

Arduino Nano 3.0

1 5V. In notebook
E8, E9 Resistor

220 Oh.

2 SMD. In notebook
E6. Light-emitting diode

Al102g.

1 Red In notebook
E7. Light-emitting diode

Al307g.

1 Green In notebook
E3. LCD displayWith I2C interface1 Green backlight In notebook
E5 ServoSG90.1 180 degrees In notebook
E2. Buzzer5V.1 Bu. In notebook
E4. Keyboard4x41 Matrix In notebook
Not Breadboard.640 Points1 Without soldering

The other day I reviewed the film "New Spiderman" and in one stage Peter Parker remotely opens and closes the door from his laptop. As soon as I saw it, I immediately realized that I need such an electronic lock on the front door.

Bearing a bit, I gathered a valid model of a smart castle. In this article, I will tell you how I collected her.

Step 1: List of Materials





For assembly electronic Castle On Arduino, you will need the following materials:

Electronics:

  • 5V wall adapter

Components:

  • 6 screws for the spinlet
  • cardboard
  • wires

Instruments:

  • soldering iron
  • adhesive Pistol
  • drill
  • drill
  • drill for guide hole
  • stationery knife
  • computer with Arduino IDE

Step 2: How the castle works

The idea is that I can open or close the door without a key, and even without coming to it. But this is only the main idea, because you can still add a detonation sensor so that it reacts to a special knock, or you can add a voice recognition system!

The servo lever connected to the scorelet will close it (0 °) and open (60 °) using the commands obtained through bluetooth module.

Step 3: Wire Installation Scheme


Let's first connect the servo to the Arduino board (I want to note that, although I used the Arduino Nano fee, in the Uno board, the location of the conclusions is exactly the same).

  • brown wire servo - grounding, connect it to the ground on Arduino
  • red wire - plus, connect it to the 5B connector on Arduino
  • orange wire - output of the source of the servo, connect it to the 9th conclusion on Arduino

I advise you to check the operation of the servo before continuing the assembly. To do this, in the Arduino IDE program in the examples choose SWEEP. Making sure that the servo works, we can connect a Bluetooth module. You need to connect the RX output of the Bluetooth module with the TX output Arduino, and TX output of the module with RX output Arduino. But do not do it yet! When these connections are soldered, you will no longer be able to download any codes on Arduino, so you first download all your codes and only after that solder connections.

Here is the scheme of the module and microcontroller compounds:

  • RX Module - TX Arduino Boards
  • TX Module - RX Boards
  • VCC (positive output) module - 3.3V Arduino boards
  • Ground Connect with Ground (Ground Ground)

If the explanation seems to you incomprehensible, follow the scheme of the wire connections.

Step 4: Testing

Now that we have all the acting parts, let us make sure that the servo can move the scorelet. Before mounting a scoring on the door, I gathered a trial sample to make sure that the servo is quite powerful. At first it seemed to me that my servo was weak and I added a drop of oil into a scarlet, after that he all worked fine. It is very important that the mechanism slides well, otherwise you risks to be locked in your room.

Step 5: Case for electrocomponents



I decided to put the controller only in the case and the Bluetooth module, and the servo is left outside. To do this, on a piece of cardboard, we supply the Arduino Nano circuit circuit and add 1 cm space around the perimeter and cut out. After that, we also cut out five more sides of the body. In the front wall, it will be necessary to cut hole hole for the power cord of the controller.

Side sizes of the case:

  • 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 power cord)
  • Rear wall - 4x4 cm

Step 6: Appendix

To control the controller, you need a gadget on Android or Windows with a built-in Bluetooth. I did not have the opportunity to check the operation of the application on apple devices, maybe you need some drivers.

I am sure that some of you have the opportunity to check it out. For Android Download Bluetooth TERMINAL application, download Teraterm for Windows. Then you need to connect the module to the smartphone, the name must be LINVOR, password - 0000 or 1234. Once the pairing is established, open installed applicationEnter the option and select "Install the connection (unsafe)". Now your smartphone is the Arduino serial interface monitor, that is, you can exchange data with the controller.

If you enter 0, the door will close, and on the screen of the smartphone there will be a message "The door is closed".
If you enter 1, you will see how the door opens, and on the screen there will be a message "The door is open."
On Windows, the process is the same, except that you need to install the TeraTerm application.

Step 7: Intim the scorelet


First you need to connect a spiting servo drive. To do this, cut the plugs from the mounting holes of the drive housing. If we put the servo drive, the mounting holes must be closed with a shatter. Then you need to put the servo lever into the spinlet slot, where there was a spinlet handle. Check how the lock goes in the case. If everything is fine, secure the servo lever with glue.

Now you need to drill in the door guide holes for screws. To do this, attach scores to the door and pencil, mark on the door of the door hole under the screws. Drill in the observed places of the hole under the screws at a depth of about 2.5 cm. Apply the scorehold and secure it with screws. Check the servo operation again.

Step 8: Nutrition


To complete the device, you will need a power source, cord and mini-USB plug to connect to Arduino.
Connect the power output of the power source with the output of the Earth of the USB mini-port, connect the red wire with the red wire of the USB mini-port, then stretch the wire from the lock to the door loop, and stretch it from it to the outlet.

Step 9: Code

#include SERVO MYSERVO; int pos \u003d 0; int state; int flag \u003d 0; void setup () (myservo.attach (9); serial.begin (9600); myservo.write (60); delay (1000);) void loop () (if (serial.available ()\u003e 0) (state \u003d Serial.read (); flag \u003d 0;) // If the state is "0" The DC Motor Will Turn Off If (state \u003d\u003d "0") (MYSERVO.WRITE (8); Delay (1000); Serial. PrintLN ("Door Locked");) ELSE if (state \u003d\u003d "1") (MYSERVO.WRITE (55); Delay (1000); serial.printLN ("Door unlocked");))

Step 10: Complete castle on the basis of Arduino

Enjoy your castle with remote control, And do not forget to "by chance" to locate friends in the room.

Master youtube Channel "AlexGyver" asked to make an electronic lock with their own hands. Welcome to the video cycle about the electronic locks on Arduino. In general terms, the master will explain the idea.

There are several options for creating an electronic lock system. Most often used to lock doors and boxes, cabinets. As well as to create caches and secret safes. Therefore, you need to make a layout with which it is convenient to work and can be clearly shown in detail the device system from the inside and outside. Therefore, I decided to make a frame with the door. To do this, you will need a square bar of 30 x 30. Plywood 10mm. Door hinges. Initially, I wanted to make a plywood box, but I remembered that everything was twisted with spare parts. Such a box has nowhere to put. Therefore, the layout will be made. If someone wants to put an electronic lock, then looking at the layout you can easily repeat everything.

All you need for the castle will find in this Chinese store.

Goal is to develop maximum effective schemes and firmware for electronic locks. You can use these results to install these systems on your doors, boxes, cabinets and caches.

The door is ready. Now you need to come up with how to open and close electronic method. For these purposes, a powerful solenoid pike with AliExpress is suitable (link to the store above). If you submit to voltage conclusions, it will open. The coil resistance is almost 12 ohms, it means that at a voltage of 12 volts, the coil will eat about 1 amp. With such a task can cope and lithium battery and boosting module. Customize the appropriate voltage. Although you can and slightly more. The pitch is mounted on the inside of the door at a distance so as not to clinging the edge and could slam. Shekold must be a retaliatory part in the form of a metal box. It is uncomfortable to use it without it. We'll have to put a step, at least created the appearance of normal operation.

In idle mode, the junk opens normally, that is, if there is a handle on the door, we apply a pulse, open the door for the handle. But if you jump out, this method is no longer suitable. The enhancement converter does not cope with the load. To open the spring-made door, you will have to use large batteries and a more powerful converter. Either a network power supply and score on the autonomy of the system. In Chinese stores there are large sizes. They are suitable for boxes. Nutrition can be supplied using a relay or transistor mosphore, or a power key on the same transistor. More interestingly and less expensive option is a servo connected to a connecting rod with any locking element - a decorating or more serious valve. It may also be needed a piece of steel needles that performs the role of a connecting rod. Such a system does not need a high current. But it takes more space and more tricky management logic.

There are two types of servo drives. Small weak and large powerful, which can be calmly plugged into the holes in serious metal pins. Both shown options work both on the doors and on drawers. With the box will have to tinker, pulling the hole in the retractable wall.

The second part of

Arduino is best system To copy any equipment. Most ideas would not be able to come true without her. For a long time there is such a thought: create a special code lock on Arduino. To open it, it is necessary to plug a specific key. In this case, the lock should not be opened, even if you know the desired button. To open it, it is necessary to withstand certain intervals using muscle memory. Such a criminal will not be able to commit. But this is all the theory.

To collect it, you need to take advantage of the special device of rectangular pulses, as well as several meters and heap. But the finished device would have big dimensions And it could not be used. As a rule, such thoughts do not give rest. The first stage in the embodiment of the dream was the creation of a program under Arduino. It is she who will serve as a code lock. In order to open it, you will need to press not one key, but a few, and do it at the same time. The finished scheme looks like:

The picture quality is not the best, but the connection is performed to the ground, D3, D5, D7, D9 and D11.

The code is presented below:

Const int ina \u003d 3; Const int Inb \u003d 5; Const int Inc \u003d 9; Const int ledpin \u003d 13; int i \u003d 1000; Byte a \u003d 0; BYTE B \u003d 0; BYTE C \u003d 0; BYTE D \u003d 0; unsigned long time \u003d 0; // Do not forget everything that takes the value of Millis () unsigned long temp \u003d 0; // Store in unsigned long byte keya \u003d (0, 0, 0, 0, 0, 0, 0, 0); // codes actually byte keyb \u003d (1, 1, 1, 1, 0, 1, 0, 0); BYTE KEYC \u003d (1, 0, 1, 0, 1, 1, 1, 0); Byte k \u003d 0; void setup () (Pinmode (INA, INPUT_PULLUP); // 3 inputs connected to the Pinmode buttons (INB, INPUT_PULLUP); Pinmode (INC, INPUT_PULLUP); Pinmode (LEDPIN, OUTPUT); // Built-in LED on the 13th Pine Pinmode (7, Output); Pinmode (11, Output); DigitalWrite (7, Low); // Replace the earth DigitalWrite (11, Low); Time \u003d Millis (); // Need to reference time) void blinktwice () ( // Double blinking DigitalWrite LED (LEDPIN, HIGH); Delay (100); DigitalWrite (LEDPIN, LOW); Delay (100); DigitalWrite (LEDPIN, HIGH); Delay (100); DigitalWrite (LEDPIN, LOW); Delay ( 200);) void loop () (if (k \u003d\u003d 0) (Blinktwice (); // Invitation Enter code) if (k \u003d\u003d 8) (DigitalWrite (LEDPIN, HIGH); Delay (3000); k \u003d 0 ;) A \u003d Digitalread (INA); // Signal levels are read from the buttons - pressed / not pressed B \u003d DigitalLread (INB); C \u003d DIGITALREAD (INC); Delay (100); // Next if - Protection against false positives, You can not use if ((DigitalLread (INA) \u003d\u003d a) && (Digitalread (InB) \u003d\u003d b) && (DigitalRead (INC) \u003d\u003d C)) (IF (A \u003d\u003d KEYA [K]) (IF (B \u003d\u003d keyb [k]) (if (c \u003d\u003d keyc [k]) (k ++; )))) if (k \u003d\u003d 1) (if (d \u003d\u003d 0) (Time \u003d Millis (); d ++;)) temp \u003d millis (); Temp \u003d Temp - Time; if (temp\u003e 10000) (k \u003d 0; d \u003d 0; time \u003d millis ();))

In order not to have any extra questions on the code, some moments should be explained. The SETUP function is used to assign ports. The following function is input_pullup, which is necessary to increase the voltage of the pine by 5 V. This is carried out using a resistor. Due to this, various short circuits will not occur. For greater convenience, it is recommended to use the BlinkTwice feature. In general, when creating various programs, you need to try other functions.

After assigning the functions, the signal is read from the ports. If the button is pressed, this will be denoted by a number 1, and if not - 2. Next, there is an analysis of all values. For example, such a combination appeared as 0.1.1. This means that the first key is pressed, and the remaining two is not. If all values \u200b\u200bare executed correctly, then condition 8 is also true. This is evidenced by the lightned LED on the front panel. Next, you need to enter a specific code that will serve to open the door.

The latest code elements are used to drop the meter values. This function is performed if after the last keystroke, more than 10 seconds passed. Without this code, it was possible to go through everything possible optionsAlthough there are a lot of them enough. After creating this device It is necessary to test it. Yet