-
Notifications
You must be signed in to change notification settings - Fork 0
/
DHT11-DUST-SONIDO-MQ7.ino
126 lines (109 loc) · 4.49 KB
/
DHT11-DUST-SONIDO-MQ7.ino
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//DHT11*********************************************************************
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4
//DHT11*********************************************************************
//SONIDO********************************************************************
#define PIN_GATE_IN 2
#define IRQ_GATE_IN 0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A1
//SONIDO*******************************************************************
//DUST SENSOR***************************************************************
int pin = 7;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
//DUST SENSOR**************************************************************
//MQ7************************************************************
int adc_MQ = analogRead(A2);
//MQ7*************************************************************
//SONIDO***********************************************************
void soundISR()
{
int pin_val;
pin_val = digitalRead(PIN_GATE_IN);
digitalWrite(PIN_LED_OUT, pin_val);
}
//SONIDO*******************************************************************
void setup(){
//DHT11******************************************************************
Serial.begin(9600);
Serial.println(DHT11LIB_VERSION);
//DHT11******************************************************************
//DUST SENSOR**************************************************************
pinMode(7,INPUT);
starttime = millis();//get the current time;
//DUST SENSOR**************************************************************
//SONIDO*****************************************************************
// Configure LED pin as output
pinMode(PIN_LED_OUT, OUTPUT);
// configure input to interrupt
pinMode(PIN_GATE_IN, INPUT);
attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);
// Display status
Serial.println("Initialized");
//SONIDO************************************************************************
}
void loop(){
//DHT11*******************************************************************
int chk;
Serial.print("DHT11, \t");
chk = DHT.read(DHT11_PIN); // READ DATA
switch (chk){
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAT DATA
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
delay(1000);
//DHT11*********************************************************************
//DUST SENSOR***************************************************************
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
if ((millis()-starttime) >= sampletime_ms)//if the sampel time = = 30s
ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100
concentration = 3.531073446*(1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62); // using spec sheet curve
Serial.print("concentration = ");
Serial.print(concentration);
Serial.println(" particulas/L");
lowpulseoccupancy = 0;
starttime = millis();
//DUST SENSOR**************************************************************
//MQ7********************************************************************
float voltaje = adc_MQ * (5.0 / 1023.0);
float Rs=1000*((5-voltaje)/voltaje);
double monoxide =76.211*pow(Rs/1284, -1.663); // read analog input pin 0
Serial.println(monoxide); // prints the value read
Serial.println(" ppmv");
delay(1000); // wait 100ms for next reading
//MQ7****************************************************************
//SONIDO***************************************************************
int value;
// Check the envelope input
value = analogRead(PIN_ANALOG_IN);
// Convert envelope value into a message
//deje 21 dB como el minimo y calcule el valor de x de la ecuacion
//21=20*log(8/x) x~2.79
Serial.print(20*log(value/2.8));
Serial.print(" dB");
Serial.print('\n');
// pause for 1 second
delay(100);
//SONIDO************************************************************
}