Devices & Components
Arduino Uno Rev3
10 jumper wires 150mm male
MG90S Micro-servo motor
HC-05 Bluetooth Module
4X4 MATRIX KEYPAD
IR SENSOR MODULE
Push Button
USB Power Bank (Generic)
5mm Red LED
Software & Tools
Arduino IDE
Project description
Code
code
1#include <Keypad.h> 2#include <Servo.h> 3 4Servo lockServo; 5 6#define servoPin 12 7#define irPin 11 8#define ledPin 13 9#define buttonPin 8 10 11const String unlockCode = "171011"; 12String enteredCode = ""; 13 14bool isLocked = true; 15 16// Keypad Setup 17const byte ROWS = 4; 18const byte COLS = 4; 19char keys[ROWS][COLS] = { 20 {'1','2','3','A'}, 21 {'4','5','6','B'}, 22 {'7','8','9','C'}, 23 {'*','0','#','D'} 24}; 25byte rowPins[ROWS] = {A0, A1, A2, A3}; 26byte colPins[COLS] = {4, 5, 6, 7}; 27 28Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); 29 30void setup() { 31 Serial.begin(9600); 32 pinMode(irPin, INPUT); 33 pinMode(ledPin, OUTPUT); 34 pinMode(buttonPin, INPUT_PULLUP); 35 lockServo.attach(servoPin); 36 lockDoor(); 37} 38 39void loop() { 40 handleIRSensor(); 41 handleKeypad(); 42 handleBluetooth(); 43 handleButton(); 44} 45 46void handleIRSensor() { 47 int sensorValue = digitalRead(irPin); 48 if (sensorValue == LOW && isLocked) { 49 unlockDoor(); 50 Serial.println("IR Sensor: Door unlocked from inside."); 51 } 52} 53 54void handleKeypad() { 55 char key = keypad.getKey(); 56 if (key) { 57 if (key == '#') { 58 lockDoor(); 59 enteredCode = ""; 60 } else { 61 enteredCode += key; 62 if (enteredCode.length() >= unlockCode.length()) { 63 if (enteredCode == unlockCode) { 64 unlockDoor(); 65 Serial.println("Keypad: Door unlocked."); 66 } 67 enteredCode = ""; 68 } 69 } 70 } 71} 72 73void handleBluetooth() { 74 if (Serial.available()) { 75 String btCommand = Serial.readStringUntil('\n'); 76 btCommand.trim(); 77 if (btCommand == "171011open") { 78 unlockDoor(); 79 Serial.println("Bluetooth: Door unlocked."); 80 } else if (btCommand == "171011close") { 81 lockDoor(); 82 Serial.println("Bluetooth: Door locked."); 83 } 84 } 85} 86 87void handleButton() { 88 if (digitalRead(buttonPin) == LOW && !isLocked) { 89 lockDoor(); 90 Serial.println("Button: Door locked from inside."); 91 delay(500); 92 } 93} 94 95void unlockDoor() { 96 lockServo.write(100); 97 digitalWrite(ledPin, HIGH); 98 isLocked = false; 99} 100 101void lockDoor() { 102 lockServo.write(0); 103 digitalWrite(ledPin, LOW); 104 isLocked = true; 105}
Documentation
circuit diagram
Screenshot 2025-07-08 212115.png

full video of working doorbot model
my project video.mp4
Comments
Only logged in users can leave comments