Yogesh Sahu
Published © GPL3+

Password Based LED Control

In this Project We can Control LEDs with Keypad

IntermediateFull instructions provided2,410
Password Based LED Control

Things used in this project

Story

Read more

Schematics

Schematic Diagram

Code

Projects Code

Arduino
#include <Keypad.h>
#include <LiquidCrystal.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 3; //three columns
#define r1 9
#define r2 10
#define r3 11
#define r4 12
int r1s = LOW;
int r2s = LOW;
int r3s = LOW;
int r4s = LOW;
const int rs =A0, en =A1, d4 = A2, d5 =A3, d6 =A4, d7 =A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte pin_rows[ROW_NUM] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

const String password = "1234"; // change your password here
String input_password;
String b1="2345";
String b2="3456";
String b3="4567";
String b4="5678";
String change="0000";

void setup(){
  pinMode(r1,OUTPUT);
  pinMode(r2,OUTPUT);
  pinMode(r3,OUTPUT);
  pinMode(r4,OUTPUT);

 digitalWrite(r1,0);
 digitalWrite(r2,0);
 digitalWrite(r3,0);
 digitalWrite(r4,0);

 lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Password Based Light Controll");
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("Enter Password : ");
  delay(1000);
  lcd.clear();
  Serial.begin(9600);
  input_password.reserve(32); // maximum input characters is 33, change if needed
}

void loop(){
  char key = keypad.getKey();
  lcd.setCursor(0, 0);
  lcd.print(key);
 if (key){
    Serial.println(key);
     
      
    if(key == '*') {
      input_password =""; // clear input password
    } else if(key == '#') {
      if(input_password==b1) {
        r1s =~r1s;
        digitalWrite(r1,r1s);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Bulb 1 :");
        Serial.println("Bulb 1 : ");
        if(r1s==0)
       { lcd.print("ON");
        Serial.println("ON");}
        else 
       { lcd.print("OFF");
        Serial.println("OFF");}
        }
      else if(input_password==b2)
      { r2s =~r2s;
        digitalWrite(r2,r2s);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Bulb 2 :");
        Serial.println("Bulb 2:");
        if(r2s==0)
        {lcd.print("ON");
        Serial.println("ON");}
        else 
        {lcd.print("OFF");
        Serial.println("OFF");} }
      else if(input_password==b3)
      { r3s =~r3s;
        digitalWrite(r3,r3s);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Bulb 3 :");
        Serial.println("Bulb 3:");
        if(r3s==0)
        {lcd.print("ON");
        Serial.println("ON");}
        else{
        lcd.print("ON");
        Serial.println("OFF");}}
      else if(input_password==b4)
      { r4s =~r4s;
        digitalWrite(r4,r4s);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Bulb 4 :");
        Serial.println("Bulb 4:");
        if(r4s==0)
        { lcd.print("ON");
          Serial.println("ON");}
        else {lcd.print("OFF");
        Serial.println("OFF");}}
      else {
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Wrong Password,Try again");
        Serial.println("password is incorrect, try again");
      }

      input_password = ""; // clear input password
    } else { lcd.setCursor(0, 1);
        lcd.print(input_password);
      input_password += key; // append new character to input password string
    }
  }
  
}

Credits

Yogesh Sahu
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.