Compare commits
2 Commits
1df37cb910
...
c4edb43af6
Author | SHA1 | Date | |
---|---|---|---|
c4edb43af6 | |||
05ada31f0e |
@ -20,6 +20,10 @@ DHT dht(DHT_PIN, DHT_TYPE);
|
||||
|
||||
int sensorValue;
|
||||
long last_sample = 0;
|
||||
float hmid = 0; // humidity
|
||||
float temp = 0; // temperature
|
||||
float heat = 0; // heat index
|
||||
float airq = 0; // air quality / gas
|
||||
|
||||
void setup() {
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
@ -27,6 +31,12 @@ void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
dht.begin();
|
||||
Wire.begin(8); // join i2c bus with address #8
|
||||
Wire.onRequest(requestEvent); // register event
|
||||
}
|
||||
|
||||
void requestEvent() {
|
||||
Wire.write("he1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -38,25 +48,25 @@ void loop() {
|
||||
last_sample = now;
|
||||
if (OPERATION_BLINK_EN) {digitalWrite(LED_BUILTIN, HIGH);}
|
||||
|
||||
float h = dht.readHumidity();
|
||||
float t = dht.readTemperature();
|
||||
hmid = dht.readHumidity();
|
||||
temp = dht.readTemperature();
|
||||
|
||||
if (isnan(h) || isnan(t)) {
|
||||
if (isnan(hmid) || isnan(temp)) {
|
||||
Serial.println(F("Failed to read from DHT sensor!"));
|
||||
} else {
|
||||
float hi = dht.computeHeatIndex(t, h, false);
|
||||
heat = dht.computeHeatIndex(temp, hmid, false);
|
||||
Serial.print(F("Humidity: "));
|
||||
Serial.print(h);
|
||||
Serial.print(hmid);
|
||||
Serial.print(F("% Temperature: "));
|
||||
Serial.print(t);
|
||||
Serial.print(temp);
|
||||
Serial.print(F("°C Heat index: "));
|
||||
Serial.print(hi);
|
||||
Serial.println(F("°C "));
|
||||
Serial.print(heat);
|
||||
Serial.print(F("°C "));
|
||||
}
|
||||
|
||||
sensorValue = analogRead(MQ135_PIN);
|
||||
Serial.print("AirQuality=");
|
||||
Serial.print(sensorValue, DEC);
|
||||
airq = analogRead(MQ135_PIN);
|
||||
Serial.print("AirQuality: ");
|
||||
Serial.print(airq);
|
||||
Serial.println(" PPM");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user