This is an old revision of the document!
The Smart Drawer Anti-Theft System is an embedded security system designed to protect a drawer, box, or small storage compartment against unauthorized access. The system uses an ESP32 microcontroller and detects suspicious activity using two complementary methods: motion detection with an I2C accelerometer and light detection using three LDR sensors placed inside the drawer.
The purpose of the project is to build a realistic, low-cost, and physically implementable anti-theft system using common components that can be connected on a breadboard. When the system is armed and detects movement, vibration, or light inside the drawer, it activates a passive buzzer and sends a notification through Bluetooth to a PC.
The initial idea came from the need for a simple security solution for personal objects stored in a drawer. A drawer is normally dark and still when closed, so sudden light exposure or movement can indicate that someone opened or moved it. By combining an accelerometer with three LDR sensors, the system can detect multiple types of unauthorized access and reduce false alarms.
The project is useful because it demonstrates several important embedded systems concepts in a practical application: analog sensor reading, I2C communication, PWM signal generation, Bluetooth communication, and finite state machine control.
The system is built around an ESP32 DevKit board, which acts as the main controller. The ESP32 reads the three LDR sensors through ADC pins, communicates with the accelerometer using the I2C bus, controls the passive buzzer using PWM, and exchanges commands and notifications with the user through Bluetooth.
The user interface is implemented exclusively through Bluetooth. There is no display and no physical keypad. The user can arm or disarm the system remotely by sending commands from a PC or phone connected to the ESP32 Bluetooth serial interface.
The system has three main states:
DISARM <PIN> command is received.The supported Bluetooth commands are:
ARM <PIN>DISARM <PIN>STATUSCHANGE_PIN <old_pin> <new_pin>The PIN is validated by the firmware before changing the security state of the system. Invalid commands or incorrect PIN values are rejected and reported back through Bluetooth.
The system contains the following modules:
The three LDR sensors are used for redundancy. Instead of triggering the alarm based on only one sensor, the firmware can use a two-out-of-three decision rule. This makes the light detection more reliable and helps avoid false alarms caused by sensor noise or uneven lighting.
The accelerometer is used to detect drawer movement, vibration, or sudden displacement. This is useful because an attacker may move the drawer or the whole box without fully opening it, in which case the light sensors may not detect a change immediately.
| Component | Quantity | Role |
|---|---|---|
| ESP32 DevKit | 1 | Main microcontroller |
| MPU6050 or LIS3DH accelerometer module | 1 | Motion detection using I2C |
| LDR sensor | 3 | Light detection inside the drawer |
| 10 kΩ resistor | 3 | LDR voltage dividers |
| Passive buzzer | 1 | Acoustic alarm |
| NPN transistor, for example 2N2222 or BC547 | 1 | Buzzer driver |
| Resistors for transistor control | 2 | Base resistor and pull-down resistor |
| Breadboard | 1 | Prototype |
| Jumper wires | as needed | Electrical connections |
| USB cable | 1 | Power and programming |
| Module / Signal | ESP32 Pin | Description |
|---|---|---|
| LDR 1 voltage divider output | GPIO34 | ADC input for first light sensor |
| LDR 2 voltage divider output | GPIO35 | ADC input for second light sensor |
| LDR 3 voltage divider output | GPIO32 | ADC input for third light sensor |
| Accelerometer SDA | GPIO21 | I2C data line |
| Accelerometer SCL | GPIO22 | I2C clock line |
| Buzzer PWM control | GPIO25 | PWM output connected to transistor base through 1 kΩ resistor |
| Accelerometer VCC | 3.3V | Power supply for accelerometer module |
| Accelerometer GND | GND | Common ground |
Each LDR is connected as a voltage divider powered from 3.3V, so the output voltage remains compatible with the ESP32 ADC input range:
3.3V --- LDR --- ADC_PIN --- 10 kΩ --- GND
The exact detection threshold will be calibrated experimentally after the sensors are mounted inside the drawer. The firmware can consider light detected only when at least two sensors report values above the threshold.
The accelerometer module is connected to the ESP32 using the I2C bus:
ESP32 GPIO21 -> SDA ESP32 GPIO22 -> SCL ESP32 3.3V -> VCC ESP32 GND -> GND
The selected module must be compatible with 3.3V logic levels. Sudden changes in acceleration are interpreted as movement, vibration, or drawer displacement.
The passive buzzer is controlled through an NPN transistor, not directly from an ESP32 GPIO pin. The ESP32 generates a PWM signal on GPIO25, and the transistor works as a low-side switch:
ESP32 GPIO25 --- 1 kΩ --- NPN base NPN emitter -------------- GND NPN collector ------------ buzzer negative terminal buzzer positive terminal -- 3.3V