Boaz Lawnce
Published © GPL3+

Password-Secured AC Main Console

Arduino Nano-based, password-protected AC Main Console.

IntermediateShowcase (no instructions)2,664
Password-Secured AC Main Console

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Solid State Relay
Solid State Relay
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Circuit Diagram

Arduino - 4x4 Keypad - Relay - AC

Code

Code

C/C++
#include <Keypad.h>
#include <Password.h>

String newPasswordString;
char newPassword[6];

Password password = Password( "0248163264" );

byte maxPasswordLength = 10;
byte currentPasswordLength = 0;
const byte ROWS = 4;
const byte COLS = 4;

boolean Alpha = false;

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

byte rowPins[ROWS] = {6, 7, 8, 9};

byte colPins[COLS] = {2, 3, 4, 5};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  pinMode(11, OUTPUT);
  digitalWrite(11, LOW);
  Serial.begin(9600);

}

void loop()
{
  char key = keypad.getKey();
  if (key != NO_KEY)
  {
    delay(60);
    switch (key)
    {
      case 'A':
        Alpha = false;
        Serial.println("Console goes OFF state");
        break;
      case 'B': break;
      case 'C': break;
      case 'D': break;
      case 'E': checkPassword(); break;
      case 'F': resetPassword(); break;
      default: processNumberKey(key);
    }
    switch (Alpha)
    {
      case true : Motor__ON(); break;
      case false : Motor__OFF(); break;
      default: processNumberKey(key);
    }
  }
}

void processNumberKey(char key) {
  Serial.print(key);
  currentPasswordLength++;
  password.append(key);
  if (currentPasswordLength == maxPasswordLength) {
    checkPassword();
  }
}

void checkPassword() {
  if (password.evaluate()) {
    Serial.println(" OK.");
    Alpha = true;
  } else {
    Serial.println(" Wrong passwowrd!");
    Alpha = false;
  }
  resetPassword();
}

void resetPassword() {
  password.reset();
  currentPasswordLength = 0;
}
void Motor__ON()
{
  digitalWrite(11, HIGH);
}
void Motor__OFF()
{
  digitalWrite(11, LOW);
}

Credits

Boaz Lawnce

Boaz Lawnce

11 projects • 38 followers
Electronics Engineer, Founder, Hobbyist....

Comments