Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include "DHT.

h"
int speakerPin = 9;
int length = 0.2;
int smokeA0=A5;
int sensorThres=460;
int buzzer=10;

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(smokeA0 ,INPUT);
pinMode (speakerPin,OUTPUT);
Serial.begin(9600);
dht.begin();
}
void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Methane Gas ");


Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(speakerPin,HIGH);
}

delay(100);
pinMode (speakerPin,OUTPUT);
// Wait for 10 minutes between measurements.
delay(4000);
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) ) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if (h>=97){
digitalWrite(speakerPin,HIGH);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print("%\t");
delay(1000);
}
if(t>=30){
digitalWrite(speakerPin,HIGH);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("C ");
Serial.println();
}
}

You might also like