This shows you the differences between two versions of the page.
|
pm:prj2026:alexandru.predescu:patricia.bratu [2026/05/16 15:49] patricia.bratu [Image with the process] |
pm:prj2026:alexandru.predescu:patricia.bratu [2026/05/26 15:19] (current) patricia.bratu [Video Demo & Explanations] |
||
|---|---|---|---|
| Line 62: | Line 62: | ||
| ====Image with the process==== | ====Image with the process==== | ||
| {{:pm:prj2026:alexandru.predescu:whatsapp_image_2026-05-16_at_15.45.34.jpeg?500|}} | {{:pm:prj2026:alexandru.predescu:whatsapp_image_2026-05-16_at_15.45.34.jpeg?500|}} | ||
| + | |||
| + | ===== 3. Software Implementation & Project Details ===== | ||
| + | |||
| + | ==== Current Status of the Software Implementation ==== | ||
| + | The software implementation is fully functional and stable. The application is written in **pure C** for the ATmega328P microcontroller using PlatformIO. It successfully runs a real-time fire detection and suppression loop. The system concurrently monitors a flame sensor via both digital and analog channels, triggers an instantaneous acoustic alarm via hardware interrupts, controls a high-power water pump through an isolated relay module, and drives a 2-axis sweep mechanism using hardware PWM. | ||
| + | {{:pm:prj2026:alexandru.predescu:whatsapp_image_2026-05-23_at_13.13.33.jpeg?200|}} | ||
| + | |||
| + | ==== Motivation for Library Selection ==== | ||
| + | In order to maximize execution speed, minimize memory footprint, and strictly adhere to low-level academic requirements, **no external third-party libraries (such as Arduino.h or Servo.h) were used**. | ||
| + | * **[[https://www.nongnu.org/avr-libc/user-manual/modules.html|avr/io.h]]:** Selected to provide direct access to the register maps of the ATmega328P (e.g., DDRD, PORTB, ADMUX), ensuring zero-overhead bit manipulation. | ||
| + | * **avr/interrupt.h:** Chosen to handle the hardware vector management (`ISR(INT0_vect)`) required for sub-microsecond event handling. | ||
| + | * **util/delay.h:** Used exclusively for minor debouncing and regulating the sweep velocity of the servo motor where strict asynchronous non-blocking timers were not vital. | ||
| + | |||
| + | ==== Element of Novelty ==== | ||
| + | The primary novelty of this project lies in its **Hybrid Dual-Channel Sensor Architecture**. Instead of relying on a single data path, the flame sensor is evaluated simultaneously through two distinct subsystems: | ||
| + | 1. A **Digital Safety Path** linked directly to a high-priority hardware interrupt line. | ||
| + | 2. An **Analog Measurement Path** processed via the ADC. | ||
| + | This creates a fail-safe paradigm: the acoustic alarm bypasses any software delay or loop blockage to guarantee immediate warning, while the analog loop calculates the spatial presence of the threat to dynamically orchestrate physical suppression. | ||
| + | |||
| + | ==== Justification of PM Laboratory Functionalities ==== | ||
| + | The architecture incorporates core concepts from three foundational PM laboratories: | ||
| + | * **Laboratory 1 & 2 (Digital I/O):** Used to actuate the isolated relay module on pin **PD4** (utilizing an active-low sinking configuration suitable for the lab's relay board) and driving the visual status LED on **PB5**. | ||
| + | * **Laboratory 3 (External Interrupts):** Implemented via **INT0** on pin **PD2**. It processes the digital output (DO) of the flame sensor on a falling edge to instantly trigger the emergency buzzer on **PD3**, guaranteeing deterministic real-time response. | ||
| + | * **Laboratory 6 & 7 (Analog-to-Digital Converter - ADC):** Implemented on channel **ADC0 (PC0)** using an AVCC reference and a prescaler of 128. It quantifies the light intensity in the infrared spectrum to distinguish between ambient environmental lighting and an active flame threat. | ||
| + | * **Laboratory 5 (Timers & PWM):** Utilizes **Timer 1 (16-bit)** configured in **Fast PWM Mode (Mode 14)** with `ICR1` acting as TOP to generate a precise **50 Hz** frequency (20ms period). This hardware-driven signal operates on pin **PB1 (OC1A)** to seamlessly position the servo motor. | ||
| + | |||
| + | ==== Project Skeleton & Functional Interaction ==== | ||
| + | The software layout is divided into explicit hardware initialization blocks and a single, low-latency execution loop: | ||
| + | |||
| + | <code> | ||
| + | +-----------------------------------------------------------------------+ | ||
| + | | Hardware Initialization | | ||
| + | | (ADC_init() | PWM_init() | INT0_init() | sei()) | | ||
| + | +-----------------------------------------------------------------------+ | ||
| + | | | ||
| + | v | ||
| + | +-----------------------------------------------------------------------+ | ||
| + | | Main Loop [while(1)] | | ||
| + | +-----------------------------------------------------------------------+ | ||
| + | | 1. Sample raw IR intensity from PC0 (ADC0). | | ||
| + | | 2. Evaluate threshold criteria (valoare_foc < 400). | | ||
| + | +-----------------------------------------------------------------------+ | ||
| + | | | | ||
| + | [Fire Detected: FALSE] [Fire Detected: TRUE] | ||
| + | | | | ||
| + | v v | ||
| + | +------------------------------------+ +------------------------------------+ | ||
| + | | - Pull PD4 LOW (Activate Relay) | | - Pull PD4 HIGH (Deactivate Relay) | | ||
| + | | - Pull PD3 HIGH (Maintain Buzzer) | | - Pull PD3 LOW (Silence Buzzer) | | ||
| + | | - Increment Servo position | | - Snap Servo back to Bisectore | | ||
| + | | (Sweep 0° to 120° dynamically) | | (60° Rest Position) | | ||
| + | +------------------------------------+ +------------------------------------+ | ||
| + | | | | ||
| + | +---------------------> [_delay_ms(20)] <----+ | ||
| + | | | ||
| + | v | ||
| + | (Repeat Loop) | ||
| + | </code> | ||
| + | |||
| + | === Asynchronous Interruption Event === | ||
| + | Independent of the flow chart above, if pin **PD2** drops to 0V at any microsecond, the CPU stops execution instantly: | ||
| + | <code> | ||
| + | ISR(INT0_vect) { | ||
| + | stare_alerta = 1; | ||
| + | PORTD |= (1 << PD3); // FORCES BUZZER ON IMMEDIATELY | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | === Validation === | ||
| + | System verification was carried out systematically: | ||
| + | * **Logic Validation:** Probed with an oscilloscope/multimeter on pin `PD4` to verify that state toggles matched the active-low transistor network of the relay module. | ||
| + | * **Timing Validation:** Verified via the built-in logic analyzer that the Timer 1 configuration outputs an exact pulse width between $1\,\text{ms}$ (`OCR1A = 2000`) and $1.66\,\text{ms}$ (`OCR1A = 3333`), ensuring safe physical operation within bounds. | ||
| + | |||
| + | ==== Sensor Calibration ==== | ||
| + | The infrared phototransistor module required hardware-software co-calibration to avoid false positives caused by laboratory overhead fluorescent lighting: | ||
| + | * **Hardware Sizing:** The onboard LM393 potentiometer was trimmed under normal ambient conditions until the onboard status LED turned off, isolating the digital output (**DO**) to trigger only when exposed to highly dense IR spectrums (e.g., a lighter flame within 30cm). | ||
| + | * **Software Mapping:** Through iterative trial testing, an empirical ADC threshold of **400** units was established. Ambient room light sits safely at $700 - 900$ units ($3.5\text{V} - 4.5\text{V}$), whereas an active flame drops the analog readout sharply under $300$ units ($1.5\text{V}$), providing a robust noise-margin buffer. | ||
| + | |||
| + | ==== Optimizations ==== | ||
| + | * **Why & Where:** To completely avoid standard CPU processing delays when driving mechanical parts, the servo sweep was optimized via **Hardware-driven PWM**. Instead of bit-banging pins or calling blocking delays, modifying the `OCR1A` register lets the internal timer handle the waveform generation autonomously. | ||
| + | * **Memory Optimization:** Global variables are minimized, and critical state indicators (such as `stare_alerta`) are decorated with the `volatile` qualifier. This prevents the compiler from erroneously optimizing the variable into a CPU register, ensuring accurate cross-boundary access between the background ISR and the foreground main loop. | ||
| + | |||
| + | ==== Video Demo & Explanations ==== | ||
| + | > Directly access the official project demonstration video hosted on the university's cloud platform here: | ||
| + | > [[ https://ctipub-my.sharepoint.com/:v:/g/personal/patricia_bratu_stud_acs_upb_ro/IQD1YnXKKr1bT7-sRjXw5bfBAZzRhBom3UHN_MiHRUU0xuM?nav=eyJyZWZlcnJhbEluZm8iOnsicmVmZXJyYWxBcHAiOiJPbmVEcml2ZUZvckJ1c2luZXNzIiwicmVmZXJyYWxBcHBQbGF0Zm9ybSI6IldlYiIsInJlZmVycmFsTW9kZSI6InZpZXciLCJyZWZlcnJhbFZpZXciOiJNeUZpbGVzTGlua0NvcHkifX0&e=bmzSTt | 🎬 Click Here to Watch: Fire Suppression System Demo ]] | ||
| + | |||
| + | * **VIDEO:** Demonstrates system startup. The servo automatically aligns itself to the central **$60^\circ$ bisector** point, remaining at idle. The buzzer and water pump are silent. | ||
| + | Link to the project repository https://github.com/PatriciaBratu/Fire-Detection-and-Suppression-System.git | ||