Microcontroller-Based Smoke Detector Schematic with Circuit Design Guide

smoke detector circuit diagram using microcontroller

Start by selecting an ATmega328P or STM32F103 as your core logic unit–both provide sufficient processing power while keeping power consumption below 50 mA in standby mode. An MQ-2 gas sensor set to 5V operation with a detection threshold adjusted via a 10 kΩ potentiometer ensures accurate response to combustion particles at concentrations as low as 300 ppm. Connect the sensor’s analog output to ADC pin A0 and sample at 10 Hz to avoid false triggers from ambient fluctuations.

Integrate a piezoelectric buzzer (model KPEG1212) driven by a 2N2222 transistor for audible alerts–configure a 2 kHz square wave via timer interrupts to reduce current draw while maintaining audibility up to 85 dB. For visual indication, use a common-cathode RGB LED with PWM control: set red (70% duty cycle) during alarm states, green (30%) for normal operation, and blue (100%) for diagnostic tests.

Power the system with a 9V alkaline battery regulated to 5V via LM7805, ensuring dropout voltage stays above 7.5V for stability. Add a 100 μF decoupling capacitor near the controller’s VCC pin to filter noise. Program the device to enter deep sleep mode between samples, reducing standby current to 2 μA, then wake on interrupt from the sensor or a push-button test switch wired to GPIO pin D2.

For remote monitoring, attach an HC-05 Bluetooth module (baud rate 9600) or an ESP-01 Wi-Fi module (operating in STA mode) to transmit status updates every 60 seconds. Format data as JSON packets with fields for sensor reading, battery voltage, and alarm state. Calibrate the system in a sealed 1 m³ chamber using controlled smoke from a candle extinction test, adjusting the sensor’s baseline resistance until the alarm triggers consistently at 10% opacity.

Building an Intelligent Fire Alarm System with a Central Processor

Select an 8-bit AVR or PIC processor like ATmega328P or PIC16F877A for optimal balance between performance and power consumption. These chips offer sufficient I/O pins, ADC channels, and interrupt capabilities for integrating sensors and alert mechanisms. Avoid ARM Cortex-M series unless extensive data processing is required–excessive features increase complexity without tangible benefits.

Key Hardware Components

  • MQ-2/Gas Sensor: Calibrate for methane, propane, or CO detection thresholds. Preheat for 24 hours before reliable readings; factor this into power budgeting. Connect to ADC pin via voltage divider to avoid exceeding VCC.
  • Buzzer/Piezo Speaker: Use a 5V active buzzer for simplicity. Drive with PWM output from the processor to control volume and pattern (e.g., 1kHz square wave for maximum audibility).
  • LED Indicators: Red for danger, yellow for warning (e.g., low battery), green for normal. Current-limiting resistors (220–330Ω) mandatory.
  • Power Supply: 9V battery with 7805 regulator for 5V rail. Add 1000μF capacitor to smooth voltage drops during alarm activation.

Configure the processor’s watchdog timer to reset the system every 2 seconds when idle, reducing power draw by ~40%. Disable brown-out detection to prevent false resets during transient sensor spikes. Use sleep modes between polling intervals (e.g., every 500ms); ATmega328P consumes only 0.1μA in deep sleep.

  1. ADC Readings:
    • Sample sensor at 10Hz (faster drains power; slower increases response latency).
    • Implement a 10-sample moving average to filter noise. Discard outliers exceeding ±15% of median.
    • Store baseline readings in EEPROM after initial 24-hour calibration to account for environmental variations.
  2. Threshold Logic:
    • Trigger alarm if reading exceeds baseline by 30% for 3 consecutive samples.
    • Secondary threshold: 50% above baseline activates immediate alert regardless of duration.
    • Include hysteresis: re-arm system only after readings drop 10% below primary threshold.

For wireless modules (e.g., HC-05 Bluetooth), limit transmission to 3 bytes per alert to minimize power. Transmit only upon confirmed danger states–continuous polling wastes battery. Use UART interrupt-driven code to avoid blocking the main loop. Example packet structure: [DEVICE_ID][ALERT_CODE][BATTERY_VOLTAGE].

Failure Mitigation

  • False Alarms: Cross-reference with temperature (LM35) to distinguish steam from combustion. Exclude readings where temp
  • Sensor Drift: Weekly self-test with internal 1.1V reference voltage. Log ADC errors in EEPROM; flag if deviation exceeds 5%.
  • Tamper Protection: Add microswitch under mounting bracket. Tampering triggers silent alert (e.g., SMS via GSM module) and local buzzer chirp every 10 seconds.
  • EMI Noise: Twist sensor signal wires; shield with grounded copper foil for runs >1m. Decouple processor pins with 0.1μF capacitors.

Choosing the Right Controller for Fire Alarm Systems

smoke detector circuit diagram using microcontroller

Opt for the ATmega328P for cost-sensitive, low-power applications requiring 8-bit processing. It delivers 16 MHz clock speed, 32 KB flash, and 2 KB SRAM, sufficient for interfacing with MQ-2 sensors and handling interrupts without latency. Its low standby current (0.1 μA) extends battery life in wireless nodes, while built-in timers simplify ADC sampling at 10 kHz–critical for detecting rapid combustion changes.

For projects needing 32-bit precision and Wi-Fi integration, the ESP32-S2 strikes the ideal balance. It packs dual-core Tensilica LX7 processors (240 MHz), 128 KB SRAM, and native support for MQTT over Wi-Fi, eliminating external modules. The ultra-low-power coprocessor retains sensor readings during deep sleep (5 μA), while the 12-bit ADC achieves 0.1% resolution–essential for discriminating CO levels below 10 ppm. Hardware-accelerated encryption secures cloud uploads without bogging down the main cores.

The STM32L0xx series excels in ultra-low-power deployments with sub-1.8V operation and a 12-bit ADC sampling at 1 Msps. Its Arm Cortex-M0+ core consumes 139 μA/MHz, with shutdown current under 0.3 μA. Built-in RTCC timestamps events during power losses, while 20 capacitive sensing channels enable tamper-proof housing designs. Pair with the STM32WL for LoRaWAN connectivity (15 km range) when cellular networks are unavailable–no extra radio ICs needed.

Connecting the MQ-2 Gas Module to a Controller Board

Begin by identifying the sensor’s pins: the MQ-2 module typically has four terminals–VCC, GND, DO (digital output), and AO (analog output). Verify the pinout with the module’s datasheet to avoid incorrect wiring. Most versions require 5V for stable operation, though some tolerate 3.3V.

Attach the VCC pin to the controller’s power rail–Arduino Uno’s 5V pin or ESP32’s VIN–ensuring the voltage matches the sensor’s specifications. Ground the module by connecting its GND pin to the board’s ground. For projects needing precise readings, skip the DO pin and wire AO directly to an analog input (e.g., A0 on Arduino). The AO pin outputs a voltage proportional to gas concentration, ideal for threshold-free measurements.

Add a 10kΩ pull-down resistor between the AO pin and ground if noise affects readings, especially in environments with electrical interference. For digital output (DO), connect it to a GPIO pin if a simple on/off signal suffices–this pin toggles high/low based on a preset threshold, adjustable via the module’s potentiometer. Calibrate the sensor in clean air before deployment: power it for 24–48 hours to stabilize baseline resistance.

Test the connection with a basic sketch reading analog values. Upload code that prints raw sensor data to the serial monitor to confirm functionality. Example: analogRead(A0) returns a 10-bit value (0–1023) on Arduino. Divide this by 1024 and multiply by the board’s reference voltage (e.g., 5V) to convert to volts. Adjust calculations if using 3.3V logic.

For reliable long-term operation, avoid exposing the sensor to extreme humidity (>95% RH) or temperatures (50°C). Mount the module away from direct airflow or heat sources to prevent false triggers. Consider a 100nF decoupling capacitor between VCC and GND near the sensor to filter power supply fluctuations.

Expand functionality by pairing the MQ-2 with other sensors (e.g., DHT11 for humidity compensation). Use interrupts for DO if response speed matters–attach it to a hardware interrupt pin to trigger actions (e.g., alerting) without polling. For battery-powered setups, reduce power consumption by powering the module via a transistor, switching it off between readings.

Implementing Interrupt-Driven Hazard Monitoring Logic

Configure external interrupts on GPIO pins tied to sensory alarms with pull-down resistors to prioritize immediate response. Use falling-edge detection for abrupt signal changes, ensuring the pin triggers only once per event. For AVR-based systems, set EICRA with ISC01 and ISC00 bits to 0b10; for ARM Cortex-M, use EXTI_RTSR and EXTI_FTSR registers to disable rising-edge interrupts. Latency should not exceed 50μs from signal drop to ISR execution–verify with an oscilloscope during hardware validation.

  • Disable nested interrupts in the ISR preamble to prevent re-entrancy issues.
  • Clear interrupt flags before exiting to avoid spurious triggers.
  • Limit ISR execution time to under 200μs to maintain system responsiveness.
  • Store event timestamps in a circular buffer with 1ms resolution for post-event analysis.
  • Use a watchdog timer to reset the system if the ISR hangs–set timeout to 500ms.

For dual-sensor redundancy, implement a voting mechanism in the ISR: require both sensors to trigger within a 10ms window before escalating. On PIC microcontrollers, use the INT0IE and INT1IE bits with INTCON; for ESP32, configure gpio_install_isr_service() and attach separate handlers to each pin. Test false positives by injecting noise via a signal generator at 10Hz–1kHz frequencies while monitoring ISR call frequency.

Debounce logic must filter transient spikes without delaying critical alerts. Use a hybrid approach:

  1. First interrupt: set a 3ms timer (hardware preferred).
  2. If the signal persists after timeout, increment a volatile counter.
  3. At 3 consecutive triggers, validate event; otherwise, discard as noise.
  4. Disable further interrupts during validation to prevent firmware overload.

For battery-operated devices, reduce power consumption by disabling non-critical peripherals in the ISR and re-enabling them in the main loop via a flag-based choreography.