This project implements a smart room automation system using an Arduino Uno, featuring predefined password-protected secure door access, automatic lighting based on occupancy, and automatic smoke detection with an alarm. The system prioritizes smoke detection over unauthorized access for safety.
- Purpose: Automate room functions (secure door, occupancy-based lighting, smoke detection) with sensor-based control.
- Platform: Designed and simulated in Tinkercad.
https://www.tinkercad.com/things/3gTcExSN1LN-smart-room
- Arduino Uno: Microcontroller (central unit).
- Servo Motor: Pin 3 (controls door lock, 0° = locked, 90° = unlocked).
- LEDs:
- Red LED (Pin 5): Indicates incorrect password.
- Green LED (Pin 6): Indicates access granted.
- Buzzer: Pin 4 (audible alarm for smoke detection).
- Gas Sensor (MQ-2): Analog pin A0 (detects smoke, threshold >600 for unsafe level).
- PIR Sensors:
- PIR1 (Pin A3): Detects entry (outside).
- PIR2 (Pin A2): Detects exit/inside movement.
- Light: Pin A1 (turns on/off based on occupancy).
- DC Motor (Exhaust Fan): Pin 4 (via 2N2222 (npn) transistor with 1kΩ resistor, activates with smoke).
- Keypad (4x4): Pins 7-13 and 2 (for password entry).
- LCD (16x2 with I2C) (Type [PCF8574], [39 (0X27)]): Default SDA/SCL (A4/A5) (displays status, occupancy, and messages).
- Servo Motor: Connect signal to Pin 3, VCC to 5V, GND to GND.
- LEDs: Connect anodes to Pins 5 and 6, cathodes to GND via 220Ω resistors.
- Buzzer: Connect positive to Pin 4, negative to GND.
- Gas Sensor: Connect VCC to 5V, GND to GND, AOUT to A0.
- PIR Sensors: Connect VCC to 5V, GND to GND, OUT to A3 (PIR1) and A2 (PIR2).
- Light: Connect anode to A1, cathode to GND via 220Ω resistor.
- DC Motor (Exhaust Fan): Connect positive to transistor collector, negative to GND; transistor base to Pin 4 via 1kΩ resistor, emitter to GND; add a diode across motor terminals (cathode to positive) to protect against back EMF.
- Keypad: Connect rows to Pins 7-10, columns to Pins 11-13 and 2.
- LCD: Connect via I2C module to A4 (SDA) and A5 (SCL), VCC to 5V, GND to GND.
- 1.1 Success Prompt if Password is Correct:
- Enter the default password "0000" (or a new password set via master password "1234") using the keypad.
- On correct entry (confirmed with 'C'), the LCD displays "Access Granted," the green LED flashes 5 times, and the servo unlocks the door (moves to 90°).
- 1.2 Implement Door Opening Feature:
- The
unlockDoor()function sets the servo to 90° for 10 seconds. Press 'D' on the keypad to lock it manually, or it auto-locks after the timer.
- The
- 1.3 Warning Message if Password is Wrong:
- On incorrect password entry, the LCD shows "CODE INCORRECT," and the red LED lights up. After 3 failed attempts, a 30-second wait is enforced; otherwise, a 3-second delay applies. Warnings are deferred if smoke is detected.
- 2.1 Detect People Entering/Exiting a Room:
- PIR1 (A3) detects entry when triggered first, followed by PIR2 (A2) within 15 seconds, indicating movement inward.
- PIR2 triggered first, then PIR1 within 15 seconds (with exit sequence flag), indicates movement outward.
- 2.2 Keep Count of People Occupied:
- The
loop()function updates theoccupancyvariable based on PIR sequences, incrementing for entry and decrementing for exit, with a 2-second debounce.
- The
- 2.3 Turn On/Off Light Based on Count:
- The light (A1) turns on if
occupancy > 0and off ifoccupancy = 0, managed inloop().
- The light (A1) turns on if
- 3.1 Turn On Alarm if Smoke Detected:
- The gas sensor (A0) monitors smoke levels. If >600, the exhaust fan (Pin 1) activates via a transistor, and the buzzer (Pin 4) beeps (500ms) as an alarm. This has the highest priority.
- 3.2 Turn Off Alarm When Smoke Level is Below Unsafe Level:
- When the gas sensor value drops to <=600, the exhaust fan and buzzer turn off, resuming deferred unauthorized access warnings if any.
- Initializes serial communication (9600 baud) for debugging.
- Configures pin modes (OUTPUT for LEDs, buzzer, fan, light; INPUT for sensors).
- Initializes LCD, sets servo to locked (0°), and displays "Smart Room Ready".
- Smoke Detection: Prioritizes checking A0; if >600, activates fan and buzzer, defers unauthorized warnings. If <=600, turns off fan/buzzer and processes pending warnings.
- Door Unlock Countdown: Manages a 10-second unlock timer.
- Keypad Input: Handles password entry, master check, or setup.
- Occupancy Counting: Processes PIR sequences for entry/exit.
- Light Control: Adjusts light based on occupancy.
- Uses a 50ms delay for responsiveness.
- Updates LCD with occupancy count (second line) if not in password/unlock mode.
- Logs to Serial Monitor.
- Clears LCD, shows "Enter Password:" with occupancy.
- Locks door (servo to 0°), updates LCD, resets exit flag.
- Unlocks door (servo to 90°), flashes green LED, sets 10-second timer.
- Sets new password (0-9, 'B' backspace, 'C' confirm).
- Verifies master password ("1234") for setup.
- Processes password input; defers incorrect warning if smoke detected.
- Displays warning, lights red LED, enforces delays after failures.
- Resets PIR flags and timers.
- Smoke Detection Priority: If smoke is detected, the system activates the exhaust fan and buzzer immediately, deferring unauthorized access warnings until smoke levels drop below 600.
- Circuit Overview
- Smoke Detection Active (fan and buzzer on)
- Door Unlocked (servo at 90°, green led blinking)
- Occupancy Display (LCD showing people count, count > 0 turn on blue led)
- Open the Tinkercad link and start the simulation.
- Enter "0000" to unlock the door (green LED flashes).
- Use PIR sensors to simulate entry/exit and watch occupancy/light changes.
- Set gas sensor >600 to trigger smoke alarm and fan.
- Test wrong password during smoke to see deferred warning.
- Developed by Fahith K.R.M. on Monday, October 02, 2025.
- Shared on GitHub for portfolio and resume enhancement.