Introduction: Intro: Password & Lock

About: Biomedical Engineer. I am passionate about the science of Biomechatronics and Bioelectronics which transform Science FIction into Reality.

This project is a simple security system: Password System.with 4 digits.

It is consist of 3 LEDs that reflect the state security:

RED LED: Closed.

GREEN LED: Open.

Yello LED: Key press LED.

Default Password is 1234 with the ability to reset the it.

Once you entered the old password you can press " * " to start the " Reset Process"

Step 1: Components

In This Project You will NEED:

  • LED *3
    RED, GREEN, YELLOW
  • Resistors*3
    220 Ohm
  • 9V Battery
  • 7805: 5V Regulator
  • 4*4 Keypad
    3*4 Keypad may work also
  • ATmega8: PDIP

Step 2: Circuit Diagram

The following Images shows How to connect the circuit:

  • Schematic Diagram
    Designed by Proteus 8 Professional

  • PCB Diagram
    Designed by Fritzing

Step 3: Code Algorithm

The Code:
The code works as the following:

You have two ways to design your code

  • Sending 1s to the rows, and check if the columns are 1 or 0

Or

  • Sending 1s to the columns, and check if the rows are 1 or 0

When there is 1 in the row and the column that means the key is pressed.

Saving the 4 Keys into 4 Variables

then checking whether the password is true or not.

  • if True: Green LED on
  • if False: Red LED Blink

To change Password:

  • Enter the Old Password: Default is 1234
  • Press " * "
  • Enter New 4 digits Password
  • Taa Daa, Password Has Changed

Step 4: Code

#include <mega8.h>
#include <delay.h>

char KeyCheck();
char K0,K1,K2,K3,K;
char P0 = '1',P1 = '2',P2 = '3',P3='4';
char Key; int i; void main(void) {
PORTB=0xff;
DDRB=0x00;
PORTC=0x00;
DDRC=0x7F;
PORTD=0x00;
DDRD=0xff;
while (1)
      {
     
PORTD = 0x20; 
K0 = KeyCheck();
PORTD = 0x60;
delay_ms(500);PORTD = 0x20;
K1 = KeyCheck();
PORTD = 0x60;
delay_ms(500);
PORTD = 0x20;
K2 = KeyCheck();
PORTD = 0x60;delay_ms(500);
PORTD = 0x20;
K3 = KeyCheck();
PORTD = 0x60;delay_ms(500);
PORTD = 0x20;
if (K0 ==P0 && K1 ==P1 && K2 ==P2 && K3 ==P3)
{
PORTD = 0x80;
K = KeyCheck();
delay_ms(20);
if (K == '*')
{
K='0';
PORTD = 0xC0;delay_ms(500);
PORTD = 0x80;
P0 = KeyCheck();
PORTD = 0xC0;
delay_ms(500);
PORTD = 0x80;
P1 = KeyCheck();
PORTD = 0xC0;
delay_ms(500);
PORTD = 0x80;
P2 = KeyCheck();
PORTD = 0xC0;
delay_ms(500);
PORTD = 0x80;
P3 = KeyCheck();
PORTD = 0xC0;
delay_ms(500);
PORTD = 0x80;
}
}
else
{
for (i =0;i<3;i++)
{
PORTD = 0x20;
delay_ms(300);
PORTD = 0x00;
delay_ms(300);
} } } }
char KeyCheck()
{
    
Key='X';
while (Key == 'X')
{
PORTC = 0b11011111;
if(PINB == 0b11111101)
Key = '1';
if(PINB == 0b11111011)
Key = '2';
if(PINB == 0b11110111)
Key = '3';
PORTC = 0b11101111;
if(PINB == 0b11111101)
Key = '4';
if(PINB == 0b11111011)
Key = '5';
if(PINB == 0b11110111)
Key = '6';
PORTC = 0b11110111;
if(PINB == 0b11111101)
Key = '7';
if(PINB == 0b11111011)
Key = '8';
if(PINB == 0b11110111)
Key = '9';
PORTC = 0b11111011;
if(PINB == 0b11111101)
Key = '*';
if(PINB == 0b11111011)
Key = '0';
if(PINB == 0b11110111)
Key = '#';
}

return Key;
}

Step 5: Burn the Code on the CHIP

Connecting Arduino Uno To the chip as Image:

ATmega8 pins are:
MISO,MOSI,SCK,REST,VCC,GND

Making Arduino Work as a programmer

burning the code using AVRDUDE

Step 6: We Are Done

That was a very simple project using ATmega8

I hope it works with you

Thank you.

Nibras Abo Alzahab

Contact ME

E-mail: Nibras.Abo.Alzahab@gmail.com

Facebook: Nibras Abo Alzahab

LinkedIn: Nibras Abo Alzahab

Wordpress: Nibras Abo Alzahab

YouTube: Nibras Abo Alzahab