4778

Gas detector and Alerting device with Arduino Uno

Gas detector and Alerting device with Arduino Uno

Code

Note: This project should not be copied without my permission. 

//Included Libraries
#include "liquidcrystal.h"

//MACROS are defined here
const int resetPin = 12;
const int enablePin = 11;
const int d4 = 5;
const int d5 = 4;
const int d6 = 3;
const int d7 = 2;
LiquidCrystal lcd16x2(resetPin, enablePin, d4, d5, d6, d7);

//Global Variables are declared here
float Gas_Sensor;

void setup(void)
{
	//put your setup code here, to run once:
	lcd16x2.begin(16, 2);
	pinMode(0, INPUT);
	pinMode(6, OUTPUT);
}

void loop(void)
{
	//put your main code here, to run repeatedly: here, to run repeatedly:

	Gas_Sensor = analogRead(0);
	lcd16x2.setCursor(1 - 1, 1 - 1);
	lcd16x2.print(Gas_Sensor);
	if ((Gas_Sensor == 85)) 
	{
		lcd16x2.setCursor(1 - 1, 2 - 1);
		lcd16x2.print("No smoke");
	}
	else 
	{
		if (((Gas_Sensor > 85) && (Gas_Sensor < 115))) 
		{
			lcd16x2.setCursor(1 - 1, 2 - 1);
			lcd16x2.print("Little Smoke");
		}
		else
		{
			if (((Gas_Sensor > 85) && (Gas_Sensor < 115))) 
			{
				lcd16x2.setCursor(1 - 1, 2 - 1);
				lcd16x2.print("Little Smoke");
			}
			else
			{
				if (((Gas_Sensor > 116) && (Gas_Sensor < 400))) 
				{
					lcd16x2.setCursor(1 - 1, 2 - 1);
					lcd16x2.print("Alert!! Smoke");
					digitalWrite(6, true);
				}
				else
				{
				}
			}
		}
	}

	delay(0.1 * 1000);
}