Hello Readers, welcome to my Blog - A Blog For Bloggers By A Blogger. I'm Arun, an entrepreneur Blogger from India.

Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Smoke Sensor

357
Mark as Favourite

In this project, we will learn How to make an Smoke Monitoring and Alarm System with AVR ATmega32 Microcontroller and 7-Segment Display using Analog MQ-2 Sensor. Here, we will interface an Analog MQ-2 Smoke Sensor with ATmega32 microcontroller and we will display the Analog MQ-2 Smoke Sensor value in 4 multiplexed Common Anode 7-Segment Displays. Also, we will compare the output of Analog MQ-2 Smoke Sensor value with a threshold value continuously and when the Analog MQ-2 Smoke Sensor output value is greater than the threshold value, the buzzer will start beeping.

Since, the output of the Analog MQ-2 Smoke Sensor is analog in nature and these analog signals cannot be processed directly by the ATmega32 microcontroller. So, first this signal needs to be converted to digital value to be processed by the microcontroller. The conversion can be done with the help of ADC of the AVR ATmega32 microcontroller. After converting the analog signal to digital, the microcontroller will display the digital value of Analog MQ-2 Smoke Sensor in the 4 multiplexed Common Anode 7-Segment Displays. Also, the ATmega32 microcontroller will compare the output of Analog MQ-2 Smoke Sensor value with a threshold value(here the threshold value is 700) continuously and when the Analog MQ-2 Smoke Sensor output value is greater than the threshold value, at that time the ATmega32 microcontroller will send signal to buzzer and the buzzer starts beeping.

Now, we will place burning incense stick near Analog MQ-2 Smoke Sensor and we will see the changes in the output of Analog MQ-2 Smoke Sensor in the 7-Segment Displays and Buzzer.

Softwares Required

Hardwares Required

Name / Unit Price Quantity Total Price
AVR Trainer Board-100 with ATmega32
Rs. 730.00
1pc
Rs.730.00
AVR USB Programmer
Rs. 350.00
1pc
Rs.350.00
12V, 1A DC SMPS Adaptor
Rs. 130.00
1pc
Rs.130.00
Analog MQ-2 General Combustible Gas Sensor Board
Rs. 200.00
1pc
Rs.200.00
Quad 7-Segment Display Board
Rs. 200.00
1pc
Rs.200.00
1 to 1 Connector-Female to Female
Rs. 4.00
10pc
Rs.40.00
10 to 10 FRC Female to Female Connector
Rs. 15.00
2pc
Rs.30.00
TOTAL Rs.1680.00

Circuit Diagram

Smoke-Monitoring-and-Alarm-System-with-AVR-ATmega32-Microcontroller-and-7-segment-using-MQ-2-Sensor-Circuit-Diagram-1024x611

C Program

Fullscreen
 

//**************************************************************//
//System Clock                          :1MHz
//Software                                 :Atmel Studio 6
//**************************************************************//

#include<avr/io.h>
/*Includes io.h header file where all the Input/Output Registers and its Bits are defined for all AVR microcontrollers*/

#define           F_CPU          1000000
/*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/

#include<util/delay.h>
/*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/

#define           _7SEGMENT_PORT           PORTB
/*Defines a macro for the 7segment.h header File. _7SEGMENT_PORT is the microcontroller PORT Register to which the data pins of the 7-segment Display are connected. Default PORT Resister in 7segment.h is PORTB*/

#define           _7SEGMENT_TYPE           COMMON_ANODE
/*Defines a macro for the 7segment.h header File. _7SEGMENT_TYPE is the type of 7-segment Display (Common Cathode or Common Anode) we are interfacing. Default type of 7-segment display is Common Anode*/

#include<avr/7segment.h>
/*Includes 7segment.h header file which defines different functions for 7-segment display. 7segment header file version is 1.1*/

#include<avr/adc.h>
/*Includes adc.h header file which defines different functions for Analog to Digital Converter. ADC header file version is 1.1*/

#define           MQ2_SENSOR_REF          700
/*Defines the threshold value for MQ-2 Smoke Sensor*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (7-segment displays are connected)*/

DDRD=0x0f;
/*LSB pins of PORTD are declared output (display select pins 1, 2, 3 and 4 of Quad 7-segment Display are connected)*/

DDRC=0x01;
/*PC0 pin of PortC is declared output(Buzzer is connected)*/

int mq2_smoke_sensor_output;
/*Variable declarations*/

unsigned char temp;
/*Variable declarations*/

adc_init();
/*ADC initialization*/

/*Starting of infinite loop*/
while(1)
{

mq2_smoke_sensor_output=read_adc_channel(0);
/*Reading MQ-2 Smoke sensor value*/

temp=mq2_smoke_sensor_output/1000;
/*Getting 1000th digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying 1000th digit of MQ-2 Smoke sensor output value in 7-segment display1*/

PORTD=0x01;
/*7-segment display1 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output/100;
/*Getting 1000th and 100th digit of MQ-2 Smoke sensor output value*/

temp=temp%10;
/*Getting 100th digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying 100th digit of MQ-2 Smoke sensor output value in 7-segment display2*/

PORTD=0x02;
/*7-segment display2 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output/10;
/*Getting 1000th, 100th and 10th digit of MQ-2 Smoke sensor output value*/

temp=temp%10;
/*Getting 10th digit of Smoke MQ-2 sensor output value*/

display_7segment(temp);
/*Displaying 10th digit of MQ-2 Smoke sensor output value in 7-segment display3*/

PORTD=0x04;
/*7-segment display3 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output%10;
/*Getting unit digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying unit digit of MQ-2 Smoke sensor output value in 7-segment display4*/

PORTD=0x08;
/*7-segment display4 is On*/

_delay_ms(10);
/*Display stays for 10ms*/

/*Comparing MQ-2 Smoke Sensor output with threshold to turn On or Off Buzzer*/
if(mq2_smoke_sensor_output > MQ2_SENSOR_REF)
{

PORTC=0x01;
/*Buzzer is On*/

}
else
{

PORTC=0x00;
/*Buzzer is Off*/

}

}

}
/*End of Program*/

  

//**************************************************************//
//System Clock                          :1MHz
//Software                                 :Atmel Studio 6
//**************************************************************//

#include<avr/io.h>
/*Includes io.h header file where all the Input/Output Registers and its Bits are defined for all AVR microcontrollers*/

#define           F_CPU          1000000
/*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/

#include<util/delay.h>
/*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/

#define           _7SEGMENT_PORT           PORTB
/*Defines a macro for the 7segment.h header File. _7SEGMENT_PORT is the microcontroller PORT Register to which the data pins of the 7-segment Display are connected. Default PORT Resister in 7segment.h is PORTB*/

#define           _7SEGMENT_TYPE           COMMON_ANODE
/*Defines a macro for the 7segment.h header File. _7SEGMENT_TYPE is the type of 7-segment Display (Common Cathode or Common Anode) we are interfacing. Default type of 7-segment display is Common Anode*/

#include<avr/7segment.h>
/*Includes 7segment.h header file which defines different functions for 7-segment display. 7segment header file version is 1.1*/

#include<avr/adc.h>
/*Includes adc.h header file which defines different functions for Analog to Digital Converter. ADC header file version is 1.1*/

#define           MQ2_SENSOR_REF          700
/*Defines the threshold value for MQ-2 Smoke Sensor*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (7-segment displays are connected)*/

DDRD=0x0f;
/*LSB pins of PORTD are declared output (display select pins 1, 2, 3 and 4 of Quad 7-segment Display are connected)*/

DDRC=0x01;
/*PC0 pin of PortC is declared output(Buzzer is connected)*/

int mq2_smoke_sensor_output;
/*Variable declarations*/

unsigned char temp;
/*Variable declarations*/

adc_init();
/*ADC initialization*/

/*Starting of infinite loop*/
while(1)
{

mq2_smoke_sensor_output=read_adc_channel(0);
/*Reading MQ-2 Smoke sensor value*/

temp=mq2_smoke_sensor_output/1000;
/*Getting 1000th digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying 1000th digit of MQ-2 Smoke sensor output value in 7-segment display1*/

PORTD=0x01;
/*7-segment display1 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output/100;
/*Getting 1000th and 100th digit of MQ-2 Smoke sensor output value*/

temp=temp%10;
/*Getting 100th digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying 100th digit of MQ-2 Smoke sensor output value in 7-segment display2*/

PORTD=0x02;
/*7-segment display2 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output/10;
/*Getting 1000th, 100th and 10th digit of MQ-2 Smoke sensor output value*/

temp=temp%10;
/*Getting 10th digit of Smoke MQ-2 sensor output value*/

display_7segment(temp);
/*Displaying 10th digit of MQ-2 Smoke sensor output value in 7-segment display3*/

PORTD=0x04;
/*7-segment display3 is On*/

_delay_ms(3);
/*Display stays for 3ms*/

temp=mq2_smoke_sensor_output%10;
/*Getting unit digit of MQ-2 Smoke sensor output value*/

display_7segment(temp);
/*Displaying unit digit of MQ-2 Smoke sensor output value in 7-segment display4*/

PORTD=0x08;
/*7-segment display4 is On*/

_delay_ms(10);
/*Display stays for 10ms*/

/*Comparing MQ-2 Smoke Sensor output with threshold to turn On or Off Buzzer*/
if(mq2_smoke_sensor_output > MQ2_SENSOR_REF)
{

PORTC=0x01;
/*Buzzer is On*/

}
else
{

PORTC=0x00;
/*Buzzer is Off*/

}

}

}
/*End of Program*/

Connection Guide

The step-by-step connection guide for Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Smoke Sensor is as follows:

  • Insert the DC Pin of 12V, 1A DC Adapter to the DC Socket of AVR Trainer Board-100.

    Steps - 1 ( 0f 9 )

  • Connect PortB header of AVR Trainer Board-100 with 7 Segment header of Quad 7-Segment Display with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 9 )

  • Connect the DIS1, DIS2, DIS3 and DIS4 pins of Display Select header of Quad 7-Segment Display with PD0, PD1, PD2 and PD3 pins of PortD header respectively of AVR Trainer Board-100 with 1 to 1 Connectors.

    Steps - 3 ( 0f 9 )

  • Connect the VCC, GND & O/P pins of Analog MQ-2 Smoke Sensor header to VCC, GND and PA0 pins of PortA header of AVR Trainer Board-100 respectively with 1 to 1 Connectors.

    Steps - 4 ( 0f 9 )

  • Connect the VCC, I/P & GND pins of Buzzer header with 5V header, PC0 pin of PortC header & GND header respectively in AVR Trainer Board-100 with a 1 to 1 Connectors.

    Steps - 5 ( 0f 9 )

  • Connect the ISP header of AVR Trainer Board-100 with AVR USB Programmer header of AVR USB Programmer with a 10 to 10 FRC Female Connector.

    Steps - 6 ( 0f 9 )

  • Connect the AVR USB Programmer to the PC/Laptop's USB Port directly or with the help of USB AM-AF Cable.

    Steps - 7 ( 0f 9 )

  • Download Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Sensor Hex file to AVR Trainer Board-100 with the help of SinaProg Hex downloader and AVR USB Programmer.

    Steps - 8 ( 0f 9 )

  • Place burning incense stick near the Analog MQ-2 Smoke Sensor and see the output.

    Steps - 9 ( 0f 9 )

  • Insert the DC Pin of 12V, 1A DC Adapter to the DC Socket of AVR Trainer Board-100.

    Steps - 1 ( 0f 9 )

  • Connect PortB header of AVR Trainer Board-100 with 7 Segment header of Quad 7-Segment Display with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 9 )

  • Connect the DIS1, DIS2, DIS3 and DIS4 pins of Display Select header of Quad 7-Segment Display with PD0, PD1, PD2 and PD3 pins of PortD header respectively of AVR Trainer Board-100 with 1 to 1 Connectors.

    Steps - 3 ( 0f 9 )

  • Connect the VCC, GND & O/P pins of Analog MQ-2 Smoke Sensor header to VCC, GND and PA0 pins of PortA header of AVR Trainer Board-100 respectively with 1 to 1 Connectors.

    Steps - 4 ( 0f 9 )

  • Connect the VCC, I/P & GND pins of Buzzer header with 5V header, PC0 pin of PortC header & GND header respectively in AVR Trainer Board-100 with a 1 to 1 Connectors.

    Steps - 5 ( 0f 9 )

  • Connect the ISP header of AVR Trainer Board-100 with AVR USB Programmer header of AVR USB Programmer with a 10 to 10 FRC Female Connector.

    Steps - 6 ( 0f 9 )

  • Connect the AVR USB Programmer to the PC/Laptop's USB Port directly or with the help of USB AM-AF Cable.

    Steps - 7 ( 0f 9 )

  • Download Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Sensor Hex file to AVR Trainer Board-100 with the help of SinaProg Hex downloader and AVR USB Programmer.

    Steps - 8 ( 0f 9 )

  • Place burning incense stick near the Analog MQ-2 Smoke Sensor and see the output.

    Steps - 9 ( 0f 9 )

Downloads

Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Sensor C File
  • 3 downloads
  • 4 Kb
Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Sensor Circuit Diagram
  • 3 downloads
  • 102 Kb
Smoke Monitoring and Alarm System with ATmega32 and 7-Segment Display using Analog MQ-2 Sensor Hex File
  • 2 downloads
  • 2 Kb
ADC Header File v1.0
  • 1177 downloads
  • 2 Kb
7 Segment Display Header File v1.0
  • 315 downloads
  • 2 Kb

Post a Comment