This is an old revision of the document!


Smart Drawer Anti-Theft System

Introduction

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.

General Description

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:

  • DISARMED - the system is inactive. Sensors may still be read for debugging or status reporting, but they do not trigger the alarm. The buzzer is turned off.
  • ARMED - the system monitors the accelerometer and the three LDR sensors. If movement, vibration, or light is detected, the system enters the alarm state.
  • ALARM - the buzzer is active and a Bluetooth notification is sent. The system remains in this state until a correct DISARM <PIN> command is received.

The supported Bluetooth commands are:

  • ARM <PIN>
  • DISARM <PIN>
  • STATUS
  • CHANGE_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.

Block Diagram

Smart Drawer Anti-Theft System block diagram

The system contains the following modules:

  • ESP32 DevKit - central processing unit of the project.
  • LDR sensor module - made of three LDR voltage dividers connected to ADC pins.
  • Accelerometer module - detects movement and vibration through I2C communication.
  • Bluetooth serial interface - receives user commands and sends status or alarm messages.
  • Buzzer driver - uses a transistor controlled by a PWM signal from the ESP32.
  • State machine firmware - decides whether the system is disarmed, armed, or in alarm mode.

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.

Hardware Design

Component List

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

Hardware Connections

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

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.

Accelerometer Connection

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.

Buzzer Driver

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

Electrical Diagram

Smart Drawer hardware connection diagram

Hardware Design Notes

  • All sensors are powered from 3.3V.
  • ADC pins must not receive voltages higher than 3.3V.
  • GPIO34 and GPIO35 are input-only pins, which is suitable for LDR readings.
  • The buzzer is controlled through a transistor.
  • All modules must share a common ground.

Software Design

Obtained Results

Conclusions

Source Code and Other GitHub Resources

Journal

Bibliography/Resources

pm/prj2026/jan.vaduva/calin.marinescu.1778233860.txt.gz · Last modified: 2026/05/08 12:51 by calin.marinescu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0