0% found this document useful (0 votes)
19 views17 pages

Pogress 4 Cea - msd-s24

Uploaded by

nimra.batalvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views17 pages

Pogress 4 Cea - msd-s24

Uploaded by

nimra.batalvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Progress 4

Complex Engineering Activity


Mechatronics System Design

Remote Control Lock

Group Members
1 Ali Hassan 211278
2 Mati Ur Rehman 201128
3 Nimra Shahzad 20118

Department of Mechatronics Engineering


Air University
Abstract
The remote control lock system integrates a keypad, Arduino microcontroller, LED screen, and servo
motor to enhance security and convenience. Users input a code via the keypad for authentication, which
is processed by the Arduino microcontroller. The microcontroller precisely manage the locking
mechanism, ensuring efficient and accurate locking/unlocking actions. Additionally, an LED screen
provides visual feedback, displaying system status and authentication results. This integrated system
offers a versatile solution for remote access control in various settings, providing improved security,
flexibility, and user experience compared to traditional key-based systems.
Contents
Objectives ..................................................................................................................................................... 4
The Project .................................................................................................................................................... 4
Simulink model ............................................................................................................................................. 4
Circuit diagrams ........................................................................................................................................ 5
Mechanical part/plant .............................................................................................................................. 5
Software .................................................................................................................................................... 6
Hardware in Loop...................................................................................................................................... 6
Operation of Project ................................................................................................................................. 7
Results ........................................................................................................................................................... 7
Part List / Cost ............................................................................................................................................... 7
Conclusion ..................................................................................................................................................... 7
Appendix ....................................................................................................................................................... 8
Code in IDE with mega2560 ...................................................................................................................... 8
Objectives
• To develop a Lock with keypad system.
• Use Servo Motor to Control the Locking Mechanism..

The Project
The door lock project utilizing Arduino, a keypad, LCD screen, and servo with no feedback system
involves constructing a system where users input a password via the keypad to unlock a door. The
Arduino functions as the main controller, managing keypad input, processing the password, and
controlling the servo motor to lock or unlock the door. The keypad provides the interface for password
entry, while the LCD screen displays messages to the user, such as prompts for password input and
notifications of successful or failed attempts. The servo motor physically operates the door lock
mechanism. When a user enters the correct password, the Arduino triggers the servo to unlock the door
and displays a success message on the LCD. If the password is incorrect, the Arduino displays a failure
message, and the door remains locked. Overall, this project integrates keypad input, LCD output, and
servo motor control to create a secure door locking system operated by a password.

Simulink model
The Transfer function for the servo motor we are using are as follows
Hardware
Circuit diagrams

Mechanical part/plant
The lock consists of a mechanical lock attached with the servo motors which is responsible for the
opening and closing of door. The keypad is placed outside the door for the user to enter the password .
Software
The logic is developed in MATALB GUI which is responsible for the functioning of the door lock. The user
enter the password through the keypad then the check button is responsible for the comparing of
password and a motor is connected pin 8 of Arduino which moves the lock.

Hardware in Loop
The door lock is connected with laptop through Arduino.
Operation of Project
Firstly the user enters enter the password through keypad then this code is compare to the code saved if
the project is correct the servo rotates through which mechanical lock is attached if the password is
incorrect the door remains locked and the user has to wait for 10seconds to try again.

Results
The door lock works smoothly with Arduino IDE but have some issues while running with MATLAB GUI.

Part List / Cost


See Table 1 for material specifications.
Table 1: Material and their specification

items Qty Specifications Cost


Plant
1 wooden base 1 Base 10cmx10cm Scrap
2 Mechanical Lock 1 Lock 200
3 Keypad 1 4x4 keypad 200
4 Arduino Mega 1 Microcontroller 4000
5 LCD 1 Display 450
Actuation 200
6 Servo Motor 1 Micro Servo
7 Miscellaneous Jumper wires, scotch tape 250
5300

Conclusion
Keypad locks offer a secure and convenient way to control access to your home or office. They eliminate
the need for physical keys and provide programmable codes for multiple users. In contrast to remote
control locks, keypad locks are more resistant to hacking and signal interference, making them a good
choice for security-conscious users.
Appendix
Code in IDE with mega2560
#include <Keypad.h> // the library for the 4x4 keypad
#include <LiquidCrystal_I2C.h> // the library for the i2c 1602 lcd
#include <Servo.h> // the library to control the servo motor
LiquidCrystal_I2C lcd(0x27,20,4); // gets the lcd
Servo servo;

#define Password_Length 8 // the length of the password, if the password is 4 digits long set this to 5
int Position = 0; // position of the servo
char Particular[Password_Length]; // the password length
char Specific[Password_Length] = "137926A"; // the password which is called specific in the code, change this to anything you
want with the numbers 0-9 an dthe letters A-D
byte Particular_Count = 0, Specific_Count = 0; // counts the amount of digits and and checks to see if the password is correct
char Key;
const byte ROWS = 4; // the amount of rows on the keypad
const byte COLS = 4; // the amount of columns on the keypad
char keys[ROWS][COLS] = { // sets the rowns and columns
// sets the keypad digits
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
bool SmartDoor = true; // the servo
// the pins to plug the keypad into
byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2, 1};
Keypad myKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); // gets the data from the keypad

// locked charcater
byte Locked[8] = {
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11011,
B11111
};
// open character
byte Opened[8] = {
B01110,
B00001,
B00001,
B11111,
B11011,
B11011,
B11011,
B11111
};
void setup()
{
servo.attach(0); // attaches the servo to pin 0
ServoClose(); // closes the servo when you say this function
lcd.init(); // initializes the lcd
lcd.backlight(); // turns on the backlight
lcd.setCursor(0,0); // sets the cursor on the lcd
lcd.setCursor(0,1); // sets the cursor on the lcd
lcd.print("DoorLock Project"); // prints text
delay(4000); // waits 4 seconds
lcd.clear(); // clears the lcd diplay

void loop()
{
if (SmartDoor == 0) // opens the smart door
{
Key = myKeypad.getKey(); // the word key = myKeypad which gets the value

if (Key == '#') // when the '#' key is pressed

{
lcd.clear(); // clears the lcd diplay
ServoClose(); // closes the servo motor
lcd.setCursor(2,0); // sets the cursor on the lcd
lcd.print("Door Closed"); // prints the text to the lcd
lcd.createChar(0, Locked); // prints the locked character
lcd.setCursor(14,0); // sets the cursor on the lcd
lcd.write(0); // prints the first character when you are on the door closed page
delay(3000); // waits 3 seconds
SmartDoor = 1; // closes the door
}
}

else Open(); // keeps the door open


}

void clearData() // clears the data


{
while (Particular_Count != 0) // counts the digits pressed
{
Particular[Particular_Count--] = 0; // counts how many digits
}
return; // returns the data
}

void ServoOpen() // opens the servo


{
for (Position = 180; Position >= 0; Position -= 5) { // moves from 0 to 180 degrees
servo.write(Position); // moves to the postion
delay(15); // waits 15 milliseconds
}
}
void ServoClose() // closes the servo
{
for (Position = 0; Position <= 180; Position += 5) { // moves from position 0 to 180 degrees
servo.write(Position); // moves to the position
delay(15); // waits 15 milliseconds
}
}

void Open() // function declarations


{
lcd.setCursor(1,0); // sets the cursor on the lcd
lcd.print("Enter Password"); // prints the text

Key = myKeypad.getKey(); // gets the keys you press from the keypad
if (Key)
{
Particular[Particular_Count] = Key;
lcd.setCursor(Particular_Count, 1); // sets the cursor on the lcd
lcd.print("*"); // prints '*' instead of the password
Particular_Count++; // counts the length of the password
}

if (Particular_Count == Password_Length - 1) // gets the length of the password


{
if (!strcmp(Particular, Specific)) // counts the length and checks to see if the password is correct
{
lcd.clear();
ServoOpen(); // moves the servo 180 degrees
lcd.setCursor(2,0); // sets the cursor on the lcd
lcd.print("Door Opened");
lcd.createChar(1, Opened);
lcd.setCursor(14,0); // sets the cursor on the lcd
lcd.write(1);
lcd.setCursor(0,1); // sets the cursor on the lcd
lcd.print("Press # to Close");
SmartDoor = 0;
}
else {
lcd.clear();
lcd.setCursor(0,0); // sets the cursor on the lcd
lcd.print("Wrong Password"); // prints the text/character
lcd.setCursor(0,1);
lcd.print("Try Again In");
lcd.setCursor(13,1);
lcd.print("10");
delay(1000);
lcd.setCursor(13,1);
lcd.print("09");
delay(1000);
lcd.setCursor(13,1);
lcd.print("08");
delay(1000);
lcd.setCursor(13,1);
lcd.print("07");
delay(1000);
lcd.setCursor(13,1);
lcd.print("06");
delay(1000);
lcd.setCursor(13,1);
lcd.print("05");
delay(1000);
lcd.setCursor(13,1);
lcd.print("04");
delay(1000);
lcd.setCursor(13,1);
lcd.print("03");
delay(1000);
lcd.setCursor(13,1);
lcd.print("02");
delay(1000);
lcd.setCursor(13,1);
lcd.print("01");
delay(1000);
lcd.setCursor(13,1);
lcd.print("00");
delay(1000);
lcd.clear();
SmartDoor = 1; // closes the smart door
}
clearData(); // clears the data
}
}

Code in MATLAB GUI


function varargout = msdprojectGUI(varargin)
% MSDPROJECTGUI MATLAB code for msdprojectGUI.fig
% MSDPROJECTGUI, by itself, creates a new MSDPROJECTGUI or raises the existing
% singleton*.
%
% H = MSDPROJECTGUI returns the handle to a new MSDPROJECTGUI or the handle to
% the existing singleton*.
%
% MSDPROJECTGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MSDPROJECTGUI.M with the given input arguments.
%
% MSDPROJECTGUI('Property','Value',...) creates a new MSDPROJECTGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before msdprojectGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to msdprojectGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help msdprojectGUI

% Last Modified by GUIDE v2.5 15-May-2024 12:03:34

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @msdprojectGUI_OpeningFcn, ...
'gui_OutputFcn', @msdprojectGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before msdprojectGUI is made visible.


function msdprojectGUI_OpeningFcn(hObject, eventdata, handles, varargin)

handles.a=arduino('COM9','Mega2560','Libraries','Servo');
handles.lock=servo(handles.a,'D8');

% This function has no output args, see OutputFcn.


% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to msdprojectGUI (see VARARGIN)

% Choose default command line output for msdprojectGUI


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes msdprojectGUI wait for user response (see UIRESUME)


% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = msdprojectGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

function screen_Callback(hObject, eventdata, handles)


% hObject handle to screen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of screen as text


% str2double(get(hObject,'String')) returns contents of screen as a double

% --- Executes during object creation, after setting all properties.


function screen_CreateFcn(hObject, eventdata, handles)
% hObject handle to screen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in number7.


function number7_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'7'));
% hObject handle to number7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number8.


function number8_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'8'));
% hObject handle to number8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number9.


function number9_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'9'));
% hObject handle to number9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in stringA.


function stringA_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'A'));
% hObject handle to stringA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number4.


function number4_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'4'));
% hObject handle to number4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number5.


function number5_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'5'));
% hObject handle to number5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number6.


function number6_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'6'));
% hObject handle to number6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in stringB.


function stringB_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'B'));
% hObject handle to stringB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number1.


function number1_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'1'));
% hObject handle to number1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number2.


function number2_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'2'));
% hObject handle to number2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in number3.
function number3_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'3'));
% hObject handle to number3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in stringC.


function stringC_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'C'));
% hObject handle to stringC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number0.


function number0_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'0'));
% hObject handle to number0 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in number.


function number_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'#'));
% hObject handle to number (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in stringD.


function stringD_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'D'));
% hObject handle to stringD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
s=get(handles.screen,'string');
set(handles.screen,'string',strcat(s,'*'));
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in check.


function check_Callback(hObject, eventdata, handles)
x=str2double(get(handles.screen,'string'));
if(x==1234)
set(handles.screen,'string','VALID');

writePosition(handles.lock,1);

else
set(handles.screen,'string','INVALID');
writePosition(handles.lock,0);

end

You might also like