Fire Alarm System using AVR Microcontroller

Published  October 20, 2015   8
User Avatar Dilip Raja
Author
Fire Alarm System using AVR Microcontroller

In this project, we are going to make a Fire Alert System using ATMEGA8 microcontroller and fire sensor. Fire sensor can be of any type, however we are using IR (Infrared) based Fire Sensor. Although IR based Fire Sensors have some disadvantages mostly of inaccuracy, it is the cheapest and easiest way to detect fire.

 

IR Based Fire sensors have lesser sensing vision, so we are going to mount the fire sensor on a servo motor. The Servo will be making 180 degrees pendulum rotations. With the Fire sensor mounted on it, we get a 270+ degrees fire sensing vision. The servo will be rotating continuously thus giving a complete room fire alert system. For more accuracy we can add a smoke sensor to the system. With that we could get higher accuracy.

 

Circuit Components

Hardware:+5v power supply, Servo motor (sg90), ATMEGA8, BUZZER, Button, 10KΩ resistor, 1KΩ resistor, 220Ω resistor, 100nF capacitor, AVR-ISP PROGRAMMER.

Software: Atmel studio 6.1, progisp or flash magic.

 

Circuit Diagram & Working

AVR MIcrocontroller Based Fire Alarm Circuit Diagram

For the servo shaft to move left all the away we need to give 1/18 turn on ration, and for the shaft to rotate all the way to the left we need to give PWM with a duty ration of 2/18. We are going to program ATMEGA8 to give out a PWM signal which will rotate servo shaft to 180 and then to 0 after a certain delay.

 

During the complete time the Fire Sensor will be on and the controller will be on complete alert. If there is a fire, the sensor provides a high pulse this pulse when detected by controller it sets an alarm. The alarm will be turned off by pressing a reset button which is connected to it. [Also check: Fire Alarm Circuit using Thermister]

 

In atmega8 for three PWM channels, we have designated three pins. We can only take PWM output at these pins only. Since we are using PWM1 we should take PWM signal at OC1A pin (PORTB 1st PIN).  As shown in the circuit diagram, we are connecting the servo signal to OC1A pin. Here another thing is over three PWM channels, two are 8-bit PWM channels and one 16-bit PWM channel. We are going to use a 16-bit PWM channel here.

 

In ATMEGA there are couple of ways to generate PWM, they are

1. Phase correct PWM.

2. Fast PWM.

Here we are going to keep everything simple, So we are going to use FAST PWM method to generate the PWM signal.

 

First to choose the frequency of PWM, This depend on application usually, for a LED any frequency greater than 50Hz would do. For that reason we are choosing the counter clock 1MHZ.So we are choosing no prescalar.  A prescalar is a number which is so selected to get a lesser counter clock. For example if the oscillator clock is 8Mhz, we can chose a prescalar of ‘8’ to get a 1MHz clock for counter. The prescalar is selected based on frequency. If we want more time period pulses we have to chose higher prescalar.

 

Now to get the FAST PWM of 50Hz clock out of the ATMEGA, we need to enable the appropriate bits in “TCCR1B” register.

Timer Counter 1 Control Register

Here,

CS10, CS11, CS12 (YELLOW)—select the prescalar for choosing counter clock. The table for appropriate prescalar is shown in below table. So for prescaling one (oscillator clock=counter clock) .

so CS10=1,other two bits are zero.

Clock Select

RED (WGM10-WGM13):are altered to choose waveform generation modes, based on the table below, for fast PWM. We have WGM11, WGM12 and WGM12 are set to 1.

waveform generation

Now we know that PWM is a signal with different duty ration or different turn ON turn OFF times. Up until now we have chosen frequency and type of PWM. The main theme of this chapter lies in this section. For getting different duty ration, We are going to choose a value between 0 and 255 (2^8 because of 8 bit). Say we choose a value 180, as the counter start counting from 0 and reaches the value 180, the output response may be triggered. This trigger may be inverting or non inverting. That is the output can be told to pulled up on reaching the count, or it can be told to pulled down on reaching the count.

 

GREEN (COM1A1,COM1A0):This selection of pulling up or down is chosen by  CM1A0 and CM1A1 bits.

 

As shown in table, for the output to go high on compare and the output will stay high until max value. We have to choose inverting mode to do that, so COM1A0=1; COM1A1=1.

Compare Output Mode

As shown in below figure, OCR1A (Output Compare Register 1A) is the byte which stores the user chosen value. So if we change OCR1A=180, the controller triggers the change (high) when counter reaches 180 from 0.

OCR1A

OCR1A must be 19999-600 for 180 degree and 19999-2400 for 0 degree.

Code

#include <avr/io.h>

//header to enable data flow control over pins

#define F_CPU 1000000      

//telling controller crystal frequency attached

#include <util/delay.h>

//header to enable delay function in program

int main(void)

{

                                DDRB = 0xFF;

                             //putting portb as ouput. PWM0 ouput pin is at 3

                                DDRD = 0x00;

                             //taking portd as input for input commands from buttons.             

                TCCR1A |=(1<<WGM11)|(1<<COM1A1)|(1<<COM1A0);

                TCCR1B |=(1<<WGM12)|(1<<WGM13)|(1<<CS10);

                ICR1 =19999;    

while(1)

       {

                          if (i<500)

                        {

                                    OCR1A = 19999-600;//for every 500ms move servo to 180

                        }

                                    i++;

                        _delay_ms(1);

                        if (bit_is_set(PIND,0))

                        {

                                    PORTB|=(1<<PINB2);//is fire is sensed set the alarm.

                        }

                        if (bit_is_clear(PIND,1))

                        {

                                    PORTB&=~(1<<PINB2);

                        }

                       

                        if ((i<1000)&&(i>500))

                        {

                                    OCR1A = 19999-2400; // for every 500ms move servo to 0

                        }

                        if (i==1000)

                        {

                                    i=0;

                        }

            } }

Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Submitted by Taha on Sat, 05/07/2016 - 03:27

Permalink

Can you give me the hex file and project file of proteus.. Please

Submitted by Shakh on Fri, 04/13/2018 - 23:32

Permalink

How to use it using Proteus? Everything works except signal

Can you give me the hex file and project file of proteus.. Please
Or the initial value of i .