Introduction
Fire safety is a crucial aspect of building management, and early detection of fires can save lives and property. A fire alarm system is designed to detect fire or smoke and alert occupants, allowing them to evacuate promptly. In this article, we will discuss the development of a simple yet effective fire alarm system using a PIC microcontroller. This system can be used in residential, commercial, and industrial settings to enhance safety and security.
Overview of the Project
The fire alarm system utilizes a temperature sensor and a smoke sensor to detect the presence of fire. The PIC microcontroller processes the signals from these sensors and triggers an alarm if the temperature or smoke level exceeds a predefined threshold. Additionally, the system can display the temperature reading on an LCD and activate a buzzer or LED for an audible/visual alert.
Components Required
PIC Microcontroller (PIC16F877A): The central processing unit that controls the entire system.
Temperature Sensor (LM35): Used to measure the ambient temperature.
Smoke Sensor (MQ-2 or MQ-7): Used to detect the presence of smoke or harmful gases.
LCD Display (16x2): To display temperature readings and alert messages.
Buzzer/LED: To provide an audible or visual alert in case of fire detection.
Resistors, Capacitors, and Diodes: For circuit stability and protection.
Power Supply: To power the microcontroller and other components.
Connecting Wires: For making connections between different components.
Breadboard/PCB: For assembling the circuit.
Circuit Diagram
Below is a basic circuit diagram for the fire alarm system:
Temperature Sensor (LM35) --> PIC16F877A --> LCD Display
Smoke Sensor (MQ-2) --> --> Buzzer/LED
| |
Power Supply Reset Circuit
Temperature Sensor (LM35) to PIC Microcontroller:
The analog output of the LM35 is connected to an analog input pin of the PIC microcontroller (e.g., AN0).
The sensor’s Vcc and GND are connected to the power supply.
Smoke Sensor (MQ-2) to PIC Microcontroller:
The analog output of the smoke sensor is connected to another analog input pin of the PIC microcontroller (e.g., AN1).
The sensor’s Vcc and GND are connected to the power supply.
PIC Microcontroller to LCD Display and Buzzer/LED:
The output pins of the PIC16F877A are connected to the LCD display for temperature readings and to a buzzer/LED for alerting in case of fire detection.
Power Supply:
The PIC microcontroller, sensors, and other components are powered by a suitable DC power supply, typically 5V.
Working Principle
Temperature and Smoke Detection:
The LM35 temperature sensor continuously measures the ambient temperature, and the MQ-2 smoke sensor monitors the air for smoke or harmful gases.
Both sensors send analog signals proportional to the temperature and smoke level to the PIC microcontroller.
Signal Processing:
The PIC microcontroller reads the analog signals from the sensors and converts them to digital values using its ADC (Analog-to-Digital Converter).
The temperature value is displayed on the LCD. The system continuously checks if the temperature or smoke level exceeds predefined threshold values.
Fire Alarm Trigger:
If the temperature exceeds a certain limit (e.g., 60°C) or if the smoke sensor detects smoke, the microcontroller triggers the buzzer/LED.
The system can also display a warning message on the LCD, such as "FIRE DETECTED!"
Programming the PIC Microcontroller
The microcontroller is programmed using Embedded C or Assembly language. Below is an example of a basic code snippet in Embedded C for this project:
#include <pic16f877a.h>
#include <lcd.h> // Assumed LCD library for easy interfacing
#define TEMP_SENSOR_CHANNEL 0 // AN0
#define SMOKE_SENSOR_CHANNEL 1 // AN1
#define BUZZER RB0
// Function prototypes
void init_system();
unsigned int read_adc(unsigned char channel);
void delay(unsigned int ms);
void main() {
unsigned int temp_value = 0;
unsigned int smoke_value = 0;
float temperature = 0;
init_system();
while(1) {
temp_value = read_adc(TEMP_SENSOR_CHANNEL);
smoke_value = read_adc(SMOKE_SENSOR_CHANNEL);
// Convert ADC value to temperature (assuming 10mV per degree Celsius)
temperature = (temp_value * 5.0 / 1024.0) * 100.0;
lcd_clear();
lcd_set_cursor(1,1);
lcd_print("Temp:");
lcd_print_float(temperature);
lcd_print("C");
// Check for fire conditions
if (temperature > 60.0 || smoke_value > 400) { // Threshold values
BUZZER = 1; // Turn on buzzer
lcd_set_cursor(2,1);
lcd_print("FIRE DETECTED!");
} else {
BUZZER = 0; // Turn off buzzer
}
delay(1000);
}
}
void init_system() {
TRISB = 0x01; // Set RB0 as output for buzzer
PORTB = 0x00; // Initialize PORTB
lcd_init(); // Initialize LCD
ADCON1 = 0x80; // Set up ADC
BUZZER = 0; // Turn off buzzer
}
unsigned int read_adc(unsigned char channel) {
ADCON0 = (channel << 3); // Select ADC channel
ADCON0 |= 0x01; // Start conversion
while(ADCON0 & 0x02); // Wait for conversion to finish
return (ADRESH << 8) | ADRESL; // Return ADC value
}
void delay(unsigned int ms) {
unsigned int i, j;
for(i = 0; i < ms; i++)
for(j = 0; j < 1275; j++);
}
Explanation of the Code
TRISB: Configures PORTB pins as input or output.
TEMP_SENSOR_CHANNEL, SMOKE_SENSOR_CHANNEL: Define the ADC channels for the temperature and smoke sensors.
BUZZER: Represents the output pin connected to the buzzer.
ADCON0, ADCON1: Control registers for the ADC module in the PIC microcontroller.
read_adc(): A function to read the analog value from the specified ADC channel.
The main loop continuously reads sensor data, calculates the temperature, and checks for fire conditions. If a fire is detected, the buzzer is activated, and a message is displayed on the LCD.
Advantages of the System
Early Detection: Provides early detection of fire hazards, allowing timely evacuation and response.
Cost-Effective: Uses inexpensive and readily available components, making it affordable for various applications.
Scalability: The system can be easily scaled or modified to include additional features like data logging, remote alerts, or integration with a larger fire alarm network.
Conclusion
A Fire Alarm System using a PIC microcontroller is an essential safety tool that can be implemented in homes, offices, factories, and other buildings. By following the steps outlined in this article, you can build a simple yet effective fire alarm system that helps protect lives and property from the dangers of fire. This project demonstrates the practical application of microcontrollers in real-world safety systems and offers a foundation for more advanced fire detection solutions.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comments