Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Door Lock – Fully Non-Blocking State Machine

Proteus Arduino UNO C++

A safety-critical smart lock system with a non-blocking architecture on resource-constrained hardware. Designed for Arduino UNO, validated in Proteus simulation.

Key Design Decisions

Zero-Blocking Runtime Architecture

Every timed behavior (servo sweep, ultrasonic polling, LED feedback, keypad timeout) uses millis() delta tracking instead of delay(). The main loop executes in <1ms when idle, guaranteeing responsive PIR edge detection and immediate safety reversal during door closure.

Fail-Safe by design

  • Sensor Failure = Obstruction: If the ultrasonic sensor disconnects or times out (pulseIn() returns 0), the system does not assume the path is clear but treats the error as an obstruction and refuses to close.
  • Dynamic Reversal: If a person steps into the doorway during the CLOSING state, the motor does not finish its sweep but instantly reverses to OPENING.
  • Paused Timer: The 5-second auto-close countdown actively pauses while a person is detected in the doorway. The door will never close on someone just because the timer expired while they were standing there.

Explicit State Machine

7 States:

  • SLEEP, WAKE, ENTER_PW, WRONG_PW,
  • OPENING, DOOR_OPEN, CLOSING

Each state owns its entry conditions, exit criteria, and context reset logic. No hidden static variables; all persistent state is explicitly declared and initialized on transition.

Hardware Mapping

Component Pin(s) Notes
Keypad Rows D2-D5 4×3 matrix
Keypad Cols D6, D7, A0
Servo Signal D8 Locked=180°, Open=0°
PIR Sensor D9 Active HIGH
Ultrasonic Trig D10 HC-SR04
Ultrasonic Echo D11 30ms timeout
Green LED D12 Unlock indicator
Red LED D13 Error / obstruction indicator
I2C LCD SDA/SCL Address 0x20, 16×2

Software Dependencies

  • Arduino IDE
  • Libraries:
    • LiquidCrystal_I2C
    • Keypad
    • Servo

Simulation vs. Hardware Behavior

Developed and validated in Proteus Design Suite.

The code includes lcd.noBacklight() for logical sleep mode. Trust the serial monitor output ([STATE] SLEEP - Re-armed) as the authoritative sleep indicator during simulation (Proteus simulation may not accurately reflect LCD backlight behavior)

Configuration

Edit these constants at the top of the sketch:

constexpr const char * PASSWORD     = "1234";   // 4-digit PIN
constexpr float       SAFE_DISTANCE = 40.0;     // cm, obstruction threshold
constexpr unsigned long MAX_OPEN_MS = 5000;    // Auto-close delay
constexpr int KEYPAD_TIMEOUT_MS     = 3000;   // Return to sleep if idle

Serial Monitor Output

Open at 9600 baud for real-time state transitions, sensor readings, and safety event logging. All debug strings use F() macro to preserve SRAM.

About

smart-lock with Proteus sim

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages