Unusual combination lock on Arduino

Arduino is the best system for copying any equipment. Most ideas would not have been possible without her. For a long time there has been such an idea: to create a special combination lock for 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 right 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 just a theory.

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

Combination lock

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

The code is presented 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 takes a millis () value

unsigned long temp = 0; // store in unsigned long

byte keya [] = {0, 0, 0, 0, 0, 0, 0, 0}; // codes actually

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 buttons

pinMode (inb, INPUT_PULLUP);

pinMode (inc, INPUT_PULLUP);

pinMode (ledPin, OUTPUT); // built-in LED on the 13th pin

pinMode (7, OUTPUT);

pinMode (11, OUTPUT);

digitalWrite (7, LOW); // replace the earth

digitalWrite (11, LOW);

time = millis (); // needed to count time

}

 

void blinktwice () {// double flashing 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 for code

}

if (k == 8) {

digitalWrite (ledPin, HIGH);

delay (3000);

k is 0;

}

a = digitalRead (ina); // read signal levels from buttons - pressed / not pressed

b = digitalRead (inb);

c = digitalRead (inc);

delay (100); // next if - protection against false positives, you can not 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 is 0;

d is 0;

time = millis ();

}

}


To avoid 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 necessary to increase the pin voltage by 5 V. This is done using a resistor. Due to this, various short circuits will not occur. For greater convenience, it is recommended to use the blinktwice function. In general, when creating various programs, you need to try other functions.

After the functions are assigned, 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. Next, an analysis of all the values. For example, there was such a combination as 0,1,1. 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 a lit LED on the front panel. Next, you need to enter a specific code that will serve to open the door.

The last code elements are used to reset the counter values. Such a function is performed if more than 10 seconds have passed since the last keystroke.Without this code, you could go through all the possible options, although there are a lot of them. After creating this device, you need to test it.

 

(3 votes)
Loading...

Add a comment