Electronic combination to a single key – Sketch Arduino

Sketch Arduino to create an electronic combination to a single key

This page describes a software capable of transforming a the Arduino board in a electronic combination a single button.

The program is structured in such a way to use the timings without using the delay() command and this means that the program can be used stand-alone, or even inside your sketch invoking the procedure within the main loop.
Attention to programs too costly in cpu resources, or with many delays. The program “Electronic combination a single button” requires that its routine is called by the loop several times per second (not under 20 executions per second).

But what is an electronic combination a single button

It ‘a device that allows you to open an electric gate or garage. Is designed as an extreme measure that allows you to enter the house (garage – workplace etc..) in the case that you forgot the keys, or even worse, you left within the protected area and you have no other option than to break something very expensive (see door, window, windows, door, wall, etc..).
The key is nothing more than a physically Arduino Board, a relay, a small push-button and a led. The push-button will be hidden and actionable without attracting attention. The led can be hidden away in a distant place even tens of meters, whose light is visible from the key and that is virtually invisible to those who do not know that it exists.

How do I put the electronic combination

This electronic combination a single button works like this: you press the push-button. After n seconds, the LED blinks 9 times. In this sequence of blinks, press the key in correspondence with the blink number x, where x is the number corresponding to the first digit of the your secret code. Then after a short pause starts the second sequence of 9 flashes which, as above, you must press the key in correspondence with the blink whose number corresponds to the second number of the combination. And then it repeats for all numbers of the combination.
At this point, if the combination is inserted correctly, after several minutes, the program will activate the relay to open a gate or garage. If the combination is wrong, another relay can activate a siren. What described is shown in the following video.

To enter the combination you waste a lot of time. The program has been designed so. Not only, if you fail to enter the numbers, you have to wait at least 5 minutes before the program accepts a new combination. So will take much time to enter the combination and you will also have to wait, after entering the exact combination, to open the gate. This is because the main objective of the program is to oblige the person, that insert the secret combination, to stay near the push-button as long as possible. This is to increase the probability that he is seen by the neighbors or occasional passers. In other words, the program will makes you lose a lot of time. But it is precisely this time that make desist an attacker, because this increases him the risk of being noticed and find out.

How you can use the program

In a Arduino board dedicated to the purpose.

Connect the wires as in the diagram and load the program into the Arduino board through its IDE. Now wait more than 5 minutes, then press the push-button once to start the flashing sequences.
Arduino connections to make the electronic key with a single push-button combination

In an Arduino board as a sketch of the main routine.

Connect the wires as in the diagram. Check that the variable names are not already used in your sketch. Enter the two routines combinazionesetup () and combination () at the end of your sketch and call the first routine in the setup () and the second inside the Loop (). Remember that the routine inside the loop must be launched continuously, at least several tens of times per second, to be able to work in parallel with your sketch. In other words, ensure you did not use command delay(), or loop “FOR” that that stops the execution of the main loop() for long time. Obviously each case is different, but in general, if you have the delay, put them inside a FOR loop, along with the call to the routine combination(), after that the delay time is divided by the number of iterations (eg Delay (2000) becomes: FOR (int I = 0, 100, I++) {delay (20); combination();}. Instead, for FOR o WHILE loops, you must put inside them also the recall to combination() routine.

The program main parameters

The program main parameters of this electronic combination, are the following:

Cor_PeriodoImpostato=1000; Is the duration of the LED lit in a single flash. It is expressed in milliescondi (divide by one thousand to get the seconds).
Cor_indice = 4; It ‘s the number of digits of your PIN. Since the varibile also considers zero, the number of digits will be given by the value in the variable plus one.
Cor_combimpostata[] = {1, 2, 3, 4, 5}; The combination, all the digits of your PIN.
Cor_OKTempoacceso = 800; The time that the pin of the arduino remains to one after you insert the exact combination. This time is set because often the electric locks do not open for short periods, while for long periods of time there is a risk of electromagnet overheating. A value of 0.8 seconds would seem appropriate. However, be modified as you wish.
Cor_NONOKTempoacceso = 3000; Time that pin to connect to the trumpets (always via a relay) stays on when you enter the wrong combination. It is set to three seconds, but can be increased up to 32 sec (maximum value of the variable INT).
Cor_TempoStandby = 300000; Is the time, after entering a combination, in which the program is intentionally inactive. Used to prevent repeated attempts to various combinations by attackers who eventually come to their knowledge of this electronic key system.

 

These parameters can be changed according to your needs.

The program / sketch Electronic combination a single button

The program can be used freely I ask you only a moral obligation to leave the author’s name within the routine and satisfy the curiosity of knowing that you’re using it (maybe with a picture postcard of your part of the world, or at worst with an email).
You can download it at the following link

Chiave_elettronica_a_combinazione_ad_un_solo_tasto-Versione_1_0_1.ino

or you can view it below.

//** ************************************************************************* **//
//** One button electronic key combination – Ver.1.0.1                 ENGLISH **//
//** ************************************************************************* **//
//**                                                                           **//
//** Author Corrado Bevilacqua                                                 **//
//**                                                                           **//
//** The program or sketch is free under the following conditions:             **//
//** 1) you must keep the author’s name within the routine.                    **//
//** 2) send a postcard of your town to the author                             **//
//** 3) not for commercial use                                                 **//
//**                                                                           **//
//** ————————————————————————- **//
//**                                                                           **//
//** How it Work:                                                              **//
//**                                                                           **//
//** Set your combination in the following variable:                           **//
//**     int Cor_combimpostata[] = {1, 2, 3, 4, 5};                            **//
//**                                                                           **//
//** Load this Sket on your Arduino. Then you can use it in this way;          **//
//** 1) press button.                                                          **//
//** 2) count the led flash.                                                   **//
//** 3) when the number of flashing light is equals the first value of your    **//
//**    code, press the button (while the led in on).                          **//
//** 4) Wait the 5 second pause at the end of flashing sequence.               **//
//** 5) count again the led flash.                                             **//
//** 6) when the number of flashing light is equals to the second value of     **//
//**    your secret code. Press the button (always while the led in on).       **//
//** 7) Wait the 5 second pause at the end of flashing sequence and            **//
//**    continue like this until you have entered all the digits.              **//
//** If you enter the right code the led on pin 10 will light                  **//
//** In you enter a wrong code, the led on pin 9 will light (you can           **//
//** connected to alarm sirens through relay.                                  **//
//**                                                                           **//
//** For increased security, you cannot insert a new code before 5 minutes     **//
//**                                                                           **//
//**                                                                           **//
//**                                                                           **//
//** Connect a 22K resistor to GND and pin 7 and a button from pin 7 and VCC   **//
//** Connect a  1K resistor with a with a led from pin 11 and GND.             **//
//** Connect a  1K resistor with a with a led from pin 10 and GND.             **//
//** Connect a  1K resistor with a with a led from pin  9 and GND.             **//
//**                                                                           **//
//**                       A Corrado Bevilacqua Programs                       **//
//**                   http://myelectronichome.altervista.org                  **//
//**                                                                           **//
//**                                                                           **//
//**      Suggest a better translation to [email protected]           **//
//** ************************************************************************* **//

//** ********************** ** ****************** **
//** Variabili Modificabili ** Editable variables **
//** ********************** ** ****************** **
int Cor_PeriodoImpostato=1000;                    **  Single flash time
int Cor_indice = 4;                               **  Secret code digits
int Cor_combimpostata[] = {1, 2, 3, 4, 5};        **  Secret Code
int Cor_OKTempoacceso = 800;                      **  Pin 10 activation time on right code
int Cor_NONOKTempoacceso = 3000;                  **  Pin 9 activation time on wrong code for alarm sirens
long Cor_TempoStandby = 300000;                   **  time to wait before trying again

//** ********************** ** ****************** **
//** Altre Variabili        ** Other Variables    **
//** ********************** ** ****************** **
int Cor_CombFatta[] = {0, 0, 0, 0, 0};
int Cor_PrimaVolta;
int Cor_LedAcceso;
int Cor_Conta;
int Cor_Tasto;
int Cor_periodo;
boolean Cor_Pin9;
boolean Cor_Pin10;
double Cor_KeyUltimoTentativo;
double Cor_OldMillis;
double Cor_OkOldMillis;
double Cor_NonOkOldMillis;

void setup()
{
combinazioneSetup();
}

void loop()
{
combinazione();
delay(50);
}

void combinazioneSetup()
{
//** *********************************************** **/
//**    Written by Corrado Bevilacqua 2013 Italy     **/
//** Found on http://myelectronichome.altervista.org **/
//** *********************************************** **/
Cor_PrimaVolta = 0;
Cor_indice = 9;
Cor_KeyUltimoTentativo = 0;

pinMode(11, OUTPUT);   //led lampeggiante
pinMode(10, OUTPUT);   //Led OK
pinMode(9, OUTPUT);    //Led Non OK
pinMode(7, INPUT);

Serial.begin(19200);
Serial.println(“Start- Testpulsanti08_convariabili_modificate”);
Cor_OkOldMillis=-99999;
Cor_NonOkOldMillis=-99999;
Cor_periodo=5000;
}

void combinazione()
{
//** *********************************************** **/
//**    Written by Corrado Bevilacqua 2013 Italy     **/
//** Found on http://myelectronichome.altervista.org **/
//** *********************************************** **/

if (Cor_Pin10==1 && millis() – Cor_OkOldMillis >  Cor_OKTempoacceso )
{
digitalWrite(10, LOW);
Cor_Pin10=0;
}

if (Cor_Pin9==1 && millis() – Cor_NonOkOldMillis >  Cor_NONOKTempoacceso )
{
digitalWrite(9, LOW);
Cor_Pin9=0;
}

if (digitalRead(7) == HIGH && Cor_PrimaVolta == 0)
{
Cor_Tasto = 0;

if (millis() – Cor_KeyUltimoTentativo > Cor_TempoStandby)
{
Cor_indice = 0;
Cor_PrimaVolta = 1;
Cor_Conta = 1;
Cor_OldMillis = millis();
Cor_CombFatta[0] = 0;
Cor_CombFatta[1] = 0;
Cor_CombFatta[2] = 0;
Cor_CombFatta[3] = 0;
Cor_CombFatta[4] = 0;
}
}

if (Cor_indice <= 4)
{
if (digitalRead(7) == HIGH)
{
Cor_Tasto=1;
}

if (millis() – Cor_OldMillis > Cor_periodo)
{
Cor_OldMillis = millis();
//cambia lo stato del led
if (Cor_LedAcceso == 0)
{
digitalWrite(11, HIGH);
Cor_Tasto=0;
Cor_LedAcceso = 1;
Cor_OldMillis = millis();
if (Cor_Conta >= 10)
{
digitalWrite(11, LOW);
Cor_LedAcceso = 0;
Cor_periodo = 5000;
Cor_Conta = 1;
Cor_indice = Cor_indice + 1;
}
else
{
Cor_periodo = Cor_PeriodoImpostato;
}
}
else
{
digitalWrite(11, LOW);
Cor_LedAcceso = 0;
Cor_periodo = Cor_PeriodoImpostato;
if (Cor_Tasto==1)
{
Cor_CombFatta[Cor_indice] = Cor_Conta;
Cor_Tasto = 0;
}
Cor_Conta = Cor_Conta + 1;
}

if (Cor_Conta == 10 && Cor_indice == 4 )
{
Cor_KeyUltimoTentativo = millis();
digitalWrite(11, LOW);
Cor_LedAcceso = 0;
int Cor_Sommali;
Cor_Sommali = 0;
for (int Cor_i=0; Cor_i <= 4; Cor_i++)
{
if (Cor_combimpostata[Cor_i] == Cor_CombFatta[Cor_i])
{
Cor_Sommali = Cor_Sommali + 1;
}
}

if (Cor_Sommali == 5 )
{
Serial.println(“ok”);
digitalWrite(10, HIGH);
Cor_OkOldMillis=millis();
Cor_Pin10=1;
}
else
{
Serial.println(“non ok”);
digitalWrite(9, HIGH);
Cor_NonOkOldMillis=millis();   //tempo di partenza per far rimanere il led acceso
Cor_Pin9=1;
}

Cor_PrimaVolta=0;
}
}
}
}
//** ************************************************************************* **//
//**                                                                           **//
//**                       A Corrado Bevilacqua Programs                       **//
//**                   http://myelectronichome.altervista.org                  **//
//**                                                                           **//
//** ************************************************************************* **//
<<This is a translation from the Italian language. Suggest me a better translation>>