You are on page 1of 5

Project Report

Dept. of Computer Science and


Engineering
Course title:Microcontroller, Computer
Peripherals and Interfacing
Course code: CSE-425

Submitted by Submitted to

Name: Ria Dutta Dr. Md. Johirul Islam


Id: 181311013 Assistant Professor
Semester: 11th Physics
Department of Computer Science &
Rajshahi University of
Engineering, Engineering &
Varendra University Technology

……………….………
Date of submission:
14-12-22 Signature
Project Report

Project Title: Air Quality monitoring and alert system using Arduino and gas
sensor(MQ-135).
Background: Most of the major cities in developing countries and most cities of
the developed countries are suffering from it. Thus to develop a real time air
quality and pollution monitoring system is critical. We have developed an
arduino based air pollution detector which combined a small-sized, minimum-
cost sensor to an arduino microcontroller unit. The advantages of the detector,
have a reliable stability, rapid response recovery and long-life features. It is
affordable, user-friendly, low-cost and minimum-power requirement hardware
which is appropriate for mobile measurement, as well as comprehensible data
collection. It has a processing software able to analyze, collected quality data
with high precision. Simple instrument which can be commercially utilized.

Code:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <LiquidCrystal.h> //Header file for LCD
const int rs=12, en=11, d4=5, d5=4, d6=3, d7=2; //pins of LCD connected
to Arduino
LiquidCrystal lcd(rs,en,d4,d5,d6,d7); //lcd function from LiquidCrystal

int threshold = 250; //Threshold level for Air Quality

void setup() {

DDRB = 0b00000011;//for(output)buzzer and led is connected as Output


from Arduino
DDRC = 0b00000000; //for(input) MQ135 is connected as INPUT to arduino

Serial.begin (9600); //begin serial communication with baud rate of 9600


lcd.clear(); // clear lcd
lcd.begin (16,2); // consider 16,2 lcd
}

uint16_t ReadADC(uint8_t ch)


{
ch= ch & 0b00000111; // select adc channel between 0 to 7

ADMUX = 0x40;
ADCSRA = 0b10000111;
ADCSRA|=(1<<ADSC); // start conversion

while(!(ADCSRA & (1<<ADIF))); // wait for ADIF conversion complete return

ADCSRA|=(1<<ADIF);

return(ADC);
}

void loop() {

int ppm = ReadADC(0); //read MQ135 analog outputs at A0 and store in


ppm PORTC = ppm;
Serial.print("Air Quality: "); //print message in serail monitor
Serial.println(ppm); //print value of ppm in serial monitor

st
lcd.setCursor (0,0); // set cursor of lcd to 1st row and 1 column
lcd.print("Air QualitY: "); // print message on lcd lcd.print(ppm);

// print value of MQ135

if (ppm > threshold) // check is ppm is greater than threshold or not


{
lcd.setCursor(1,1); //jump here if ppm is greater than threshold
lcd.print("AQ Level HIGH");
Serial.println("AQ Level HIGH");
PORTB|=(1<<PB1);// Turn ON LED
PORTB|=(1<<PB0) ; //Turn ON Buzzer
}
else
{
PORTB &=~(1<<PB1) ; //jump here if ppm is not greater than threshold
and turn off LED
PORTB &=~(1<<PB0) ; //Turn off Buzzer
lcd.setCursor(1,1);
lcd.print ("AQ Level Good");
Serial.println("AQ Level Good");
}
delay (200);
}

Circuit Diagram:

Description: First we define some header file .Then we define all the pins of
LCD that are connected to Arduino. Then we initialize LCD with this argument
LiquidCrystal lcd(rs,en,d4,d5,d6,d7).Now I define threshold for compare with
digital input value. In Void setup() function I use Data Direction Register(DDRX)
configures the data direction of port pins. Then making two pins of port B as
output pins which is PB0 and PB1 . For making PC0 pins of port C as input pins:
DDRC = 0b00000000 (in binary) or DDRC = 0x00 (in hexa).
Now clearing LCD with this command lcd.clear() and begin LCD with this
command .Now taking digital input and read in ReadAdc().After read from A0
store it in ppm. Then ppm convert with threshold value if ppm > threshold
then turn on LED and Buzzer and showing in LCD AQ Level is high. If not then
turn off LED and BUZZER and show in LCD AQ level is low.

OUTPUT:

You might also like