49 Online
3 Member And 46 Guest
Members present at the site
Today Visits : 14844
Yesterday Visits : 25156
All Visits : 1363801

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



Categories


1 like 0 dislike
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' )
    {
         
    }
  }
}
in Arduino by (150 points)

1 Answer

0 like 0 dislike
It will work but you won't be able to see what you type!
by (34.8k points)
The relay fluctuates when connected to mains and the keypad input is extremely slow. And how do i enable serial print for the keypad on the computer.
...