Temperature Logger Codes
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include <DHT22.h>
|
||||
|
||||
#define DHTPIN 2
|
||||
#define DHTTYPE DHT22
|
||||
|
||||
DHT22 dht(DHTPIN);
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("Hello, ESP32!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
float h = dht.getHumidity();
|
||||
float t = dht.getTemperature();
|
||||
float f = dht.getTemperature(true);
|
||||
|
||||
if (isnan(h) || isnan(t) || isnan(f)) {
|
||||
Serial.println(F("Failed to read from DHT sensor!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("{ \"tempC\" : ");
|
||||
Serial.print(t);
|
||||
Serial.print(", \"tempF\" : ");
|
||||
Serial.print(f);
|
||||
Serial.print(", \"tempH\" : ");
|
||||
Serial.print(h);
|
||||
Serial.println(" }");
|
||||
|
||||
delay(1000); // this speeds up the simulation
|
||||
}
|
||||
Reference in New Issue
Block a user