Created
January 24, 2020 02:33
-
-
Save HackRanger/2bc28d869c3b8ce643df40caf570ef27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
#define DHTPIN 7 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
const int buzzer = 8; //buzzer to arduino pin 9 | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(F("DHTxx test!")); | |
pinMode(buzzer, OUTPUT); | |
dht.begin(); | |
} | |
void loop() { | |
delay(2000); | |
tone(buzzer, 5000); | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
float f = dht.readTemperature(true); | |
if (isnan(h) || isnan(t) || isnan(f)) { | |
Serial.println(F("Failed to read from DHT sensor!")); | |
return; | |
} | |
float hif = dht.computeHeatIndex(f, h); | |
float hic = dht.computeHeatIndex(t, h, false); | |
Serial.print(F("Humidity: ")); | |
Serial.print(h); | |
Serial.print(F("% Temperature: ")); | |
Serial.print(t); | |
Serial.print(F("°C ")); | |
Serial.print(f); | |
Serial.print(F("°F Heat index: ")); | |
Serial.print(hic); | |
Serial.print(F("°C ")); | |
Serial.print(hif); | |
Serial.println(F("°F")); | |
if(t < 29.0){ | |
noTone(buzzer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment