-
Notifications
You must be signed in to change notification settings - Fork 0
/
dht11_and_gassensor
52 lines (50 loc) · 1.17 KB
/
dht11_and_gassensor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Arudino_codes
some sensors code.
/*pre-installed library dht11 library
ledr is red led
ledg is green led*/
dht11 ht;
int ledr=6;
int ledg=7;
int buzzer=8;
int gas=A0;
int htpin=5;
int sensorvalue;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledr,OUTPUT);
pinMode(ledg,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(gas,INPUT);
}
void loop() {
ht.read(htpin);
float t=ht.temperature;
float h=ht.humidity;
Serial.println(t);
Serial.println(h);
sensorvalue=analogRead(gas);
if(sensorvalue>250 && t<38){
digitalWrite(ledr,HIGH);
digitalWrite(ledg,LOW);
digitalWrite(buzzer,LOW);
Serial.print(sensorvalue);
Serial.println("ppm");
Serial.println("smoke");}
else if(sensorvalue>200 && t>40){
digitalWrite(ledr,HIGH);
digitalWrite(ledg,LOW);
digitalWrite(buzzer,HIGH);
Serial.print(sensorvalue);
Serial.println("ppm");
Serial.println("Danger run fire and smoke");}
else{
digitalWrite(ledg,HIGH);
digitalWrite(ledr,LOW);
digitalWrite(buzzer,LOW);
Serial.print(sensorvalue);
Serial.println("ppm");
Serial.println("Nothing to worry sleep freely");}
delay(2000);
}