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. It is also useful from a practical point of view, because it can be extended into a real small-scale alarm system.
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, Bluetooth interface, ADC, I2C, and PWM control |
| MPU6050 or LIS3DH accelerometer module | 1 | Motion and vibration detection using I2C |
| LDR sensor | 3 | Light detection inside the drawer |
| 10 kΩ resistor | 3 | Fixed resistors for the LDR voltage dividers |
| Passive buzzer | 1 | Acoustic alarm output |
| NPN transistor, for example 2N2222 or BC547 | 1 | Low-side driver for the buzzer |
| 1 kΩ resistor | 1 | Base resistor for the transistor |
| 10 kΩ resistor | 1 | Pull-down resistor for the transistor base |
| Breadboard | 1 | Prototype assembly |
| Jumper wires | as needed | Electrical connections |
| USB cable | 1 | ESP32 programming and power supply |
| 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 |
| LDR voltage dividers | 3.3V and GND | Analog light sensing circuits |
| Buzzer positive terminal | 3.3V | Buzzer supply |
| Buzzer negative terminal | NPN collector | Low-side switching through transistor |
| NPN emitter | GND | Ground connection |
Each LDR is connected as part of a voltage divider powered from 3.3V, so the output voltage is compatible with the ESP32 ADC input range.
One possible connection for each LDR channel is:
3.3V --- LDR --- ADC_PIN --- 10 kΩ --- GND
In this configuration, the ADC value changes depending on the amount of light reaching the LDR. The exact threshold will be calibrated experimentally after the sensors are mounted inside the drawer.
The project uses three LDR sensors instead of one in order to improve reliability. The firmware can consider light detected only when at least two sensors report values above the configured 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 accelerometer module must be compatible with 3.3V logic levels. The MPU6050 and LIS3DH are common options and both can be used for this project if the module is powered correctly.
The accelerometer is used to detect changes in acceleration. Sudden changes or values above a configured threshold are interpreted as movement, vibration, or drawer displacement.
The passive buzzer is controlled through a transistor instead of being connected directly to the ESP32 GPIO pin. This protects the microcontroller and allows the buzzer current to be switched safely.
The ESP32 generates a PWM signal on GPIO25. This signal is applied to the base of the NPN transistor through a 1 kΩ resistor. The transistor works as a low-side switch for the buzzer.
Basic connection:
ESP32 GPIO25 --- 1 kΩ --- NPN base NPN emitter -------------- GND NPN collector ------------ buzzer negative terminal buzzer positive terminal -- 3.3V
A 10 kΩ pull-down resistor can be connected between the transistor base and GND to keep the buzzer off while the ESP32 pin is not configured.
| Signal | Type | Description |
|---|---|---|
| LDR1_ADC | Analog input | Voltage proportional to the light level measured by LDR 1 |
| LDR2_ADC | Analog input | Voltage proportional to the light level measured by LDR 2 |
| LDR3_ADC | Analog input | Voltage proportional to the light level measured by LDR 3 |
| SDA | I2C data | Data line between ESP32 and accelerometer |
| SCL | I2C clock | Clock line between ESP32 and accelerometer |
| BUZZER_PWM | PWM output | Signal used to generate tones on the passive buzzer |
| Bluetooth Serial | Wireless serial communication | Receives commands and sends system responses |