Se afișează postările cu eticheta tastatura. Afișați toate postările
Se afișează postările cu eticheta tastatura. Afișați toate postările

vineri, 2 septembrie 2016

Sistem deblocare usa cu cod din exterior si buton fara retinere din interior

   Pentru o incinta (garaj, intrare in casa, bloc, etc) se poate monta un sistem de acces conditionat de introducerea unui cod de la o tastatura locala la exterior si un buton la interior.
   Yala sau usa se pot debloca fie cu un electromagnet care va fi atras timp de 5 secunde sau de un actuator de masina, care va primi impuls de 0,7 secunde pentru deschidere si dupa 5 secunde un impuls pentru inchidere de 0,7 secunde.
   Montajul de test are o placa Arduino Mega (merge la fel si cu Uno, Nano, etc), o tastatura cu 12 taste si 4 leduri fiecare cu rezistente de limitare curent de 330 ohmi.
   Schema mea de test este:
   Incarcand sketch-ul acces_code_keypad_1.ino am urmatoarele indicatii:
- in repaus, toate ledurile stinse
- daca se apasa butonul se aprinde pentru timp scurt led-ul galben (deschidere actuator), apoi se aprinde ledul alb 5 secunde (electromagnet atras), se aprinde ledul verde (inchidere actuator)
- daca se introduce un cod incorect de la tastatura se aprinde o secunda ledul rosu indicand o eroare
- daca se introduce corect codul, adica *123#se aprinde pentru timp scurt led-ul galben (deschidere actuator), apoi se aprinde ledul alb 5 secunde (electromagnet atras), se aprinde ledul verde (inchidere actuator)

   Pentru a conecta un electromagnet, schema devine:
iar pentru un actuator 
   Tommy a realizat un montaj de test pentru actuator in care a folosit o placa compatibila Arduino Nano achizitionata de la Ardushop.ro folosind cuponul de reducere de 5% al cititorilor paginilor mele, Z4A413ZN:


   Dupa discutii cu el, am modificat sketch-ul care devine acces_code_keypad_2.ino, led-ul rosu este aprins permanent cand sistemul este in asteptare.
   Am facut un filmulet cu versiunea a 2-a a sletch-ului, deblocare usa cu cod din exterior si buton fara retinere din interior (3)
   Tommy s-a pus pe treaba si a proiectat un cablaj pentru versiune definitiva, cu ajutorul programului Eagle PCB software
realizand cablajul propriu-zis prin metoda expunerii la ultraviolete:
si apoi a montat piesele pentru versiunea cu actuator:
facand si un filmulet pentru mine, deblocare usa cu cod din exterior si buton fara retinere din interior (4)

marți, 31 mai 2016

Sistem de alarma (2)


   Fata de sistemul de alarma prezentat in articolul precedent, in care activarea si dezactivarea alarmei se facea cu un comutator, acum am conectat o tastatura cu 12 butoane:
   Sistemul de alarma functioneaza astfel, dupa incarcarea sketch-ului alarm_system_2a.ino:
- la pornire sistemul este dezactivat, confirmat prin aprinderea led-ului albastru;
- daca se tasteaza codul corect (1234* sau mai bine #1234* pentru a elimia posibilitatea erorilor din cauza unor apasari anteriorare, deoarece tasta # asta face), led-ul albastru se stinge si incepe sa clipeasca led-ul verde timp de 20 secunte, indicand ca alarma se pregateste de armare;
- dupa trecerea timpului de pregatire, se intra in modul activ de supraveghere, indicat de aprinderea continua a led-ului verde;
- daca se detecteaza o miscare, led-ul verde se stinge si se aprinde intermitent led-ul rosu, timp de 10 secunde, timp pentru a putea dezactiva alarma
- daca a trecut timpul si alarma nu a fost dezactivata, ledu-ul rosu se aprinde permanent indicand activarea avertizarii sonore (eu am doar led-ul de pe placa Arduino)
- daca nu se intervine nici acum pentru dezactivare alarma, sistemul trece in supraveghere si daca este iar miscare, asteapta 10 secunde si apoi se declanseaza avertizorul sonor tot 10 secunde.
- alarma se poate dezactiva in orice moment prin intorducerea codului.
   Am facut niste filmulete in care se vede mai bine modul de functionare:

vineri, 22 noiembrie 2013

Arduino, un servomotor si o tastatura cu 12 butoane

   In prezentul articol o sa prezint un modul de acces cu parola, cu inchidere manuala sau temporizata, in care elementul de executie e un servomotor.
   Acest articol se bazeaza pe informatiile, schemele si programioarele (sketch-urile) din articolele anterioare:
Arduino si o tastatura cu 12 butoane
Arduino si o tastatura cu 12 butoane (II)
Arduino si un servomotor
   In prima faza am conectat tastatura, afisajul si servomotorul:
schema de conectare fiind:
   Am realizat 2 filmulete:
Arduino - door lock with code - ver.4.0cu timp de acces nelimitat, inchidere prin apasarea tastei '#':
- Arduino - door lock with code - ver.4.1, cu timp de acces limitat la 5 secunde:
   Sketch-ul pentru prima versiune este:
// original schematic and schetch from http://www.arduinoevilgenius.com/
// adapted schematic by niq_ro ( http://www.tehnic.go.ro/ )
// sketch door lock ver.4.0 (19.11.2013) use sketch door lock ver.2.0 (02.03.2013)
// http://nicuflorica.blogspot.com
#include <Keypad.h>
#include <EEPROM.h>
char* secretCode = "2255";
int position = 0;
int position2 = 0;
boolean locked = true;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {2, 7, 6, 4};
byte colPins[cols] = {3, 1, 5};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int redPin = 11;
int greenPin = 9;
int bluePin = 10;
int solenoidPin = 13;

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

/*
---------------------
| Arduino | LCD1602 |
---------------------
| D14(A0) |    RS   |
---------------------
| D15(A1) |    E    |
---------------------
| D16(A2) |    D4   |
---------------------
| D14(A3) |    D5   |
---------------------
| D14(A4) |    D6   |
---------------------
| D14(A5) |    D7   |
---------------------

*/

#include <Servo.h>
Servo servoMain; // Define our Servo


void setup()
{
/*pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
*/
//pinMode(9, OUTPUT);
servoMain.attach(9); // servo on digital pin 9
//servoMain.write(0);   // Turn Servo Left to 0 degrees
lcd.begin(16, 2);
// print my logo
lcd.setCursor(0, 0);
lcd.print("www.tehnic.go.ro");
lcd.setCursor(0, 1);
lcd.print("   by niq_ro");
delay(5000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("acces permis la");
lcd.setCursor(2, 1);
lcd.print("introducere");
delay(1000);
lcd.clear();

lcd.setCursor(2, 0);
lcd.print("parola corecta");
lcd.setCursor(2, 1);
lcd.print("versiune 4 .0");
delay(1000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("apasa tasta '#'");
lcd.setCursor(0, 1);
lcd.print("pentru stergere");
delay(5000);
lcd.clear();


//eraseCode(); // a first test for initial code at "2255";
delay(1000);
loadCode(); // load the code from EEPROM

flash();
updateOutputs();

// print a new message
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("introdu parola");
lcd.setCursor(0, 1);

}
void loop()
{

//servoMain.write(0);   // Turn Servo Left to 0 degrees
char key = keypad.getKey();
if (key)
{
position2 ++;
//digitalWrite(bluePin, HIGH);
delay(30);
//digitalWrite(bluePin, LOW);
lcd.print("?");
}
if (key == '*' && ! locked)
{
// unlocked and * pressed so change code
position = 0;
position2 = 0;
getNewCode();
updateOutputs();
}
if (key == '#')
{
locked = true;
position = 0;
position2= 0;
updateOutputs();
//digitalWrite(bluePin, HIGH);
//delay(300);
//digitalWrite(bluePin, LOW);

lcd.clear();
lcd.setCursor(1, 0);
lcd.print("yala incuiata");
lcd.setCursor(0, 1);
delay(1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("introdu parola");
lcd.setCursor(0, 1);

//lcd.clear();

}
if (key == secretCode[position])
{
position ++;
}
if (position == 4 & position2 == 4)
{
locked = false;
//digitalWrite(bluePin, HIGH);
delay(300);
//digitalWrite(bluePin, LOW);
updateOutputs();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola corecta..");
lcd.setCursor(2, 1);
lcd.print("acces permis");
}
delay(100);

}

void updateOutputs()
{
if (locked)
{
//digitalWrite(redPin, HIGH);
//digitalWrite(greenPin, LOW);
digitalWrite(solenoidPin, HIGH);
servoMain.write(90);  // Turn Servo back to center position (90 degrees)
}
else
{
//digitalWrite(redPin, LOW);
//digitalWrite(greenPin, HIGH);
digitalWrite(solenoidPin, LOW);
servoMain.write(0);   // Turn Servo Left to 0 degrees
}
}

void getNewCode()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola noua este");
lcd.setCursor(6, 1);
lcd.print("");

flash();
for (int i = 0; i < 4; i++ )
{
char key;
key = keypad.getKey();
while (key == 0)
{
key = keypad.getKey();
}
flash();
secretCode[i] = key;
lcd.print(key);
}
saveCode();
flash();flash();

}


void loadCode()
{
if (EEPROM.read(0) == 7)
{
secretCode[0] = EEPROM.read(1);
secretCode[1] = EEPROM.read(2);
secretCode[2] = EEPROM.read(3);
secretCode[3] = EEPROM.read(4);
}
}

void saveCode()
{
EEPROM.write(1, secretCode[0]);
EEPROM.write(2, secretCode[1]);
EEPROM.write(3, secretCode[2]);
EEPROM.write(4, secretCode[3]);
EEPROM.write(0, 7);
}


void eraseCode() // code is "2255"
{
EEPROM.write(1, 2);
EEPROM.write(2, 2);
EEPROM.write(3, 5);
EEPROM.write(4, 5);
EEPROM.write(0, 2);
}


void flash()
{
/*digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
delay(100);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
*/
delay(100);
}
    Sketch-ul pentru a 2-a versiune este:
// original schematic and schetch from http://www.arduinoevilgenius.com/
// adapted schematic by niq_ro ( http://www.tehnic.go.ro/ )
// sketch door lock ver.4.1 (19.11.2013) use sketch door lock ver.2.0 (02.03.2013)
// http://nicuflorica.blogspot.com
#include <Keypad.h>
#include <EEPROM.h>
char* secretCode = "2255";
int position = 0;
int position2 = 0;
boolean locked = true;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {2, 7, 6, 4};
byte colPins[cols] = {3, 1, 5};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
/*
int redPin = 11;
int greenPin = 9;
int bluePin = 10;
*/
int solenoidPin = 13;

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

/*
---------------------
| Arduino | LCD1602 |
---------------------
| D14(A0) |    RS   |
---------------------
| D15(A1) |    E    |
---------------------
| D16(A2) |    D4   |
---------------------
| D14(A3) |    D5   |
---------------------
| D14(A4) |    D6   |
---------------------
| D14(A5) |    D7   |
---------------------
*/


#include <Servo.h>
Servo servoMain; // Define our Servo


void setup()
{
  /*
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
*/
pinMode(solenoidPin, OUTPUT);
servoMain.attach(9); // servo on digital pin 9

lcd.begin(16, 2);
// print my logo
lcd.setCursor(0, 0);
lcd.print("www.tehnic.go.ro");
lcd.setCursor(0, 1);
lcd.print("   by niq_ro");
delay(5000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("acces permis la");
lcd.setCursor(2, 1);
lcd.print("introducere");
delay(1000);
lcd.clear();

lcd.setCursor(1, 0);
lcd.print("parola corecta");
lcd.setCursor(2, 1);
lcd.print("versiune 4.1");
delay(1000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("apasa tasta '#'");
lcd.setCursor(0, 1);
lcd.print("pentru stergere");
delay(2000);
lcd.clear();



//eraseCode(); // a first test for initial code at "2255";
delay(1000);
loadCode(); // load the code from EEPROM

flash();
updateOutputs();
afisaj();

}
void loop()
{
/*
 servoMain.write(0);   // Turn Servo Left (to 0 degrees)
 delay(500);          // Wait 1 second  
*/

char key = keypad.getKey();
if (key)
{
position2 ++;
// digitalWrite(bluePin, HIGH);
delay(30);
// digitalWrite(bluePin, LOW);
lcd.print("?");
}


if (key == '*' && ! locked)
{
// unlocked and * pressed so change code
position = 0;
position2 = 0;
getNewCode();
updateOutputs();
afisaj();
}
// if (key == '#' && ! locked)   // manual locked when push '#'
if (key == '#' )   // manual locked when push '#'
{
locked = true;
position = 0;
position2= 0;
updateOutputs();
// digitalWrite(bluePin, HIGH);
//delay(300);
// digitalWrite(bluePin, LOW);
afisaj();
}

if (key == secretCode[position])
{
position ++;
}
if (position == 4 & position2 == 4)
{
locked = false;
// digitalWrite(bluePin, HIGH);
delay(300);
// digitalWrite(bluePin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola corecta..");
lcd.setCursor(0, 1);
lcd.print("acces permis 5s");
updateOutputs();
afisaj();
}
}


void updateOutputs()
{
if (locked)
{
//digitalWrite(redPin, HIGH);
//digitalWrite(greenPin, LOW);
digitalWrite(solenoidPin, LOW);
servoMain.write(90);  // Turn Servo back to center position (90 degrees)
}
else
{
//digitalWrite(redPin, LOW);
//digitalWrite(greenPin, HIGH);
digitalWrite(solenoidPin, HIGH);
servoMain.write(0);  // Turn Servo back to left position (0 degrees)

delay (50);
for (int i=0; i <= 100; i++)
{
char key;
key = keypad.getKey();
if (key == '*')
{
// unlocked and * pressed so change code
position = 0;
position2 = 0;
getNewCode();
updateOutputs();
}
delay (50);
}
//digitalWrite(redPin, HIGH);
//digitalWrite(greenPin, LOW);
digitalWrite(solenoidPin, LOW);
servoMain.write(90);  // Turn Servo back to center position (90 degrees)
locked = true;
position = 0;
position2= 0;
}
}


void getNewCode()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola noua este");
lcd.setCursor(6, 1);
lcd.print("");

flash();
for (int i = 0; i < 4; i++ )
{
char key;
key = keypad.getKey();
while (key == 0)
{
key = keypad.getKey();
}
flash();
secretCode[i] = key;
lcd.print(key);
}
saveCode();
flash();flash();
//delay(400);
//afisaj();
}


void loadCode()
{
if (EEPROM.read(0) == 7)
{
secretCode[0] = EEPROM.read(1);
secretCode[1] = EEPROM.read(2);
secretCode[2] = EEPROM.read(3);
secretCode[3] = EEPROM.read(4);
}
}

void saveCode()
{
EEPROM.write(1, secretCode[0]);
EEPROM.write(2, secretCode[1]);
EEPROM.write(3, secretCode[2]);
EEPROM.write(4, secretCode[3]);
EEPROM.write(0, 7);
}


void eraseCode() // code is "2255"
{
EEPROM.write(1, 2);
EEPROM.write(2, 2);
EEPROM.write(3, 5);
EEPROM.write(4, 5);
EEPROM.write(0, 2);
}


void flash()
{
//digitalWrite(redPin, HIGH);
//digitalWrite(greenPin, LOW);
delay(100);
//digitalWrite(redPin, LOW);
//digitalWrite(greenPin, HIGH);
delay(100);
}

void afisaj()
{
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("yala incuiata");
lcd.setCursor(0, 1);
delay(500);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("introdu parola");
lcd.setCursor(0, 1);
}

   Ulterior am conectat si LED-ul multicolor, care imi indica starea (rosu la inchis, verde la deschis si albastru la apasare tasta):
 
   Am facut un filmulet, numit Arduino - door lock with code - ver.4.2
iar sketch-ul pentru aceasta varianta este:
// original schematic and schetch from http://www.arduinoevilgenius.com/
// adapted schematic by niq_ro ( http://www.tehnic.go.ro/ )
// sketch door lock ver.4.2 (20.11.2013) use sketch door lock ver.2.0 (02.03.2013)
// http://nicuflorica.blogspot.com

#include <Keypad.h>
#include <EEPROM.h>
char* secretCode = "2255";
int position = 0;
int position2 = 0;
boolean locked = true;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {2, 7, 6, 4};
byte colPins[cols] = {3, 1, 5};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

int solenoidPin = 13;
int redPin = 12;
int bluePin = 11;
int greenPin = 10;
int servoPin = 9;

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

/*
---------------------
| Arduino | LCD1602 |
---------------------
| D14(A0) |    RS   |
---------------------
| D15(A1) |    E    |
---------------------
| D16(A2) |    D4   |
---------------------
| D14(A3) |    D5   |
---------------------
| D14(A4) |    D6   |
---------------------
| D14(A5) |    D7   |
---------------------
*/


#include <Servo.h>
Servo servoMain; // Define our Servo


void setup()
{

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(solenoidPin, OUTPUT);
servoMain.attach(servoPin); 

lcd.begin(16, 2);
// print my logo
lcd.setCursor(0, 0);
lcd.print("www.tehnic.go.ro");
lcd.setCursor(0, 1);
lcd.print("   by niq_ro");
delay(5000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("acces permis la");
lcd.setCursor(2, 1);
lcd.print("introducere");
delay(1000);
lcd.clear();

lcd.setCursor(1, 0);
lcd.print("parola corecta");
lcd.setCursor(2, 1);
lcd.print("versiune 4.2");
delay(1000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("apasa tasta '#'");
lcd.setCursor(0, 1);
lcd.print("pentru stergere");
delay(2000);
lcd.clear();



//eraseCode(); // a first test for initial code at "2255";
delay(1000);
loadCode(); // load the code from EEPROM

flash();
updateOutputs();
afisaj();

}
void loop()
{

char key = keypad.getKey();
if (key)
{
position2 ++;
digitalWrite(bluePin, HIGH);
delay(30);
digitalWrite(bluePin, LOW);
lcd.print("?");
}


if (key == '*' && ! locked)
{
// unlocked and * pressed so change code
position = 0;
position2 = 0;
getNewCode();
updateOutputs();
afisaj();
}
// if (key == '#' && ! locked)   // manual locked when push '#'
if (key == '#' )   // manual locked when push '#'
{
locked = true;
position = 0;
position2= 0;
updateOutputs();
digitalWrite(bluePin, HIGH);
delay(300);
digitalWrite(bluePin, LOW);
afisaj();
}

if (key == secretCode[position])
{
position ++;
}
if (position == 4 & position2 == 4)
{
locked = false;
digitalWrite(bluePin, HIGH);
delay(300);
digitalWrite(bluePin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola corecta..");
lcd.setCursor(0, 1);
lcd.print("acces permis 5s");
updateOutputs();
afisaj();
}
}


void updateOutputs()
{
if (locked)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(solenoidPin, LOW);
servoMain.write(90);  // Turn Servo back to center position (90 degrees)
}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(solenoidPin, HIGH);
servoMain.write(0);  // Turn Servo back to left position (0 degrees)

delay (50);
for (int i=0; i <= 100; i++)
{
char key;
key = keypad.getKey();
if (key == '*')
{
// unlocked and * pressed so change code
position = 0;
position2 = 0;
getNewCode();
updateOutputs();
}
delay (50);
}
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(solenoidPin, LOW);
servoMain.write(90);  // Turn Servo back to center position (90 degrees)
locked = true;
position = 0;
position2= 0;
}
}


void getNewCode()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("parola noua este");
lcd.setCursor(6, 1);
lcd.print("");

flash();
for (int i = 0; i < 4; i++ )
{
char key;
key = keypad.getKey();
while (key == 0)
{
key = keypad.getKey();
}
flash();
secretCode[i] = key;
lcd.print(key);
}
saveCode();
flash();flash();
//delay(400);
//afisaj();
}


void loadCode()
{
if (EEPROM.read(0) == 7)
{
secretCode[0] = EEPROM.read(1);
secretCode[1] = EEPROM.read(2);
secretCode[2] = EEPROM.read(3);
secretCode[3] = EEPROM.read(4);
}
}

void saveCode()
{
EEPROM.write(1, secretCode[0]);
EEPROM.write(2, secretCode[1]);
EEPROM.write(3, secretCode[2]);
EEPROM.write(4, secretCode[3]);
EEPROM.write(0, 7);
}


void eraseCode() // code is "2255"
{
EEPROM.write(1, 2);
EEPROM.write(2, 2);
EEPROM.write(3, 5);
EEPROM.write(4, 5);
EEPROM.write(0, 2);
}


void flash()
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
delay(100);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
delay(100);
}

void afisaj()
{
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("yala incuiata");
lcd.setCursor(0, 1);
delay(500);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("introdu parola");
lcd.setCursor(0, 1);
}