Min menu


Project 34: arduino thermometer


Required Components 

The segments needed for this undertaking are as per the following 

  • Arduino Uno
  • Monochrome OLED 128X64

  • DHT22 Temperature and Humidity Sensor 

  • Associating wires 

  • Breadboard 

Circuit Diagram 

Most importantly, we will associate the OLED with the Arduino. The OLED can be associated with the Arduino in I2C just as SPI. The associations for interfacing the OLED in the I2C way are simpler yet SPI correspondence is quicker than the I2C. Thus, we will interface the OLED with the Arduino utilizing SPI. Make the associations of the OLED with the Arduino as follows: 

Associate the CS nail to the OLED to nail 10 to the Arduino 

Interface the DC nail to the OLED to nail 9 to the Arduino 

Interface the RST nail to the OLED to nail 8 to the Arduino 

Associate the D1 or CLK nail to the OLED to nail 11 to the Arduino 

Interface the D0 or DIN nail to the OLED to nail 13 to the Arduino 

We have associated the OLED to pins 13, 11, 10, 9, and 8 on the grounds that these pins are for SPI correspondence. Next, associate the DHT22 with the Arduino. The associations for DHT22 sensor with Arduino are as per the following: 

Associate the VCC on DHT22 to the 5V pin on the Arduino 

Associate the GND on the DHT22 to the GND on the Arduino 

Interface the information pin of the DHT22 to nail 7 to the Arduino

Arduino Code

#include "DHT.h"
#define DHTPIN 7 
#define DHTTYPE DHT22 
U8GLIB_SH1106_128X64 oled (13, 11, 10, 9, 8);  

void setup() 
   oled.setFont(u8g_font_fur14);   	//setting the font size
//Printing the data on the OLED   
oled.drawStr(20, 15, "Welcome");	
   oled.drawStr(40, 40, "To");
   oled.drawStr(5, 60, "DIYHACKING");  
}  while( oled.nextPage() );

void loop()
float h = sensor.readHumidity(); 		//Reading the humidity value
float t = sensor.readTemperature(); 		//Reading the temperature value
float fah = sensor.readTemperature(true);	//Reading the temperature in Fahrenheit
if (isnan(h) || isnan(t) || isnan(fah)) {		//Checking if we are receiving the values or not
    Serial.println("Failed to read from DHT sensor!");
  float heat_index = sensor.computeHeatIndex(fah, h);	//Calculating the heat index in Fahrenheit
  float heat_indexC = sensor.convertFtoC(heat_index);    //Calculating the heat index in Celsius
  oled.setFont(u8g_font_fub11);   	//setting the font size
//Printing the data on the OLED
   oled.drawStr(0, 15, "Temp: ");
   oled.drawStr(0, 40, "Hum: ");
   oled.drawStr(0, 60, "Hi: ");
   oled.setPrintPos(72, 15);     		//setting the dimensions to print the temperature
   oled.print(t, 0);
   oled.setPrintPos(72, 40);		//setting the dimensions to print the humidity
   oled.print(h, 0);     
   oled.setPrintPos(72, 60);		//setting the dimensions to print the heat index
   oled.print(heat_indexC, 0);
while( oled.nextPage() );