Arduino DHT11 Temperature & Humidity Sensor Project

DHT sensor line

The DHT sensor line (DHT11/22) is one of the most commonly used in many electronic projects, ranging from home weather stations to plant automation systems, due to its simplicity and compactness as a temperature/humidity sensor. Although the more accurate and expensive DHT22 may be substituted (with some changes in the code), the DHT11 sensor module will be used in this project. With a basic 3-pin interface, the DHT11 sensor that will be used in this project is not the standalone 4-pin sensor version but rather, a 3-pin module that has a built-in capacitor & pull-up resistor, hence eliminating the need for additional components when building this circuit. Therefore, when interfaced with an Arduino board, the DHT11 sensor module can directly be connected to a digital pin which processes and feeds the serial data from the sensor to the microcontroller, for us to read.

In this DIY PCBA project, the temperature and humidity data from the DHT11 sensor will be displayed on a 0.96″ 128×64 OLED (organic light-emitting diode) display for us to visibly read. An advantage of using an i2c OLED display compared to other display types is that it only requires a 4-wire connection to the Arduino board and with a wide variety of libraries, it can be programmed with ease. A noticeable feature of an OLED display is its clarity, sharpness and visual quality of texts, figures & images that it can display.

Altogether, this is a fairly simple circuit project that is suitable for absolute beginners as it only requires a few components and some basic coding skills. However, for those who are more advanced, this project can definitely be improved upon and upgraded to add more features such as wireless communication (RF, LoRa, Bluetooth PCB, Wi-Fi, etc), RTC (real-time clock) data, additional sensor data (altitude, atmospheric pressure, gas concentrations, etc) and many other features. In order to realize this project, you will need to purchase components:

  • Arduino Nano (other Arduino-compatible boards will work)
  • USB cable (compatible with the Arduino board)
  • Breadboard
  • Male-Male Jumper Wires (7)
  • 0.96″ 128×64 i2c OLED Display
  • DHT11 Sensor Module


If you are using a different development board, it may require a different type of breadboard. For this project, FS Technology is utilizing an Arduino Nano, which necessitates the use of a breadboard. However, if an Arduino Uno is being used instead, the jumper wires can be directly plugged into the board pins, eliminating the need for the breadboard. Despite the change in board, the wiring for the DHT11 sensor module and OLED display to the Arduino board remains consistent. Furthermore, the wiring diagram for the DHT11 temperature and humidity sensor circuit is provided below.

  • DHT11 Sensor Module: Connect the signal (S) pin of the sensor to D2, the positive (+) pin to +5v and the negative (-) pin to GND.
  • OLED: Connect SDA (serial data) to A4, SCL/SCK (serial clock) to A5, VDD/VCC (supply voltage) to +5v and GND to GND.
  • Now, you can plug in your Arduino board via the USB cable to the computer.
DHT11 Temperature & Humidity Sensor

Project Code

#include <Wire.h> 

#include <Adafruit_GFX.h> 

#include <Adafruit_SSD1306.h> 


#define screen_width 128 

#define screen_height 64

#define OLED_RESET 4 

Adafruit_SSD1306 display(screen_width, screen_height);


#include “DHT.h”

#define DHTPIN 2

#define DHTTYPE DHT11



 void setup() {



 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);




 void loop() {





 display.setCursor(0, 15);


 display.setCursor(80, 15);


 display.setCursor(110, 15);

 display.print(” C”);


 display.setCursor(0, 35);


 display.setCursor(80, 35);


 display.setCursor(110, 35);




About the code

  • One of the advantages of working with an i2c OLED display is the incredible amount of support that is available online, in the form of open-source libraries, that can greatly assist in programming the display from the Arduino IDE. In this project, the Adafruit SSD1306 and GFX libraries are the main two libraries that are utilized to interface the OLED display with the Arduino and since all the setup information is already configured in the library files, basic commands are used within the IDE, simplifying the use of the display. If you do not have these libraries downloaded and installed to your IDE, you may run into compilation errors so please ensure that you have the latest library versions installed in the Arduino IDE.
  • The code starts off with defining the libraries needed for setting up the OLED display: Wire, Adafruit SSD1306 and Adafruit GFX. These are necessary for the OLED to function with the Arduino.
  • In the second block, several parameters relating to the OLED display are defined, which includes the screen width and height (128 x 64 pixels) and the OLED reset pin (A4).
  • Next, the libraries required for the DHT11 sensor to interface with the Arduino are defined, which species the ‘DHT’ library in particular. The digital pin that the DHT sensor is connected to on the Arduino board (digital pin 2 – D2) is additionally defined alongside the particular model of DHT sensor we are utilizing, the DHT11 sensor.
  • Now, the void setup section is introduced, one of the two essential functions in every Arduino code. This is where we start up the DHT11 sensor (dht.begin()) as well as the OLED display and before proceeding into the void loop section, the OLED display is cleared from any previous visuals (display.clearDisplay()).
  • In terms of the void loop section, the main part of the code which continuously repeats (in a loop) as long as there is power to the Arduino board, it mainly consists of OLED-specific functions that first sets the text size, text colour and cursor (where we want text to print on the OLED). Subsequently, we command the OLED to print lines of text at various places on the display, which is mainly the temperature (in degrees Celsius) and humidity (%) information that is read by the DHT11 sensor. Just through the use of these simple commands that have been produced from the libraries defined, we are able to easily print any information to the display.
  • With the delay function at the very end of the code, it is set to update the OLED display every 2000 milliseconds with the latest data read from the sensor. However, you may alter this timing depending on how often you would like to receive up-to-date information directly from the sensor.


With a fundamental understanding of this project and the basic principles that are involved in interfacing a sensor to an OLED display, there are certainly a multitude of ways which this project can be upgraded and improved upon. Most commonly, a setup like this can be integrated into a much larger weather station project by possibly adding on more sensors, a larger display, wireless capabilities, a case, etc. As demonstrated by this project, just by familiarizing yourself with some of the Arduino libraries that are available to use, it then becomes relatively effortless to code your very own weather station. A future project may involve the wireless transmission of such weather data from one microcontroller board to another in order to monitor a remote environment or centrally control an autonomous system. Nevertheless, projects like this are excellent to introduce hobby electronics to an absolute beginner and can very well also be targeted toward a more experienced PCBA manufacturer who may want to explore other aspects of electronics. 

DIY Electronics Project Blog

Arduino UNO Interrupt Timer

Arduino UNO Interrupt Timer The Timer is a feature embedded in every microcontroller and has certain functions regarding the passage of time. The Timer function

Read More »