Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; AntiBotCaptcha has a deprecated constructor in /homepages/8/d680172117/htdocs/QA/qa-plugin/q2a-captcha-antibot-master/AntiBotCaptcha.php on line 22
Arduino Keypad lock. With a single switch. Can you help someone or electronoob? - Electronoobs Q&A

6 Online
0 Member And 6 Guest
Today Visits : 705
Yesterday Visits : 2085
All Visits : 6535

Welcome to Electronoobs Q&A, where you can ask questions and receive answers from other members of the community.



Categories


0 votes
I was just wondering if this code would work with one switch and relay with no lcd or buzzer.

/*Test Version: 0.0.1
*/

#include <Keypad.h>

//Variables
int character = 0;
int activated =0;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};

//Pins
int relay1 = 2;
const int switchPin = 5;

//Keypad config
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

//define the symbols on the buttons of the keypad
char hexaKeys[ROWS][COLS] = {
  {'1','4','7','*'},
  {'2','5','8','0'},
  {'3','6','9','#'},
  {'A','B','C','D'}
};

//Keypad Pins
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {9, 8, 7, 6};

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
  pinMode(relay1,INPUT);
 
  //put the lock in the close position first
  digitalWrite(relay1, LOW);
 
}
 
void loop(){
 
///////////////EMERGENCY OPEN/CLOSE (SWITCH)/////////
  if (digitalRead(switchPin))
  {
      digitalWrite(relay1, HIGH);
      activated = 2;
  }

  if (digitalRead(switchPin))
  {
    digitalWrite(relay1, LOW);
    activated = 0;
    character=0;
    Str[6]= '-';
    Str[7]= '*';
    Str[8]= '*';
    Str[9]= '*';
    Str[10]= ' ';    
  }
   
///////////////KEYPAD OPEN/CLOSE////////////
  char customKey = customKeypad.getKey(); //this function reads the pressed key
 
  if (customKey){

    if (character ==0)
    {
    Serial.println(customKey);
    Str[6]= customKey;   
    }
    if (character ==1)
    {
    Serial.println(customKey);
    Str[7]= customKey;    
    }
    if (character ==2)
    {
    Serial.println(customKey);
    Str[8]= customKey;  
    }
    if (character ==3)
    {
    Serial.println(customKey);
    Str[9]= customKey;  
    }
    if (character ==4)
    {
    Serial.println(customKey);
    Str[10]= customKey;
    activated=1;
    }
    character=character+1;
  }

  if (activated == 1)
    {
     
/*Change your password below...
Change each of Str[6], Str[7], Str[8], Str[9]*/

    if(Str[10]='A' && character==5 && Str[6]=='1' && Str[7]=='0' && Str[8]=='3' && Str[9]=='7' )
    {
      digitalWrite(relay1, HIGH);
    }
    else
    {
      character=0;
      Str[1]= '-';
      Str[1]= '*';
      Str[1]= '*';
      Str[1]= '*';
      Str[10]= ' ';
      activated = 0;
    }
  }
  if (activated == 2)
    {
    if(customKey == 'B' )
    {
         
    }
  }
}
asked in Arduino by (150 points)
edited by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...