/* Sketch to display humidity and temperature Written by R. Jordan Kreindler, J Sketch: November 27,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 can be easily converted to Fahrenheit. */ #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 #define 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 float cTemp = 0.0; // Holds Centigrade temperature results as an integer //float centigradeTemp = 0; // The Centigrade temperature float fTemp = 0; // Will hold the calculated Fahenheit temperature int delay1 = 4000; // The time between text displays void setup() { u8g2.begin(); dht.begin(); //Start the DHT22 sensor } void loop() { u8g2.setFont(u8g2_font_7x14_mf); // Set Font 10 pixels high u8g2.drawStr(42,10, "RH:"); // Display resolution is 128 x 64 humidity = round(dht.readHumidity()); u8g2.setCursor(70, 10); u8g2.print(humidity); u8g2.setFont(u8g2_font_courR24_tf); // Set Font u8g2.drawStr(02, 41, "C"); u8g2.setCursor(30,41); cTemp = dht.readTemperature(); u8g2.print(cTemp); u8g2.drawStr(30, 41, " "); u8g2.drawStr(02, 62 , "F"); fTemp = cTemp * 9.0 / 5.0 + 32.0; u8g2.setCursor(30,62); u8g2.print(fTemp); delay(2000); u8g2.drawStr(30, 62, " "); u8g2.sendBuffer(); }