03 October, 2018

Password Based Switching


Password Based Switching

  Now a days encryption is necessary to prevent unauthorized activity. In this project we are switching any power load using relay interfaced with arduino board by entering password with keypad.

Components Required :

  •  Arduino UNO
  • Keypad (4 x 4)
  • Relay
  • LCD display (optional)
Keypad is connected to the arduino by jumper wires. The keypad has 8 pins 4 for Columns and 4 for Rows. each pin is connected to any of the Arduino digital pins.

CODE : 

#include <Keypad.h>;
#include <Wire.h>;
int Relay = 7;
#define Password_Lenght 7
char Data[Password_Lenght];
char Master[Password_Lenght] = "123789";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3' ,'A'},
  {'4', '5', '6' ,'B'},
  {'7', '8', '9' ,'C'},
  {'*', '0', '#' ,'D'}
};

byte rowPins[ROWS] = {
  2, 3, 4, 5
};
byte colPins[COLS] = {
  10, 9, 8, 7
};

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()
{
  Serial.begin(9600);
  pinMode(Relay, OUTPUT);
}

void loop()
{
  Serial.println("Enter Password");

  customKey = customKeypad.getKey();
  if (customKey)
  {
    Data[data_count] = customKey;
  }

  if (data_count == Password_Lenght - 1)
  {
    Serial.print("Password is ");

    if (!strcmp(Data, Master))
    {
      Serial.println("acceced");
      delay(1000);
      digitalWrite(Relay, HIGH);
      Serial.println("Relay operated");
    }
    else {
      Serial.println("Denied");
      delay(1000);
      Serial.println("Wrong Password");
      delay(1000);

      clearData();
    }
  }
}

void clearData()
{
  while (data_count != 0)
  {
    Data[data_count--] = 0;
  }
  return;
}

Contact us on Facebook ELECTRICAL HUB

for any help on arduino Coding  WhatsApp  Send Message