Cadastrar
Login
Novo texto
Português
English
Português
Cadastrar
Login
Novo Texto
Importar Arquivo
/* Password Door Unlock with Arduino uno Dev: Vasilakis Michalis // Date:24/5/2016 // Ver:1.0 */ //Libraries #include <LiquidCrystal_I2C.h> #include <Keypad.h> /*-------------------------------KEYPAD---------------------------------------*/ const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad char keypressed; char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; //Code that shows the the keypad connections to the arduino terminals byte rowPins[numRows] = {A5,A4,A3,A2};//Rows 0 to 3 byte colPins[numCols] = {13,12,11,10};//Columns 0 to 3 //initializes an instance of the Keypad class Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); /*-------------------------------CONSTANTS------------------------------------*/ LiquidCrystal_I2C lcd(0x27,20,4); //LCD const int buzzer = A1; //Buzzer/small speaker const int lock = 9; //Electric door opener /*-------------------------------VARIABLES------------------------------------*/ String password="2580"; //Variable to store the current password String tempPassword=""; //Variable to store the input password int doublecheck; //Check twice the new passoword boolean armed = false; //Variable for system state (armed:true / unarmed:false) boolean input_pass; //Variable for input password (correct:true / wrong:false) boolean storedPassword = true; boolean changedPassword = false; boolean checkPassword = false; int i = 1; //variable to index an array /*----------------------------------------------------------------------------*/ void setup(){ pinMode(lock,OUTPUT); lcd.begin(16, 2); //Setup the LCD's number of columns and rows //Print welcome message... lcd.setCursor(0,0); lcd.print("Arduino Security"); lcd.setCursor(0,1); lcd.print(" electric door "); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print(" opener system "); lcd.setCursor(0,1); lcd.print(" with password "); delay(2000); lcd.clear(); } void loop() { //Main loop unlockTheDoor(); } /********************************FUNCTIONS*************************************/ void unlockTheDoor(){ lockAgain: //goto label tempPassword=""; lcd.clear(); **6; noTone(buzzer); digitalWrite(lock, LOW); while(!checkPassword){ lcd.setCursor(0,0); lcd.print("Open the door: "); lcd.setCursor(0,1); lcd.print("PASS>"); keypressed = myKeypad.getKey(); //Read pressed keys if (keypressed != NO_KEY){ //Accept only numbers and * from keypad if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' || keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' || keypressed == '8' || keypressed == '9' ){ tempPassword += keypressed; lcd.setCursor(i,1); lcd.print("*"); //Put * on lcd i++; tone(buzzer,800,200); //Button tone } else if (keypressed == 'A'){ changePassword(); goto lockAgain; } else if (keypressed=='#'){ break; } else if (keypressed == '*'){ //Check for password if (password==tempPassword){//If it's correct... lcd.clear(); lcd.setCursor(0,0); lcd.print("Correct password"); lcd.setCursor(0,1); lcd.print("Door is unlocked"); tone(buzzer,100); //Play a tone while door is unlocked digitalWrite(lock, HIGH);//unlock the door for 5 seconds delay(5000); goto lockAgain; } else{ //if it's false, retry tempPassword=""; tone(buzzer,500,200); delay(300); tone(buzzer,500,200); delay(300); goto lockAgain; } } } } } //Change current password void changePassword(){ retry: //label for goto tempPassword=""; lcd.clear(); **1; while(!changedPassword){ //Waiting for current password keypressed = myKeypad.getKey(); //Read pressed keys lcd.setCursor(0,0); lcd.print("CURRENT PASSWORD"); lcd.setCursor(0,1); lcd.print(">"); if (keypressed != NO_KEY){ if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' || keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' || keypressed == '8' || keypressed == '9' ){ tempPassword += keypressed; lcd.setCursor(i,1); lcd.print("*"); i++; tone(buzzer,800,200); } else if (keypressed=='#'){ break; } else if (keypressed == '*'){ **1; if (password==tempPassword){ storedPassword=false; tone(buzzer,500,200); newPassword(); //Password is corrent, so call the newPassword function break; } else{ //Try again tempPassword=""; tone(buzzer,500,200); delay(300); tone(buzzer,500,200); delay(300); goto retry; } } } } } String firstpass; //Setup new password void newPassword(){ tempPassword=""; changedPassword=false; lcd.clear(); **1; while(!storedPassword){ keypressed = myKeypad.getKey(); //Read pressed keys if (doublecheck==0){ lcd.setCursor(0,0); lcd.print("SET NEW PASSWORD"); lcd.setCursor(0,1); lcd.print(">"); } else{ lcd.setCursor(0,0); lcd.print("One more time..."); lcd.setCursor(0,1); lcd.print(">"); } if (keypressed != NO_KEY){ if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' || keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' || keypressed == '8' || keypressed == '9' ){ tempPassword += keypressed; lcd.setCursor(i,1); lcd.print("*"); i++; tone(buzzer,800,200); } else if (keypressed=='#'){ break; } else if (keypressed == '*'){ if (doublecheck == 0){ firstpass=tempPassword; doublecheck=1; newPassword(); } if (doublecheck==1){ doublecheck=0; if (firstpass==tempPassword){ **1; firstpass=""; password = tempPassword; // New password saved tempPassword="";//erase temp password lcd.setCursor(0,0); lcd.print("PASSWORD CHANGED"); lcd.setCursor(0,1); lcd.print("----------------"); storedPassword=true; tone(buzzer,500,400); delay(2000); lcd.clear(); break; } else{ firstpass=""; newPassword(); } } } } } }
Configurações do Texto
Título do Texto :
[Opcional]
Guardar na Pasta :
[Opcional]
Selecionar
Syntax Highlighting :
[Opcional]
Selecionar
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiração do Texto :
[Opcional]
Nunca
Auto Destruir
10 Minutos
1 Hora
1 Dia
1 Semana
2 Semanas
1 Mês
6 Meses
1 Ano
Status do Texto :
[Opcional]
Público
Não Listado
Privado (somente membros)
Senha :
[Opcional]
Descrição:
[Opcional]
Tags:
[Opcional]
Criptografar Texto
(
?
)
Criar Novo Texto
No momento você não está logado, isso significa que você não pode editar ou excluir nada que você poste.
Cadastre-se
ou faça o
Login
Idiomas do site
×
English
Português
Você gosta de cookies?
🍪 Usamos cookies para garantir que você obtenha a melhor experiência em nosso site.
Saber mais
Concordo