/* Sketch to display humidity and temperature Written by R. Jordan Kreindler Sketch: November 9,2020 Uses a 0.96 inch OLED to display Humidity, as well as Fahrenheit and Centigrade room Temperatures. The DHT22 sensor provides Centigrade temperature values which are easily converted to Fahrenheit temperature values */ #include U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE); /* U8G2_R0 No rotation, landscape U8G2_R1 90 degree clockwise rotation // Moves us to portrait U8G2_R2 180 degree clockwise rotation U8G2_R3 270 degree clockwise rotation */ #include int DHTData = 3; // The data pin from the DHT22 is digital pin 3 DHT dht(DHTData, DHT22);// Define a DHT object, dht int humidity = 0; // Holds humidity results as an integer int cTemp = 0.0; // Holds Centigrade temerature results as a float int centigradeTemp = 0; // The Centigrade temperature after conversion to int int fahrenheitTemp = 0; // Will hold the converted to Fahenheit temperature int i = 0; // A for loop index int delay1 = 4000; // The time between text displays void setup() { u8g2.begin(); u8g2.setFont(u8g2_font_luRS14_te); // Set Font dht.begin(); //Start the DHT22 sensor } void loop() { u8g2.drawStr(02, 21, "RH:"); // Display resolution is 128 x 64 humidity = round(dht.readHumidity()); u8g2.setCursor(40, 21); u8g2.print(humidity); u8g2.drawStr(02, 42, "C:"); u8g2.setCursor(40,42); cTemp = dht.readTemperature(); fahrenheitTemp = cTemp * 9.0 / 5.0 + 32.0; u8g2.print(centigradeTemp); centigradeTemp = round(cTemp); u8g2.drawStr(02, 63 , "F:"); u8g2.setCursor(40, 63); u8g2.print(fahrenheitTemp); u8g2.sendBuffer(); } }