This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:calin.marinescu [2026/05/08 12:51] calin.marinescu [Jurnal] |
pm:prj2026:jan.vaduva:calin.marinescu [2026/05/16 01:14] (current) calin.marinescu [Hardware Photos and Evidence] |
||
|---|---|---|---|
| Line 5: | Line 5: | ||
| 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 **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 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 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 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 important embedded systems concepts in a practical application: analog sensor reading, I2C communication, PWM signal generation, Bluetooth communication, and finite state machine control. | + | 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. |
| + | |||
| + | * analog sensor reading using ADC; | ||
| + | * I2C communication with an accelerometer; | ||
| + | * PWM signal generation for a passive buzzer; | ||
| + | * common ground and 3.3 V power distribution; | ||
| + | * safe interfacing between the ESP32 and external components. | ||
| ===== General Description ===== | ===== 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 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 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 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 system has three main states: | + | The final system is planned to have 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. | * **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. | + | * **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. | + | * **ALARM** - the buzzer is active and a notification is sent. The system remains in this state until a correct ''DISARM <PIN>'' command is received. |
| - | The supported Bluetooth commands are: | + | The planned remote commands for the final software stage are: |
| * ''ARM <PIN>'' | * ''ARM <PIN>'' | ||
| Line 29: | Line 35: | ||
| * ''STATUS'' | * ''STATUS'' | ||
| * ''CHANGE_PIN <old_pin> <new_pin>'' | * ''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 ==== | ==== Block Diagram ==== | ||
| - | {{:pm:prj2026:jan.vaduva:diagrama_bloc.png?500|Smart Drawer Anti-Theft System block diagram}} | + | {{:pm:prj2026:jan.vaduva:diagrama_bloc.png?600|Smart Drawer Anti-Theft System block diagram}} |
| The system contains the following modules: | The system contains the following modules: | ||
| - | * **ESP32 DevKit** - central processing unit of the project. | + | * **ESP32 LOLIN32 Lite** - central processing unit of the project. |
| - | * **LDR sensor module** - made of three LDR voltage dividers connected to ADC pins. | + | * **LDR sensor module** - three LDR voltage dividers connected to ADC pins. |
| * **Accelerometer module** - detects movement and vibration through I2C communication. | * **Accelerometer module** - detects movement and vibration through I2C communication. | ||
| - | * **Bluetooth serial interface** - receives user commands and sends status or alarm messages. | + | * **Buzzer driver** - passive buzzer controlled through a 2N2222 transistor and PWM. |
| - | * **Buzzer driver** - uses a transistor controlled by a PWM signal from the ESP32. | + | * **Bluetooth communication module** - planned communication channel between the ESP32 and the PC application. |
| - | * **State machine firmware** - decides whether the system is disarmed, armed, or in alarm mode. | + | * **State machine firmware** - planned logic for the DISARMED, ARMED and ALARM states. |
| - | 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 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 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. | + | 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. |
| ===== Hardware Design ===== | ===== Hardware Design ===== | ||
| + | |||
| + | ==== Current Hardware Implementation Status ==== | ||
| + | |||
| + | At the current hardware milestone, the ESP32 LOLIN32 Lite is mounted on a breadboard together with: | ||
| + | |||
| + | * three LDR voltage dividers; | ||
| + | * an I2C accelerometer module; | ||
| + | * a passive buzzer driven through a 2N2222 NPN transistor; | ||
| + | * common 3.3 V and GND rails. | ||
| + | |||
| + | 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: | ||
| + | |||
| + | * the ESP32 boots correctly; | ||
| + | * the accelerometer is detected on the I2C bus at address ''0x19''; | ||
| + | * the accelerometer returns ''WHO_AM_I = 0x33'', which indicates a LIS3DH-compatible device; | ||
| + | * at least one LDR reading is visible through the ADC; | ||
| + | * the board starts BLE advertising as ''SmartDrawerAlarm''. | ||
| + | |||
| + | Current Serial Monitor evidence: | ||
| + | |||
| + | <code> | ||
| + | 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 | ||
| + | </code> | ||
| + | |||
| + | 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 List ==== | ==== Component List ==== | ||
| - | ^ Component ^ Quantity ^ Role ^ | + | ^ Component ^ Quantity ^ Role in project ^ |
| - | | ESP32 DevKit | 1 | Main microcontroller | | + | | ESP32 LOLIN32 Lite | 1 | Main microcontroller, sensor reading, buzzer control and Bluetooth communication | |
| - | | MPU6050 or LIS3DH accelerometer module | 1 | Motion detection using I2C | | + | | LIS3DH-compatible accelerometer module | 1 | Motion and vibration detection over I2C | |
| | LDR sensor | 3 | Light detection inside the drawer | | | LDR sensor | 3 | Light detection inside the drawer | | ||
| - | | 10 kΩ resistor | 3 | LDR voltage dividers | | + | | 10 kOhm resistor | 3 | Fixed resistors for the LDR voltage dividers | |
| | Passive buzzer | 1 | Acoustic alarm | | | Passive buzzer | 1 | Acoustic alarm | | ||
| - | | NPN transistor, for example 2N2222 or BC547 | 1 | Buzzer driver | | + | | 2N2222 NPN transistor | 1 | Low-side driver for the passive buzzer | |
| - | | Resistors for transistor control | 2 | Base resistor and pull-down resistor | | + | | 1 kOhm resistor | 1 | Base resistor for the 2N2222 transistor | |
| - | | Breadboard | 1 | Prototype | | + | | Breadboard | 1 | Prototype assembly | |
| | Jumper wires | as needed | Electrical connections | | | Jumper wires | as needed | Electrical connections | | ||
| - | | USB cable | 1 | Power and programming | | + | | USB cable | 1 | Firmware upload, serial debugging and power during development | |
| + | | External USB power bank | 1, optional | Standalone power supply after firmware upload | | ||
| - | ==== Hardware Connections ==== | + | ==== Pin Mapping ==== |
| - | ^ Module / Signal ^ ESP32 Pin ^ Description ^ | + | ^ Module / Signal ^ ESP32 Pin ^ Reason for choosing this pin ^ |
| - | | LDR 1 voltage divider output | GPIO34 | ADC input for first light sensor | | + | | LDR 1 voltage divider output | GPIO34 | ADC-capable input-only pin, suitable for analog sensing | |
| - | | LDR 2 voltage divider output | GPIO35 | ADC input for second light sensor | | + | | LDR 2 voltage divider output | GPIO35 | ADC-capable input-only pin, suitable for analog sensing | |
| - | | LDR 3 voltage divider output | GPIO32 | ADC input for third light sensor | | + | | LDR 3 voltage divider output | GPIO32 | ADC-capable GPIO, used for the third light sensor | |
| - | | Accelerometer SDA | GPIO21 | I2C data line | | + | | Accelerometer SDA | GPIO23 | Custom I2C data pin used by the firmware | |
| - | | Accelerometer SCL | GPIO22 | I2C clock line | | + | | Accelerometer SCL | GPIO22 | I2C clock pin | |
| - | | Buzzer PWM control | GPIO25 | PWM output connected to transistor base through 1 kΩ resistor | | + | | Buzzer PWM control | GPIO17 | PWM-capable GPIO used to drive the passive buzzer through a transistor | |
| - | | Accelerometer VCC | 3.3V | Power supply for accelerometer module | | + | | Accelerometer VCC | 3.3 V | Sensor power supply compatible with ESP32 logic | |
| | Accelerometer GND | GND | Common ground | | | 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. | ||
| ==== LDR Voltage Dividers ==== | ==== 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: | + | 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: |
| <code> | <code> | ||
| - | 3.3V --- LDR --- ADC_PIN --- 10 kΩ --- GND | + | 3.3V ---- LDR ---- ADC_PIN ---- 10 kOhm ---- GND |
| </code> | </code> | ||
| - | 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 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. | ||
| ==== Accelerometer Connection ==== | ==== Accelerometer Connection ==== | ||
| - | The accelerometer module is connected to the ESP32 using the I2C bus: | + | The accelerometer module is connected to the ESP32 using I2C: |
| <code> | <code> | ||
| - | ESP32 GPIO21 -> SDA | + | ESP32 GPIO23 -> SDA |
| ESP32 GPIO22 -> SCL | ESP32 GPIO22 -> SCL | ||
| ESP32 3.3V -> VCC | ESP32 3.3V -> VCC | ||
| Line 98: | Line 147: | ||
| </code> | </code> | ||
| - | The selected module must be compatible with **3.3V logic levels**. Sudden changes in acceleration are interpreted as movement, vibration, or drawer displacement. | + | The firmware performs an I2C scan at startup and reads the ''WHO_AM_I'' register. The detected sensor currently reports: |
| + | |||
| + | <code> | ||
| + | I2C address: 0x19 | ||
| + | WHO_AM_I: 0x33 | ||
| + | Type: LIS3DH-compatible | ||
| + | </code> | ||
| + | |||
| + | 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. | ||
| ==== Buzzer Driver ==== | ==== 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: | + | 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: |
| <code> | <code> | ||
| - | ESP32 GPIO25 --- 1 kΩ --- NPN base | + | ESP32 GPIO17 --- 1 kOhm --- 2N2222 base |
| - | NPN emitter -------------- GND | + | 2N2222 emitter ----------- GND |
| - | NPN collector ------------ buzzer negative terminal | + | 2N2222 collector --------- buzzer negative terminal |
| - | buzzer positive terminal -- 3.3V | + | buzzer positive terminal - 3.3 V |
| </code> | </code> | ||
| + | |||
| + | 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. | ||
| ==== Electrical Diagram ==== | ==== Electrical Diagram ==== | ||
| - | {{:pm:prj2026:jan.vaduva:diagrama_electrica.png?500|Smart Drawer hardware connection diagram}} | + | {{:pm:prj2026:jan.vaduva:diagrama_electrica.png?650|Smart Drawer hardware connection diagram}} |
| + | |||
| + | The electrical diagram should show: | ||
| + | |||
| + | * all modules powered from 3.3 V; | ||
| + | * common GND rail for ESP32, sensors and buzzer driver; | ||
| + | * three independent LDR voltage dividers; | ||
| + | * accelerometer connected over I2C on GPIO23/GPIO22; | ||
| + | * buzzer connected through a 2N2222 transistor and a 1 kOhm base resistor; | ||
| + | * no ADC input connected to a voltage higher than 3.3 V. | ||
| ==== Hardware Design Notes ==== | ==== Hardware Design Notes ==== | ||
| - | * All sensors are powered from **3.3V**. | + | * All sensors are powered from **3.3 V**. |
| - | * ADC pins must not receive voltages higher than 3.3V. | + | * ADC pins must not receive voltages higher than 3.3 V. |
| * GPIO34 and GPIO35 are input-only pins, which is suitable for LDR readings. | * GPIO34 and GPIO35 are input-only pins, which is suitable for LDR readings. | ||
| - | * The buzzer is controlled through a transistor. | + | * The buzzer is controlled through a transistor because it should not be powered directly from an ESP32 GPIO. |
| * All modules must share a common ground. | * All modules must share a common ground. | ||
| + | * USB is used for firmware upload, serial debugging and power during development. | ||
| + | * An external USB power bank can be used later for standalone operation after the firmware has already been uploaded. | ||
| ===== Software Design ===== | ===== Software Design ===== | ||
| + | |||
| + | 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. | ||
| ===== Obtained Results ===== | ===== Obtained Results ===== | ||
| + | |||
| + | This section will be completed after the full integration and testing stage. | ||
| + | |||
| + | For the current hardware milestone, the obtained hardware results are: | ||
| + | |||
| + | * ESP32 firmware upload through USB is working; | ||
| + | * Serial Monitor output is available at 115200 baud; | ||
| + | * accelerometer I2C detection is working; | ||
| + | * the accelerometer returns ''WHO_AM_I = 0x33''; | ||
| + | * LDR ADC reading is visible; | ||
| + | * BLE advertising starts successfully. | ||
| ===== Conclusions ===== | ===== Conclusions ===== | ||
| + | |||
| + | 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. | ||
| ===== Source Code and Other GitHub Resources ===== | ===== Source Code and Other GitHub Resources ===== | ||
| + | |||
| + | This section will be completed later with the public repository link and final source code structure. | ||
| ===== Journal ===== | ===== Journal ===== | ||
| + | |||
| + | ^ 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. | | ||
| ===== Bibliography/Resources ===== | ===== Bibliography/Resources ===== | ||
| + | |||
| + | * ESP32 LOLIN32 Lite PlatformIO board documentation: https://docs.platformio.org/en/stable/boards/espressif32/lolin32_lite.html | ||
| + | * ESP32 LOLIN32 Lite pinout reference: https://www.mischianti.org/2021/07/30/esp32-wemos-lolin32-lite-high-resolution-pinout-and-specs/ | ||
| + | * ST LIS3DH datasheet: https://www.st.com/resource/en/datasheet/lis3dh.pdf | ||
| + | * ST LIS3DSH datasheet: https://www.st.com/resource/en/datasheet/lis3dsh.pdf | ||
| + | * ST H3LIS331DL datasheet: https://www.st.com/resource/en/datasheet/h3lis331dl.pdf | ||
| + | * DokuWiki syntax reference: https://ocw.cs.pub.ro/courses/wiki/syntax | ||
| + | * PM project template: https://ocw.cs.pub.ro/courses/pm/pm/prj2021/template | ||