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 will activate a passive buzzer and send a notification to a PC application through Bluetooth Low Energy.
The initial idea came from the fact that a closed drawer is normally dark and still. Sudden light exposure or movement can indicate that someone opened the drawer or moved the protected box. 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 embedded systems concepts in a practical application. From the hardware point of view, the current stage focuses on sensor wiring, power distribution, ADC inputs, I2C communication and transistor-based buzzer driving.
The system is built around an ESP32 LOLIN32 Lite 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 and controls the passive buzzer using a PWM signal and a transistor driver.
The user interface will be implemented through a PC application. There is no display and no physical keypad on the embedded device. The user will be able to arm or disarm the system remotely.
The final system is planned to have three main states:
DISARM <PIN> command is received.The planned remote commands for the final software stage are:
ARM <PIN>DISARM <PIN>STATUSCHANGE_PIN <old_pin> <new_pin>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 planned firmware will use a two-out-of-three decision rule. This should make the light detection more reliable and reduce 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 someone may move the drawer or the whole box without fully opening it, in which case the light sensors may not detect a change immediately.
At the current hardware milestone, the ESP32 LOLIN32 Lite is mounted on a breadboard together with:
The board is powered and programmed through USB during development. After the firmware is uploaded, the ESP32 can also be powered from an external USB power bank for standalone operation.
The current hardware was tested with a firmware smoke test. The Serial Monitor confirms that:
0x19;WHO_AM_I = 0x33, which indicates a LIS3DH-compatible device;SmartDrawerAlarm.Current Serial Monitor evidence:
Smart Drawer Anti-Theft System boot [LOG] 221 BOOT [LOG] 1578 I2C 0x19 accel=LIS3DH-compatible addr=0x19 who=0x33 [LOG] 1579 LDR raw1=939 base1=937 deltaThreshold=450 [LOG] 1864 BLE advertising SmartDrawerAlarm
This proves that the ESP32 is running uploaded firmware, the I2C accelerometer is wired correctly and the ADC reading for the LDR circuit is functional. The second and third LDR sensors have also been physically added on GPIO35 and GPIO32 and will be verified together with the final three-sensor voting logic.
| Component | Quantity | Role in project |
|---|---|---|
| ESP32 LOLIN32 Lite | 1 | Main microcontroller, sensor reading, buzzer control and Bluetooth communication |
| LIS3DH-compatible accelerometer module | 1 | Motion and vibration detection over I2C |
| LDR sensor | 3 | Light detection inside the drawer |
| 10 kOhm resistor | 3 | Fixed resistors for the LDR voltage dividers |
| Passive buzzer | 1 | Acoustic alarm |
| 2N2222 NPN transistor | 1 | Low-side driver for the passive buzzer |
| 1 kOhm resistor | 1 | Base resistor for the 2N2222 transistor |
| Breadboard | 1 | Prototype assembly |
| Jumper wires | as needed | Electrical connections |
| USB cable | 1 | Firmware upload, serial debugging and power during development |
| External USB power bank | 1, optional | Standalone power supply after firmware upload |
| Module / Signal | ESP32 Pin | Reason for choosing this pin |
|---|---|---|
| LDR 1 voltage divider output | GPIO34 | ADC-capable input-only pin, suitable for analog sensing |
| LDR 2 voltage divider output | GPIO35 | ADC-capable input-only pin, suitable for analog sensing |
| LDR 3 voltage divider output | GPIO32 | ADC-capable GPIO, used for the third light sensor |
| Accelerometer SDA | GPIO23 | Custom I2C data pin used by the firmware |
| Accelerometer SCL | GPIO22 | I2C clock pin |
| Buzzer PWM control | GPIO17 | PWM-capable GPIO used to drive the passive buzzer through a transistor |
| Accelerometer VCC | 3.3 V | Sensor power supply compatible with ESP32 logic |
| Accelerometer GND | GND | Common ground |
| LDR voltage dividers VCC | 3.3 V | Keeps ADC voltage within ESP32 limits |
| LDR voltage dividers GND | GND | Common ground |
| Buzzer positive terminal | 3.3 V | Buzzer supply |
| Buzzer negative terminal | 2N2222 collector | Transistor switches the buzzer to ground |
GPIO34 and GPIO35 are input-only pins, which is acceptable for LDR measurements because the firmware only needs ADC input. GPIO32 is also ADC-capable and is used for the third LDR. GPIO23 and GPIO22 are used as custom I2C pins for the accelerometer. GPIO17 is used for PWM because the buzzer is passive and must be driven with a square wave, not just a static HIGH/LOW output.
Each LDR is connected as a voltage divider powered from 3.3 V, so the output voltage remains compatible with the ESP32 ADC input range:
3.3V ---- LDR ---- ADC_PIN ---- 10 kOhm ---- GND
The ADC pins are:
| LDR | ADC pin |
|---|---|
| LDR1 | GPIO34 |
| LDR2 | GPIO35 |
| LDR3 | GPIO32 |
The firmware will store a dark baseline during calibration and then compare the current ADC values with this baseline. The final light detection logic will use all three LDR sensors and will trigger the alarm only when at least two sensors detect a significant light change.
The accelerometer module is connected to the ESP32 using I2C:
ESP32 GPIO23 -> SDA ESP32 GPIO22 -> SCL ESP32 3.3V -> VCC ESP32 GND -> GND
The firmware performs an I2C scan at startup and reads the WHO_AM_I register. The detected sensor currently reports:
I2C address: 0x19 WHO_AM_I: 0x33 Type: LIS3DH-compatible
This startup check is important because the exact accelerometer chip was not assumed only from the module appearance. The sensor is verified through I2C before being used for motion detection.
The passive buzzer is controlled through a 2N2222 NPN transistor, not directly from an ESP32 GPIO pin. The ESP32 generates a PWM signal on GPIO17, and the transistor works as a low-side switch:
ESP32 GPIO17 --- 1 kOhm --- 2N2222 base 2N2222 emitter ----------- GND 2N2222 collector --------- buzzer negative terminal buzzer positive terminal - 3.3 V
The buzzer is passive, therefore it requires a PWM/tone signal. The transistor protects the ESP32 GPIO and allows the buzzer current to be switched externally.
The electrical diagram should show:
This section will be completed during the software milestone. At the current hardware milestone, only a basic firmware smoke test was used to verify that the connected hardware components can be accessed by the ESP32.
This section will be completed after the full integration and testing stage.
For the current hardware milestone, the obtained hardware results are:
WHO_AM_I = 0x33;
At the current stage, the project has a working hardware prototype on breadboard. The most important hardware blocks are connected, and at least one component, the accelerometer, has been verified through I2C detection and WHO_AM_I reading. The LDR circuit also produces ADC readings, and the ESP32 is able to boot and advertise over BLE.
The next hardware-related steps are to take clear photos of the assembled circuit, finish the electrical diagram, verify all three LDR sensors individually and test the passive buzzer driver.
This section will be completed later with the public repository link and final source code structure.
| Date | Progress |
|---|---|
| 2026-05-08 | Initial OCW project page created with project idea, block diagram and first hardware description. |
| 2026-05-15 | Hardware pin mapping was finalized for ESP32 LOLIN32 Lite: LDRs on GPIO34/GPIO35/GPIO32, I2C on GPIO23/GPIO22 and buzzer PWM on GPIO17. |
| 2026-05-15 | ESP32 firmware smoke test was uploaded successfully through USB using PlatformIO. |
| 2026-05-15 | Serial Monitor confirmed accelerometer detection at I2C address 0x19 with WHO_AM_I value 0x33. |
| 2026-05-15 | Three LDR voltage divider connections were added on the breadboard. |