adding arduino examples for DHT11, blink, and temperature sensor
This commit is contained in:
1 parent
492b275595
commit
a2882a5bff
26 files changed
+1129
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <DHT.h>
|
||||
|
||||
#define DHTPIN 22
|
||||
#define DHTTYPE DHT11 //Also can use for DHT22
|
||||
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Initializing sensor");
|
||||
dht.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(2000);
|
||||
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 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("deg Cel"));
|
||||
Serial.print(f);
|
||||
Serial.print(F("deg F Heat index: "));
|
||||
Serial.print(hic);
|
||||
Serial.print(F("deg Celsius "));
|
||||
Serial.print(hif);
|
||||
Serial.println(F("deg F"));
|
||||
}
|
||||
Reference in new issue
Block a user