Introduction
Access control systems are widely used for security purposes in homes, offices, and other buildings. These systems allow only authorized individuals to enter restricted areas. In this project, we will design a door access control system using the 8051 microcontroller and a keypad for input.
Components Required
8051 Microcontroller (e.g., AT89S52)
4x4 Keypad
16x2 LCD Display
Relay Module (to control the door lock)
Buzzer (for incorrect access alert)
Resistors (10kΩ, 1kΩ, 330Ω)
Capacitors (33pF, 100μF)
Crystal Oscillator (11.0592 MHz)
Breadboard and Connecting Wires
Power Supply (5V for the 8051 and components)
Circuit Diagram
The keypad is used to enter a password, which is checked against a predefined code stored in the microcontroller. If the entered password is correct, the relay is activated to unlock the door. The LCD displays status messages, and a buzzer sounds if an incorrect password is entered.
+5V ----- +5V
|
|
Keypad
+---+
| |
| |
| +---------- P1.0 - P1.3 (8051 rows)
| +---------- P1.4 - P1.7 (8051 columns)
| |
GND
LCD Display
VSS to Ground
VCC to +5V
VEE to Potentiometer (for contrast control)
RS to P2.0 (8051)
RW to Ground
E to P2.1 (8051)
D4 to P2.2 (8051)
D5 to P2.3 (8051)
D6 to P2.4 (8051)
D7 to P2.5 (8051)
Relay Module
VCC to +5V
GND to Ground
IN to P3.0 (8051)
NO to one terminal of the door lock
COM to power supply for the lock
Buzzer
Anode to P3.1 (8051) through 330Ω resistor
Cathode to Ground
Pin Connections
Keypad:
Rows connected to P1.0 to P1.3 of the 8051
Columns connected to P1.4 to P1.7 of the 8051
LCD Display:
VSS to Ground
VCC to +5V
VEE to the potentiometer for contrast control
RS to P2.0 of the 8051
RW to Ground
E to P2.1 of the 8051
D4 to P2.2 of the 8051
D5 to P2.3 of the 8051
D6 to P2.4 of the 8051
D7 to P2.5 of the 8051
Relay Module:
VCC to +5V
GND to Ground
IN connected to P3.0 of the 8051
Buzzer:
Anode connected to P3.1 of the 8051 through a 330Ω resistor
Cathode connected to Ground
Software Implementation
The code is written in C using Keil uVision IDE. It involves reading the keypad input, comparing it with a predefined password, and controlling the relay and buzzer based on the input.
#include <reg51.h>
#include <lcd.h> // Include a custom LCD library
#define PASSWORD "1234" // Predefined password
sbit RELAY = P3^0; // Relay control pin
sbit BUZZER = P3^1; // Buzzer control pin
unsigned char keypad[4][4] = {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
unsigned char row, col;
void delay(unsigned int time) {
unsigned int i, j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++);
}
void keypad_init() {
P1 = 0xF0; // Set P1.0-P1.3 as inputs (rows) and P1.4-P1.7 as outputs (columns)
}
char keypad_getkey() {
while(1) {
for(col = 0; col < 4; col++) {
P1 = ~(0x10 << col); // Ground one column at a time
row = P1 & 0x0F; // Read the rows
if (row != 0x0F) {
while(P1 & (0x10 << col)); // Wait for key release
row = P1 & 0x0F;
if(row == 0x0E) return keypad[0][col];
if(row == 0x0D) return keypad[1][col];
if(row == 0x0B) return keypad[2][col];
if(row == 0x07) return keypad[3][col];