Arduino combination lock - scheme

click fraud protection

Arduino is the best system for copying any hardware. Most ideas would not have been possible without her. There has long been such a thought: to create a special combination lock on the arduino. To open it, you need to hold down a certain key. In this case, the lock should not open, even if you know the desired button. To open it, it is necessary to maintain certain intervals using muscle memory. Such a criminal cannot do. But this is all just theory.

To collect it, you need to use a special device for rectangular pulses, as well as several counters and a heap. But the finished device would have large dimensions and would be inconvenient to use. As a rule, such thoughts do not give rest. The first step in making this dream come true was the creation of a program for Arduino. It is she who will serve as a combination lock. In order to open it, you need to press not one key, but several, and do it simultaneously. The finished circuit looks like this:

The picture quality is not the best, but connections are made to ground, D3, D5, D7, D9 and D11.

The code is shown below:

const int ina = 3; const int inb = 5; const int inc = 9; const int ledPin = 13; int i = 1000; byte a = 0; byte b = 0; byte c = 0; byte d = 0; unsigned long time = 0; // don't forget everything that millis () takes on unsigned long temp = 0; // store in unsigned long byte keya [] = {0, 0, 0, 0, 0, 0, 0, 0}; // codes proper byte keyb [] = {1, 1, 1, 1, 0, 1, 0, 0}; byte keyc [] = {1, 0, 1, 0, 1, 1, 1, 0}; byte k = 0; void setup () {pinMode (ina, INPUT_PULLUP); // 3 inputs connected to the buttons pinMode (inb, INPUT_PULLUP); pinMode (inc, INPUT_PULLUP); pinMode (ledPin, OUTPUT); // built-in LED on pin 13 pinMode (7, OUTPUT); pinMode (11, OUTPUT); digitalWrite (7, LOW); // replace the ground digitalWrite (11, LOW); time = millis (); // needed to count the time} void blinktwice () {// double blinking of the LED digitalWrite (ledPin, HIGH); delay (100); digitalWrite (ledPin, LOW); delay (100); digitalWrite (ledPin, HIGH); delay (100); digitalWrite (ledPin, LOW); delay (200); } void loop () {if (k == 0) {blinktwice (); // prompt to enter code} if (k == 8) {digitalWrite (ledPin, HIGH); delay (3000); k = 0; } a = digitalRead (ina); // signal levels are read from buttons - pressed / not pressed b = digitalRead (inb); c = digitalRead (inc); delay (100); // the next if - protection against false positives, you don't need to use if ((digitalRead (ina) == a) && (digitalRead (inb) == b) && (digitalRead (inc) == c)) {if (a == keya [k]) {if (b == keyb [k]) {if (c = = keyc [k]) {k ++; }}}} if (k == 1) {if (d == 0) {time = millis (); d ++; }} temp = millis (); temp = temp - time; if (temp> 10000) {k = 0; d = 0; time = millis (); } } 


In order not to raise unnecessary questions about the code, some points should be clarified. The setup function is used to assign ports. The next function is Input_Pullup, which is needed to increase the pin voltage by 5 V. This is done using a resistor. Due to this, various short circuits will not occur. For more convenience, it is recommended to use the blinktwice function. 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, then it will be indicated by the number 1, and if not - 2. Further, all values ​​are analyzed. For example, a combination such as 0,1,1 appeared. This means that the first key is pressed and the other two are not. If all values ​​are true, then condition 8 is also true. This is evidenced by the illuminated LED on the front panel. Next, you need to enter a specific code that will serve to open the door.

The last elements of the code are used to reset the counter values. This function is performed if more than 10 seconds have passed since the last key press. Without this code, it was possible to enumerate all possible options, although there are quite a few of them. After creating this device, you need to test it. Yet Arduino projects.

Like(0)I do not like(0)

instagram viewer