Smart Doorbell System – Raspberry Pi Project
This project is a smart doorbell system built on a Raspberry Pi using the GrovePi sensor kit and Python. It combines motion detection, light sensing, and a physical doorbell button to trigger notifications via visual, audio, and cloud-based channels. It also includes mock hardware modules and a full unit test suite, allowing for development and testing without physical hardware.
Features
- Motion detection (PIR sensor)
- Light level detection for night/day logic
- Button press detection (doorbell trigger)
- LCD display (scrolling messages)
- Audio buzzer notifications
- Visual and MQTT (Thingsboard) notifications
- Fully testable with mocked GPIO and MQTT clients
- Modular code structure for clarity and reusability
Project Structure
doorbellSystem/
├── doorbell/# Core application logic
├── config.py
├── display.py
├── mqtt_client.py
├── notifier.py
├── sensors.py
├── utils.py
└── main.py
│
├── mocks/ # Mocked hardware interfaces
├── mock_gpio.py
├── mock_lcd.py
└── mock_mqtt.py
│
├── tests/ # Unit tests for all major components
├── test_button.py
├── test_light.py
├── test_motion.py
├── test_display.py
└── test_mqtt.py
│
├── run_tests.py # Script to run the full test suite
└── README.md # You're reading this!
Running the program
This project must be run as a module python -m doorbell.main
Running the Test Suite
This project uses Python’s unittest
framework with custom hardware mocks for offline/local testing.
1. Enable Mock Mode
In doorbell/config.py
, make sure this is set: MOCK_MODE = True
2. Run the Tests
From the root folder: python run_tests.py
3. Verify Output
Example Output csharp Copy Edit [TEST] Reading motion sensor on pin 4 [MOCK GPIO] digitalRead(4) Motion detected: True
[TEST] Reading light level on pin 1 [MOCK GPIO] analogRead(1) Light level: 412 ...
Ran 6 tests in 0.01s
OK All tests should return ok if the system is working correctly.
Unit Test Coverage Test File Description test_button.py Verifies mock button returns expected values test_motion.py Checks mock motion sensor readings test_light.py Validates light value range + night mode threshold test_display.py Ensures LCD accepts and displays messages test_mqtt.py Tests MQTT connection and telemetry sending