Arduino code lock with SD card. Automatic "smart" lock and Arduino. Further development of the project "Smart Castle"

It so happened that we decided to install a code lock on your door at work, because we are constantly running - we run out of the office, the door to which should be closed constantly in the absence of inhabitants. Keys often turn out to be forgotten inside. In general, they decided that the code lock was an excellent way out.

I rummaged on Chinese flea markets and eBay I did not find anything cheaper and more or less serious and decided to make it my own hands. I will make a reservation immediately that the Arduino platform was chosen for its simplicity, as the experience of communication with microcontrollers was not at all.

Idea

On the door with the outside of the door there should be a keyboard on which the password is entered, the rest of the design is fixed on the inside. To control the full closure of the door is used by Geron. Going out of the cabinet, a person presses on the "*" keyboard and without waiting until the door close the closer goes on his affairs when the door is completely closed, the Geron closes and the lock will be closed. The door opens by entering the 4x digit password and clicking on "#".

Accessories

Arduino Uno \u003d $ 18
Arduino Protoshield + BreadBoard \u003d $ 6
L293D \u003d $ 1
Punch of wires 30pcs for Braddatrad \u003d $ 4
2 Sockets RJ45 \u003d $ 4
2 plugs RJ45 \u003d $ 0.5
Central locking actuator \u003d 250 rubles.
Geron \u003d freezing free from the old window.
Sewing Metal Giant Sizes \u003d Free
Case from an old hub D-Link from one and a half million iron \u003d free
Power supply from the same D-LINK hub for 12 and 5V \u003d also for free
A bunch of screws and buckets for fastening all this good to the housing \u003d 100 rubles.
Control Panel OT security alarm \u003d free.

TOTAL: $ 33.5 and 350 rubles.

Not so little, you will say, and you will definitely right, but for the pleasure you have to pay! And you are always nice to collect something. Before the design can be slowed down, if you use a bare MK without Arduino.

Preparation for assembly

I want to say a few words about buying a key element of the actuator design. In the local auto-store I was offered the actuators of two types: "With two wires and five". According to the saleswoman, they were absolutely the same and the difference in the number of wires did not mean absolutely nothing. However, as it turned out later, it is not so! I chose a device with two wires, it was fed from 12V. In the design with five wires, the limit switches are installed, which allows you to control the movement of the lever. I realized that I didn't bought it only when I disassembled him and change it late. The course of the lever turned out to be too short to push the tape normally, so it was necessary to modify it a bit, namely, remove two rubber washers shortening the actuator lever. For this, the body had to cut along the usual hacksaw, because the second washer was inside. Blue tape us, as always helped us in the future when assembling it back.
To control the motor motor, the L293D motors was used, which withstands the peak load of up to 1200 mA, when stopping the engine of the actuator, the peak load grown up to 600 mA.
Controls from the keyboard, dynamics and two LEDs were removed from the control alarm control panel. The console and the main device was supposed to be connected using a twisted pair and RJ45 connectors

Programming.

So, as Arduino programming experience I have not had so far. I took advantage of other people's work and articles from the site arduino.cc. Who is interested, can look at this ugly code :)

Photo and video



Arduino and actuator


Power Supply


Keyboard


Sewingale (connected to the actuator with a metal needle and on which the heat shrinking for beauty)

Video operation of the device:

Progress does not stand still and "Smart Castles" are increasingly appearing on the doors of apartments, garages and houses.

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

This project will be implemented by the DIY version of the smart lock on Arduino, which can be managed remotely from any point of the ground.

In addition, the project added the ability to open the lock after the fingerprint identification. To do this, the fingerprint sensor will be integrated. Both options for opening doors will operate on the basis of the AdaFruit IO platform.

A similar castle can be an excellent first step in the project of your smart home.

Setting the fingerprint sensor

To work with the fingerprint sensor, there is an excellent library for Arduino, which greatly facilitates the process of adjusting the sensor. ARDUINO UNO is used in this project. AdaFruit CC3000 is used to connect to the Internet.

Let's start connecting power:

  • Connect the contact 5V from the Arduino board to the Red Rail;
  • The GND contact with Arduino connects to a blue rail on an inconceptuous circuit board.

Go to the connection of the fingerprint sensor:

  • First connect the power. To do this, the red wire is connected to the rail +5 V, and the black - with the Rail GND;
  • The white sensor wire connects to 4 to Arduino.
  • Green wire goes to contact 3 on a microcontroller.

Now we will deal with the CC3000 module:

  • Contact IRQ from CC3000 cards connect to Pin 2 on Arduino.
  • VBAT - to contact 5.
  • CS - to contact 10.
  • After that, you need to connect SPI contacts to Arduino: MOSI, MISO and CLK to contacts 11, 12 and 13, respectively.

Well, at the end it is necessary to provide meals: Vin - to Arduino 5V (red rail on your mounting board), and GND to GND (blue rail on the laype).

The photo of the fully assembled project is shown below:

Before developing Sketch, which will load data on Adafruit IO, you need to transfer data about your fingerprint sensor. Otherwise, in the future, he does not recognize you;). We recommend calibrating the fingerprint sensor using Arduino separately. If you work with this sensor for the first time, we recommend reading the calibration process and detailed instructions for working with the fingerprint sensor.

If you have not done this yet, you will start an account on AdaFruit IO.

After that, we can proceed to the next stage of the development of a "smart lock" on Arduino: namely, the development of the sketch, which will transmit the data on the AdaFruit IO. Since the program is quite voluminous, in the article we will highlight and consider only its main parts, and then let's give a link to GitHub, where you can download a full sketch.

Skatch begins with loading all the necessary libraries:

#Include.

#Include.

#Include.

#Include "adafruit_mqtt.h"

#InClude "adafruit_mqtt_cc3000.h"

#Include.

#Include. >

After that, you need to correctly correct the sketch, inserting the parameters of your WiFi network, specifying SSID and password (Password):

#Define Wlan_Security WLAN_SEC_WPA2\u003e

In addition, you must enter the name and AIO key (Key) to enter your ADAFRUTI IO account:

#Define Aio_Serverport 1883.

#Define Aio_USERNAME "adafruitic"

#Define Aio_Key "adafruit_io_key"\u003e

The following lines are responsible for interaction and data processing from the fingerprint sensor. If the sensor has been activated (the imprint of the coincided), will be "1":

const char fingerprint_feed progmem \u003d aio_username "/ feeds / fingerprint";

Adafruit_mqtt_publish fingerprint \u003d adafruit_mqtt_publish (& mqtt, fingerprint_feed);

In addition, you need to create an instance of the SoftWareSerial object for our sensor:

SoftWareSerial MYSERIAL (3, 4);

After that, we can create an object for our sensor:

Adafruit_fingerprint finger \u003d adafruit_fingerprint (& myserial);

Inside the Sketch, we specify which fingerid should activate the lock in the future. This example uses 0 that corresponds to the first fingerprint ID, which is used by the sensor:

iNT FINGERID \u003d 0;

After that, initialize the counter and delay (Delay) in our project. In essence, we want the lock automatically work after opening. This example uses a delay of 10 seconds, but you can adjust this value for your own needs:

iNT ActivationCounter \u003d 0;

iNT LastActivation \u003d 0;

int ActivationTime \u003d 10 * 1000;

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

In the body of the LOOP () function connect to AdaFruit IO. The following line is responsible for it:

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

if (fingerprintid \u003d\u003d FingerID && Lockstate \u003d\u003d False) (

Serial.printLN (F ("Access Granted!"));

lockstate \u003d True;

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

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

lastActivation \u003d Millis ();

If, within the LOOP () function, the lock is activated and we reached the delay value, which was indicated above, sending "0":

if ((ActivationCounter - LastActivation\u003e ActivationTime) && Lockstate \u003d\u003d True) (

lockstate \u003d 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! Do not forget to download and install all the necessary libraries for Arduino!

Make sure you have made all the necessary changes to the Sketch and download it to your Arduino. After that, open the serial monitor window.

When Arduino connects to the WiFi network, the fingerprint sensor will flash red. Legend your finger to the sensor. The Serial Monitor window should appear the ID number. If it coincides, a message will appear, "OK!". This means that the data was sent to the AdaFruit IO servers.

Scheme and Sketch for further lock setting on the example of the LED

Now we will deal with the part of the project that is directly responsible for managing the door lock. To connect to the wireless network and activate / deactivate the lock, you will need an optional ADAFRUTI ESP8266 module (the ESP8266 module does not have to be from AdaFruit). On the example, which we will consider below, you will be able to evaluate how easy it is to ensure the exchange of data between two platforms (Arduino and ESP8266) using AdaFruit IO.

In this section, we will not work directly with the lock. Instead, we simply connect the LED to the contact, where the lock will be connected hereinafter. This will give the opportunity to test our code, without deepening in the features of the castle design.

The scheme is quite simple: first set the ESP8266 on the Breadboard. After that, set the LED. Do not forget that the long (positive) leg of the LED is connected via the resistor. The second resistor foot is connected to contact 5 on the ESP8266 module. The second (cathode) of the LED is connected to the GND Pin on ESP8266.

Fully collected scheme Shown in the photo below.


Now let's figure it out with a sketch that use for this project. Again, the code is quite voluminous and complicated, so we will consider only its main parts:

We start with the connection of the necessary libraries:

#Include.

#Include "adafruit_mqtt.h"

#Include "adafruit_mqtt_client.h"

Configure WiFi:

#Define Wlan_ssid "Your_Wifi_ssid"

#Define WLAN_PASS "Your_Wifi_Pall"

#Define Wlan_Security WLAN_SEC_WPA2.

Also configure the parameters of AdaFruit IO. Just as in the previous section:

#Define Aio_Server "Io.adafruit.com"

#Define Aio_Serverport 1883.

#Define Aio_USERNAME "adafruit_io_" user "

#Define Aio_Key "adafruit_io_key"

We indicate to which Pine we have connected the LED (in the future it will be our lock or relay):

int relaypin \u003d 5;

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

const char lock_feed progmem \u003d aio_username "/ Feeds / Lock";

ADAFRUIT_MQTT_SUBSCRIBE LOCK \u003d ADAFRUIT_MQTT_SUBSCRIBE (& MQTT, LOCK_FEED);

In the body of the setup () function, we specify that the PIN to which the LED is connected should operate in Output mode:

pinmode (Relaypin, Output);

Within the loop () cycle, first check whether we connected to AdaFruit IO:

After that, check which signal comes. If "1" is transmitted, activate the contact that we have announced earlier to which our LED is connected. If we got "0", we translate contact to the "Low" state:

Adafruit_mqtt_subscribe * subscription;

while ((Subscription \u003d MQTT.ReadSubscription (1000))) (

if (Subscription \u003d\u003d & Lock) (

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

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

// Save the command to data type data

String Command \u003d String (Char *) lock.Lastread);

if (Command \u003d\u003d "0") (

digitalWrite (Relaypin, Low);

if (Command \u003d\u003d "1") (

digitalWrite (Relaypin, High);

To find last version Sketch you can on GitHub.

It's time to test our project. Do not forget to download all the necessary libraries for your Arduino and check whether you have made changes to the sketch.

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

Load the Skatch on Arduino and open the serial monitor window. At this stage, we simply checked whether to connect to ADAFRUTI IO: Affordable functionality we will look further.

Test project

Now proceed to testing! Go to your Adafruit IO user menu, in Feeds menu. Check, created or no channels for the fingerprint and lock (on the print screen below it is the rows Fingerprint and Lock):


If there is no, you have to create manually.

Now we need to provide data exchange between FingerPrint and Lock channels. The Lock channel must make the value "1" when the FingerPrint channel takes the value "1" and vice versa.

To do this, use a very powerful tool AdaFruit IO: triggers. Triggers are in essence conditions that you can apply to the configured channels. That is, they can be used to interrelation of 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 channels and the castle:


This is how it should look when both triggers are customized:

Everything! Now we can really test our project! Apply your finger to the sensor and see as Arduino began to wink by the LED, which corresponds to data transmission. After that, the LED is blinking on the ESP8266 module. This means that he began to receive data via MQTT. The LED on the circuit board at this point should also turn on.

After the delay, which you installed in the Sketch (by default, this value is 10 seconds), the LED will turn off. Congratulations! You can control the LED with a fingerprint, being at any point in the world!

Customize electronic castle

We got to the last part of the project: the direct connection and control of the electronic lock using Arduino and the fingerprint sensor. The project is not easy, you can use all the sources in the form in which they are set out higher, but instead of the LED to connect the relay.

To directly connect the lock, you will need additional components: power supply to 12 V, Jack for power supply, transistor (in this example, used IRLB8721PBF MOSFET, but you can also use another, for example, the bipolar transistor TIP102. If you use a bipolar transistor, you will need Add a resistor.

Below is shown electrical circuit Connecting all components to the ESP8266 module:


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

The fully assembled project is shown in the photo below:


Wave an ESP8266 module using the FTDI module and connect the power supply of 12 V to Jack. If you used the recommended pins to connect, you do not have to change anything in the sketch.

Now you can lean your finger to the sensor: the lock must work, responding to your fingerprint. The video below shows the project of an automatic "smart" castle in action:

Further development of the project "Smart Castle"

In our project released remote control of the door lock using a fingerprint.

You can safely experiment, modify the sketch and strapping. For example, you can replace the door electronic lock on the relay to manage your 3D printer, manipulator or quadcopter ...

You can develop your " smart House"For example, remotely activate the irrigation system on Arduino or include the light in the room ... Do not forget that you can simultaneously activate the 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 the discussion!

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





To assemble the electronic lock 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 via the 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 set, open the installed application, enter 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 lock friends in the room.

This project is modular, i.e. You can connect / disable different items and get different functionality. The pictures above shows the option with full functionality, namely:

  • Locking mechanism. Used to open and closing the door. This project discusses the use of three different mechanisms:
    • Servo. There are big, there are small. Very compact, and coupled with severe casing - a great option
    • Castle electric drive car door. Big and powerful thing, but eats just crazy currents
    • Solenoid pike. A good optionbecause it slams himself

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

  • Button inside. It serves to open and closing the door from the inside. Can be placed on the door handle (from the palm or from the side of the fingers), on the door itself, or on the jam
  • Button Outside. It serves to close the door, as well as for awakening from energy saving. Can be placed on the door handle (from the palm or from the side of the fingers), on the door itself, or on the jam
  • Context on the closure of the door. Used to automatically close the lock when closing the door. They may be:
    • Clock Button
    • Hall sensor + magnet on the door itself
    • Gercon + magnet on the door itself
  • Secret access reset button. Used to reset the password / entering a new password / memorization of a new key / combination, etc. Can be hidden somewhere in the case
  • Light-emitting diode To indicate work. RGB LED, used red and green colors (when mixed is yellow):
    • Gorite green - the castle is open. Gorbs not to forget to close the door
    • Yellow is burning - the system woke up and expects the password input
    • Flashing red - sat down battery

Any of these elements can be excluded from the system:

  • We remove the confusion. In the firmware in the settings, also turn it off (setting tail_Button.). Now to close the lock, you need to press the button.
  • We remove the outdoor button. In the firmware in the settings, also turn it off (setting wake_button.). Now the system does not need to wake up, it wakes up itself (energy consumption is slightly larger). And also, we now do not have a button to close on the front door, and you need a confusion. Either castle - tickold
  • We remove the inner button. This option is suitable for cabinets and safes. You do not need to change anything in the settings
  • We remove the LED. You do not need to change anything in the settings
  • The access reset button can be disappeared after the first use, or rewrite the code for itself
  • The door is closed, clicking outside - wake up, wait for the password input / RFID label / electronic key / fingerprint
  • The door is closed, the system woke up, waiting for the password. Time can be configured (setting sleep_time.)
  • The door is closed, the password is entered / label / key, etc. - Open
  • The door is closed, pressed inside - open
  • The door is open, clicks from the outside - close
  • The door is open, pressed inside - close
  • The door is open, pressed - close

The lock provides a battery operation in low power saving mode (Enable Disable: Setup sleep_enable), namely:

  • Waking up every few seconds, follow the event (optional option, if there is no button outside. You can enable in the setting wake_button.)
  • Every few minutes to monitor the AKUM voltage (on / off setting battery_Monitor)
  • If the akum is discharged (the voltage is set in the setting bat_low.):
    • open door (optional, can be configured in the firmware open_Bat_low.)
    • prohibit Further Opening and Closing
    • when you click on the buttons to flash a red LED
    • stop watching the event (i.e. Password / label, etc.)

When the system does not sleep, press the password shift button (hidden button). Find B. password change mode:
We enter a password from numbers ( Maximum 10 digits !!!)

  • Clicking * Password is recorded in memory and the system comes out of the password change
  • When you click the password is reset (you can enter again)
  • If you do not press anything 10 seconds, automatically leave the password change mode, the password will remain old

When the system does not sleep (I woke up the buttons or sleep is disabled), click * To enter the password entry mode
If the system is sleeping and periodically wakes up to check the event, then press * and hold until the red LED will light up
Password entry mode:

  • Password processing is made in such a way that the correct password is counted only when set to the correct sequence of numbers, 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 up 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 the usual (duty) mode
  • If you click #, immediately come out of the password entry mode
  • If you press the secret password change button in password input mode, then you will come out of it

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. Finished scheme It 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

mOB_INFO.