/*
Instructor's demo on FSO
Vs.
ESP32 Tutorial - DHT11/DHT22 (Temperature and Humidity Sensor)
From https://www.youtube.com/watch?v=K98h51XuqBE
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
*/
// Import library
// #include <DHT.h>
#include <DHT_U.h>
// Initialize library
// PIN 23 yellow wire, DHT22 sensor
// DHT dht(23, DHT22);
DHT_Unified dht(23, DHT22);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Buit-in LED
pinMode(2, OUTPUT);
// Initialize object
dht.begin();
// delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
// Reusable data structure
sensors_event_t event;
// Get temp
dht.temperature().getEvent(&event);
// Store in variable
float celsius = event.temperature;
// Convert to F
float fahrenheit = (celsius * 1.8) + 32;
Serial.print("Temperature is ");
Serial.println(fahrenheit);
// LED on for 1/10 second
digitalWrite(2, HIGH);
delay(100);
// LED off
digitalWrite(2, LOW);
// float temp = dht.readTemperature(true);
// float humidity = dht.readHumidity();
// Serial.print("Temp: ");
// Serial.print(temp);
// Serial.println("F");
// Serial.print("Humidity: ");
// Serial.print(humidity);
// Serial.println("%");
// delay(2000); // Get new temp every 2 seconds
delay(5000); // Get new temp every 5 seconds
// delay(60000); // new temp every 60 seconds / 1 minute
}