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

Alcohol Monitoring and Alarm System with ATmega32 and LCD Display using Analog MQ-3 Sensor

963
Mark as Favourite

In this project, we will learn How to make an Alcohol Monitoring and Alarm System with AVR ATmega32 Microcontroller and LCD Display using Analog MQ-3 Sensor. Here, we will interface an Analog MQ-3 Alcohol Sensor with ATmega32 microcontroller and we will display the Analog MQ-3 Alcohol Sensor value in 16X2 Alphanumeric LCD Display. Also, we will compare the output of Analog MQ-3 Alcohol Sensor value with a threshold value continuously and when the Analog MQ-3 Alcohol Sensor output value is greater than the threshold value, the buzzer will start beeping.

Since, the output of the Analog MQ-3 Alcohol 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-3 Alcohol Sensor in the Alphanumeric LCD Display. Also, the ATmega32 microcontroller will compare the output of Analog MQ-3 Alcohol Sensor value with a threshold value(here the threshold value is 700) continuously and when the Analog MQ-3 Alcohol 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 cotton dipped in Alcohol/Spirit near Analog MQ-3 Alcohol Sensor and we will see the changes in the output of Analog MQ-3 Alcohol Sensor in the Alphanumeric LCD Display 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-3 Alcohol Sensor Board
Rs. 210.00
1pc
Rs.210.00
RG1602A 16X2 Alphanumeric LCD Green
Rs. 150.00
1pc
Rs.150.00
1 to 1 Connector-Female to Female
Rs. 4.00
1pc
Rs.4.00
10 to 10 FRC Female to Female Connector
Rs. 15.00
6pc
Rs.90.00
TOTAL Rs.1664.00

Circuit Diagram

C Program

Fullscreen
 

//**************************************************************//
//System Clock                           :1MHz
//Software                                   :Atmel Studio 6
//LCD Data Interfacing                :8-Bit
//**************************************************************//

#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         LCD_DATA_PORT         PORTB
/*Defines a macro for the lcd.h header File. LCD_DATA_PORT is the microcontroller PORT Register to which the data pins of the LCD are connected. Default PORT Register for data pins in lcd.h header file is PORTA*/

#define         LCD_CONT_PORT         PORTD
/*Defines a macro for the lcd.h header File. LCD_CONT_PORT is the microcontroller PORT Register to which the control pins of the LCD are connected. Default PORT Register for control pins in lcd.h header file is PORTB*/

#define         LCD_RS         PD0
/*Defines a macro for the lcd.h header file. LCD_RS is the microcontroller Port pin to which the RS pin of the LCD is connected. Default Port pin for RS pin in lcd.h header file is PB0*/

#define         LCD_RW         PD1
/*Defines a macro for the lcd.h header file. LCD_RW is the microcontroller Port pin to which the RW pin of the LCD is connected. Default Port pin for RW pin in lcd.h header file is PB1*/

#define         LCD_EN         PD2
/*Defines a macro for the lcd.h header file. LCD_EN is the microcontroller Port pin to which the EN pin of the LCD is connected. Default Port pin for EN pin in lcd.h header file is PB2*/

#include<avr/lcd.h>
/*Includes lcd.h header file which defines different functions for all Alphanumeric LCD(8-Bit Interfacing Method). LCD 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         MQ3_SENSOR_REF         700
/*Defines the threshold value for MQ-3 Alcohol Sensor*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (data pins of LCD are connected)*/

DDRD=0x07;
/*PD0, PD1 and PD2 pins of PortD are declared output (control pins of LCD are connected)*/

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

int mq3_alcohol_sensor_output;
/*Variable declarations*/

lcd_init();
/*LCD initialization*/

adc_init();
/*ADC initialization*/

lcd_string_write(“ABLab Solutions”);
/*String display in 1st row of LCD*/

lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/

lcd_string_write(“www.ablab.in”);
/*String display in 2nd row of LCD*/

_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
/*Display stays for 2 second*/

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

lcd_command_write(0x01);
/*Clear screen*/

lcd_string_write(“MQ-3 Value:-“);
/*String display in 1st row of LCD*/

lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/

mq3_alcohol_sensor_output=read_adc_channel(0);
/*Reading MQ-3 Alcohol Sensor output from channel 0*/

lcd_number_write(mq3_alcohol_sensor_output,10);
/*MQ-3 Alcohol Sensor output value is displayed in 2nd row of LCD*/

/*Comparing MQ-3 Alcohol Sensor output with threshold to turn On or Off Buzzer*/
if(mq3_alcohol_sensor_output>MQ3_SENSOR_REF)
{

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

}
else
{

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

}

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

}

}
/*End of Program*/

  

//**************************************************************//
//System Clock                           :1MHz
//Software                                   :Atmel Studio 6
//LCD Data Interfacing                :8-Bit
//**************************************************************//

#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         LCD_DATA_PORT         PORTB
/*Defines a macro for the lcd.h header File. LCD_DATA_PORT is the microcontroller PORT Register to which the data pins of the LCD are connected. Default PORT Register for data pins in lcd.h header file is PORTA*/

#define         LCD_CONT_PORT         PORTD
/*Defines a macro for the lcd.h header File. LCD_CONT_PORT is the microcontroller PORT Register to which the control pins of the LCD are connected. Default PORT Register for control pins in lcd.h header file is PORTB*/

#define         LCD_RS         PD0
/*Defines a macro for the lcd.h header file. LCD_RS is the microcontroller Port pin to which the RS pin of the LCD is connected. Default Port pin for RS pin in lcd.h header file is PB0*/

#define         LCD_RW         PD1
/*Defines a macro for the lcd.h header file. LCD_RW is the microcontroller Port pin to which the RW pin of the LCD is connected. Default Port pin for RW pin in lcd.h header file is PB1*/

#define         LCD_EN         PD2
/*Defines a macro for the lcd.h header file. LCD_EN is the microcontroller Port pin to which the EN pin of the LCD is connected. Default Port pin for EN pin in lcd.h header file is PB2*/

#include<avr/lcd.h>
/*Includes lcd.h header file which defines different functions for all Alphanumeric LCD(8-Bit Interfacing Method). LCD 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         MQ3_SENSOR_REF         700
/*Defines the threshold value for MQ-3 Alcohol Sensor*/

int main(void)
{

DDRB=0xff;
/*All the 8 pins of PortB are declared output (data pins of LCD are connected)*/

DDRD=0x07;
/*PD0, PD1 and PD2 pins of PortD are declared output (control pins of LCD are connected)*/

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

int mq3_alcohol_sensor_output;
/*Variable declarations*/

lcd_init();
/*LCD initialization*/

adc_init();
/*ADC initialization*/

lcd_string_write(“ABLab Solutions”);
/*String display in 1st row of LCD*/

lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/

lcd_string_write(“www.ablab.in”);
/*String display in 2nd row of LCD*/

_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
/*Display stays for 2 second*/

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

lcd_command_write(0x01);
/*Clear screen*/

lcd_string_write(“MQ-3 Value:-“);
/*String display in 1st row of LCD*/

lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/

mq3_alcohol_sensor_output=read_adc_channel(0);
/*Reading MQ-3 Alcohol Sensor output from channel 0*/

lcd_number_write(mq3_alcohol_sensor_output,10);
/*MQ-3 Alcohol Sensor output value is displayed in 2nd row of LCD*/

/*Comparing MQ-3 Alcohol Sensor output with threshold to turn On or Off Buzzer*/
if(mq3_alcohol_sensor_output>MQ3_SENSOR_REF)
{

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

}
else
{

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

}

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

}

}
/*End of Program*/

Connection Guide

The step-by-step connection guide for Alcohol Monitoring and Alarm System with ATmega32 and LCD Display using Analog MQ-3 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 11 )

  • Connect PortB header with LCD data header in AVR Trainer Board-100 with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 11 )

  • Connect RS, RW & EN pins of LCD control header with PD0, PD1 & PD2 pins of PortD header respectively in AVR Trainer Board-100 with 1 to 1 Connectors.

    Steps - 3 ( 0f 11 )

  • Connect the 16X2 Alphanumeric LCD to the LCD header of AVR Trainer Board-100.

    Steps - 4 ( 0f 11 )

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

    Steps - 5 ( 0f 11 )

  • 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 - 6 ( 0f 11 )

  • 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 - 7 ( 0f 11 )

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

    Steps - 8 ( 0f 11 )

  • Switch on the power with the help of Power Switch of AVR Trainer Board-100.

    Steps - 9 ( 0f 11 )

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

    Steps - 10 ( 0f 11 )

  • Place cotton dipped in Alcohol/Spirit near the Analog MQ-3 Alcohol Sensor and see the output.

    Steps - 11 ( 0f 11 )

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

    Steps - 1 ( 0f 11 )

  • Connect PortB header with LCD data header in AVR Trainer Board-100 with a 10 to 10 FRC Female Connector.

    Steps - 2 ( 0f 11 )

  • Connect RS, RW & EN pins of LCD control header with PD0, PD1 & PD2 pins of PortD header respectively in AVR Trainer Board-100 with 1 to 1 Connectors.

    Steps - 3 ( 0f 11 )

  • Connect the 16X2 Alphanumeric LCD to the LCD header of AVR Trainer Board-100.

    Steps - 4 ( 0f 11 )

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

    Steps - 5 ( 0f 11 )

  • 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 - 6 ( 0f 11 )

  • 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 - 7 ( 0f 11 )

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

    Steps - 8 ( 0f 11 )

  • Switch on the power with the help of Power Switch of AVR Trainer Board-100.

    Steps - 9 ( 0f 11 )

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

    Steps - 10 ( 0f 11 )

  • Place cotton dipped in Alcohol/Spirit near the Analog MQ-3 Alcohol Sensor and see the output.

    Steps - 11 ( 0f 11 )

Downloads

Alcohol Monitoring and Alarm System with ATmega32 and LCD Display using Analog MQ-3 Sensor C File
  • 5 downloads
  • 4 Kb
Alcohol Monitoring and Alarm System with ATmega32 and LCD Display using Analog MQ-3 Sensor Circuit Diagram
  • 3 downloads
  • 86 Kb
Alcohol Monitoring and Alarm System with ATmega32 and LCD Display using Analog MQ-3 Sensor Hex File
  • 4 downloads
  • 2 Kb
Alphanumeric LCD Header File v1.0
  • 1479 downloads
  • 1 Kb
ADC Header File v1.0
  • 993 downloads
  • 2 Kb

Comments