Smoking and alcohol are hazardous to health. Also, the consumption of alcohol is one of the reasons behind many anti-social incidents. That is why, smoking and consumption of alcohol is prohibited in many areas like it is prohibited in schools, colleges, hospitals and public transport like buses and trains. In fact, these kind of activities must be prohibited in all kind of public places. Despite rules of prohibition, there are many incidents when people are found not abiding the rules. In such case, for law enforcement, there must be some system to detect infringement of such laws and the authorities must be sent an alert at time. In this tutorial, an electronic system for the same has been designed.
A deployable electronic circuit is designed in this project which can detect the consumption of alcohol in public places by the smell of alcohol using MQ3 alcohol sensor. Similarly, the programmable circuit is equipped with MQ6 smoke sensor to detect smoking in a public place. The circuit has GSM-GPRS module interfaced to it which sends an SMS alert to police control room or authorized enforcement body about the location of the public place where alcohol consumption or the smoking is detected despite prohibition. The module is also equipped with a buzzer which starts sounding when alcohol consumption or smoking is detected. The buzzer acts as a warning and keeps sounding until the smell of alcohol or smoke is gone away. If despite buzzer alert for a long time, the smoking or alcohol is removed from the spot, an SMS alert is sent to the authorities which can reach at the spot to take appropriate actions.
The device is built around AVR Atmega 32. The controller is programmed to read values from the alcohol and smoke sensor and invoke the buzzer alarm and send an SMS via GSM module once the sensor values exceed the threshold limits. The GSM module used in the project is SIM900A. A character LCD is also interfaced in the device circuitry to monitor and calibrate the sensor values while testing of the device. The LCD module and code sections related to it can be removed later once the device is final tested and ready to deploy. The AVR controller is programmed and loaded with the executable code using AVR studio. The device built in this project is battery operated and uses a 12V battery to run. This is a portable device which can be reprogrammed when suitable and can be installed anywhere.
Fig. 1: Prototype of AVR Atmega32 based Alcohol and Smoking Detector
Components Required –
Fig. 2: List of components required for AVR Atmega32 based Alcohol and Smoking Detector
Block Diagram –
Fig. 3: Block Diagram of AVR Atmega32 based Alcohol and Smoking Detector
Circuit Connections –
The AVR Atmega 32 microcontroller is the sitting MCU in the device. The MQ3 alcohol sensor, MQ6 smoke sensor, SIM900A GSM module, buzzer and LCD display are interfaced to the controller IC to build the device. The circuit connections are as follow –
Power Supply – The controller as well as other modules of the circuit except the GSM module requires a 5V supply for their operation. The AVR Atmega 32 microcontroller, MQ3 alcohol sensor, MQ6 smoke sensor and character LCD, all work on 5V DC while GSM-GPRS module needs 12V supply. For supplying power to the circuit, a 12V battery is used. The power from the battery is regulated to 5V and 12V DC using 7805 and 7812 voltage regulator ICs respectively. The pin 1 of the voltage regulator ICs is connected to the anode of the battery and pin 2 of them is connected to the ground. The regulated voltage output is drawn from pin 3 of the ICs. An LED along with a 10K Ω pull-up resistor is also connected between common ground and output pin to get a visual hint of supply continuity. The output of the regulator ICs is connected to the supply pins of the respective modules and controller while their ground is connected with the common ground of the circuit.
AVR Atmega 32 – This is a 8-bit AVR RISC based microcontroller. It comes in a 40-pin package and has 2KB RAM, 32KB flash memory, 1KB EEPROM, 32 General Purpose Input Output (GPIO) pins, 8 10-bit ADC channels, One SPI, one UART and one TWI interface on-chip. The controller has three in-built timers of which 2 are 8-bit timers and one is a 16-bit timer. The controller operates up to a clock frequency of 16 MHz. By executing powerful instructions in a single clock cycle, the Atmega 32 achieves throughputs approaching 1 MIPS per MHz allowing the system designers to optimize power consumption versus processing speed. The controller comes available in 40-pin Dual Inline (DIP) Package. Check out the pin diagram and pin configuration of this AVR controller here.
In this project 13 GPIO pins of the controller are used of which 11 pins are used to interface the character LCD, 1 pin is used to interface the MQ3 alcohol sensor and 1 pin is used to interface the MQ6 smoke sensor. The RX and TX pins of the controller are used to interface the SIM900A GSM module.
16X2 LCD: The 16X2 LCD display is used to monitor the sensor values. It is interfaced with the AVR microcontroller by connecting its data pins to port B of the controller. The data pins DB0 to DB7 of the character LCD are interfaced to pins PB0 to PB7 of the AVR Atmega 32 respectively. The RS, RW and E pins of the LCD are connected to pins PC6, PC5 and PC4 of the AVR respectively. The circuit connections of the character LCD with the AVR controller are summarized in the following table –
Fig. 4: Table listing circuit connections between AVR ATMega32 and Character LCD
MQ6 Gas Sensor – The MQ6 gas sensor is a gas sensor module. The module has 4 pins for interfacing of which two pins are VCC and ground, one pin is analog output and one pin is digital pin via. The analog output pin of the module is used for detecting concentration level of gas leakage or smoke and is interfaced with the PA1 analog input pin of the AVR controller. The sensor measures the concentration of gas or smoke in ppm according to the following formulae –
Concen = 1036.5*R^-2.392 Where
Concen is the concentration of gas or smoke in ppm
R is the ratio of Rs the resistance of sensor to the R0 which is the resistance at 1000ppm at 20 degree Celsius and 65% humidity
The resistance of the sensor Rs is given by the formulae –
Rs = (1024/ADC_DATA-1)*RL where
Rs is the resistance of the sensor
ADC_DATA is digital reading ranging from 0 to 1023
RL is load resistance ranging from 10K to 40K ohms
The sensor from its analog pin outputs analog voltage which is proportional to the concentration of gas or smoke in ppm. The voltage is sensed by the controller and converted to a digital value using in-built ADC channel. For a fixed load resistance, the ADC reading is directly proportional to the concentration of gas in ppm.
In the datasheet the ratio of concentration to the sensor resistance is given. There is a graph given for normal condition of 20 degree Celsius and 65% humidity where Rs=R0 for the curve. This way the concentration of gas in ppm becomes equal to ADC reading. The AVR controller has 10-bit long ADC channels so, the ADC reading will range between 0 and 1023. In the project, the threshold value for sensing smoke is set to 200 which means that if the smoke concentration at a place exceeds 200 ppm, the controller will invoke alert.
MQ3 Sensor – MQ3 is an analog as well as digital sensor which detects alcohol consumption by the smell of the breath. The sensor has four pins – Analog Out, Digital Output, VCC and Ground. The VCC and ground are connected to the common VCC and Ground. The digital output pin is not used therefore is kept not connected. The output of the sensor is drawn from the analog output pin which is connected to the pin PA0 of the AVR controller. Like for the gas sensor, the controller senses analog voltage from the alcohol sensor and convert it to a digital reading using in-built ADC channel. Again since the ADC channels are 10-bit long in the AVR controller, the digitized reading varies from 0 to 1023. The threshold value for the alcohol detection is set to 700. Once the sensor value exceed 700, the controller invokes an alert.
SIM900A GSM module -SIM900A is a dual band GSM GPRS modem which operates at frequencies of 900 or 1800 MHz. The modem has on-board UART port to connect with a computer, SBC or controller. The modem has a configurable baud rate between 9600 and 115200. The baud rate can be set by passing AT commands to the modem through serial communication. This modem can be used to make voice calls, send and receive SMS and connect with mobile internet. The internet connectivity in the modem is facilitated via GPRS and it has a TCP/IP stack to handle internet connectivity. The modem has four terminals – RX, TX, VCC and ground. The VCC pin must be connected to a 12V DC supply. The modem has in-built voltage regulator, so it can be connected to any unregulated power source as well. The ground pin is connected to the common ground of the circuit. The RX and TX pins (for serial communication with the controller) are interfaced with the TX and RX pins of the AVR controller. The modem sends and receives data through UART.
Note that character LCD is interfaced in the circuit to monitor sensor values during calibration of the sensors and testing of the circuit for its intended application. The LCD module can be later removed and code sections written for it can be removed as well from the source code if the size of the circuit has to reduced.
How the circuit works –
The working of this device is simple and straight forward. Once the device is powered on by attaching a battery and is installed at a place, it loads the on-chip program. The AVR program starts reading data from the MQ3 alcohol sensor and the MQ6 smoke sensor. The analog output pins of both the sensors are interfaced with the controller and analog voltage is sensed by the controller from both the sensor modules. The analog voltage from both the sensors is converted to digital values using in-built ADC channels. There are 10-bit long ADC channels in the Atmega 32 controller, so the sensor readings vary from 0 to 1023. The digitized value for the smoke sensor is directly proportional to the concentration of smoke in parts per million. The threshold for this sensor is set 200, so at the concentration of smoke sensed by the sensor exceeds 200, the controller sends an alert and invoke buzzer alarm. The digitized value of the alcohol sensor is again proportional to the concentration of gas from the smell of the alcohol. The threshold value for this sensor is set to 700. Once the concentration of gas from the smell of alcohol exceeds value of 700, the controller sends an alert and invoke buzzer alarm. For testing alcohol sensor, Listerine cool mint liquid is used which has some content of alcohol.
Fig. 5: Image of AVR Atmega32 based Alcohol and Smoking Detector
While testing the circuit, the sensor values are passed to the LCD display where they can be monitored for proper calibration of the device.
On detection of Alcohol consumption by the MQ3 sensor at a place, an SMS alert is sent to a mobile number hard coded in the AVR code with text “ALCOHOL”. The same way, on detection of smoke by the MQ6 sensor at a place, an SMS alert is sent to a mobile number hard coded in the AVR code with text “SMOKE”. The location of the device instalment is assumed to be known otherwise, an ID or location of the device can also be sent via SMS to the authorized security personnel. At the same time, buzzer is activated which keeps sounding until alcohol or smoke is removed from the spot. The SMS is sent after a delay if the smoke or alcohol are still detected after the buzzer alarm.
Check out the programming guide to learn how AVR controller reads sensor values, compare them with threshold values and send an SMS alert and activate buzzer when the sensor values exceed their threshold limit.
Programming Guide –
In order to program Atmega 32 microcontroller, AVR studio 4 and GCC compiler are the software tools required. For learning how AVR studio 4 is used see the following tutorial –
Working with AVR Studio
First of all, separate header files are imported for the Initialization of lcd and ADC. The lcd.h, and adc.h are included for the LCD programming and reading data from sensor modules via ADC respectively.
#include <avr/lcd.h>
#include <avr/adc.h>
In order to make header files work, they must be copied to the following folder – C > WinAVR-20090313 > avr > include > avr and paste the downloaded header files in the folder.
Note that in the path WinAVR-20090313, 20090313 is a number appended to the installation folder. This number can be different in a different installation of the AVR Studio.
After importing the required libraries, variables and constants are defined to denote circuit connections with the sensors and GSM module. Some arrays are defined which store the AT commands that will be used to configure the GSM module and send SMS via it.
The main() function is called in which the controller pins interfaced with LCD are set as digital output while pins interfaced with sensors are set as analog input. The LCD and ADC channels are initialized using lcd_init() and adc_init() functions and some initial messages are passed on to the LCD display.
An infinite while loop is called in which LCD is configured to display sensor values and the sensor values are compared with threhold values to send appropriate SMS alert.
For sending the alert message to the security room from the GSM modem, the AT commands have to be passed to the modem. First the AT commands has to be used to set the baud rate of the modem for serial communication with the controller. The AT commands are passed in the following manner –
unsigned char cmd1[]={“AT”}
The following AT is used to check response from GSM modem whether the serial connection is established or not.
unsigned char cmd2[]={“AT+CMGF=1”};
Here AT+CMGF=1 command is used to configure the GSM modem in SMS text mode.
unsigned char cmd3[]={“AT+CMGS=”};
unsigned char cmd5[]={“094********”};
The command AT+CMGS is used to send the SMS text to the particular mobile number which is hard coded in the AVR program.
unsigned char cmd4[]={“Alert Alcohol detected”};
After configuring the GSM modem with AT commands, content of message which is to be sent is mentioned.
The sendSMS() function is defined to read elements of arrays containing AT commands required for sending SMS alerts and pass them to the GSM modem using serial communication. The serial communication between the modem and the controller is established by calling the usartinit() function. In usartinit() function, the baud rate for serial communication is declared and bits in USART control and status register B and C are set for synchronous communication. In USART control and status register B, Receiver Enable (bit 4) and transmitter enable (bit 5) are set high to enable receiver and transmitter pins. the USART control and status register C is set for writing by setting URSEL bit to high and both the character size bits UCSZ0 and UCSZ1 are set high to configure for 8-bit character transmission and reception.
Check out the complete code and try it out.
Project Source Code
###
//Program to #ifndef _ADC_H_ #define _ADC_H_ 1 #include
#include // This function is declared to initialize the Analog to Digital Converter of AVR microcontrollers void adc_init(void); //This function is declared to read the digital value of the ADC conversion int read_adc_channel(unsigned char channel); /*Function definations*/ void adc_init(void) { ADCSRA=(1< ###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.