Table of Contents
Introduction
Hello techies, welcome back to Techatronic. In this article, we are going to learn how to display the temperature and humidity on an SSD1306 OLED display using Arduino UNO and DHT11 temperature-humidity sensors.
The detailed circuit diagram for the project is given below but before starting please go through with the working of the DHT11 sensor once.
You can make more similar projects based on Arduino and also check out our E-book on Arduino having 10+ amazing projects with well-explained codes.
dht11 with arduino Working
- DHT11 sensor gives the values of temperature in degree Celcius and humidity in percentage.
- The values for both temperature and humidity can also be seen on the Serial monitor screen of the Arduino Software.
- You can open the serial monitor from the top right corner of your screen as shown in the screenshot below.
- In this dht11 with Arduino Tutorial, The OLED display is useful in displaying texts as well as graphics.
- It works with the I2C protocol as it has SDA and SCK pins. In the code, we have to set the size and color of the text which is going to be displayed on the OLED screen.
- The clearDisplay() function is used to remove all the text and reset the OLED screen.
- We use setCursor() function for adjusting the text on the screen so that it looks neat and clean.
- The values of the temperature and humidity keep updating automatically with time.
Components Required
- Arduino UNO board
- USB cable for uploading the code
- DHT11 temperature-humidity sensor
- SSD1306 OLED display
- Jumper wires
- Breadboard
Components Table
You can buy the whole components from the given link we have to share the amazon link. from where you can get a good discount on the components.
temperature humidity sensor Circuit Diagram
Connection Table
Arduino UNO | DHT 11 Sensor |
+5V | ( V ) VCC |
G, GND | ( G ) GND |
2 Pin | ( S ) OUT Pin |
Arduino UNO | SSD 1306 Oled Display |
+5V | VCC |
GND | GND |
A4 Pin ( SDA Pin ) | SDA Pin |
A5 Pin ( SCL Pin ) | SCL Pin |
dht11 Arduino code CodeMake the connections according to the diagram given above.
- Connect the 5 volts pin of the Arduino with the VCC pin of the DHT11 sensor and also with the VCC pin of the OLED display.
- Join the GND pin of the Arduino with the GND pin of the OLED display and also with the GND pin of the DHT11 sensor.
- Connect the signal pin of the DHT11 sensor with the digital-2 pin of the Arduino.
- Join the SCK and SDA pins of the OLED display with the SCK and SDA pins of the Arduino that are pin numbers analog-4 and analog-5.
- These pins are for serial communication between two devices. Arduino has a total of two pairs of I2C (SDA and SCK) pins. Arduino Tutorial series contains this important article too.
- You can read more about an OLED display from one of our articles on it. Connect a USB cable to the Arduino so that system starts working.
NOTE: Please upload the code which is given below to the Arduino board. Before compiling the code you have to install <SimpleDHT.h>, <SPI.h>, <Adafruit_GFX.h>, <Adafruit_SSD1306.h> these dht11 Arduino library to the IDE software. You can take a reference from here on how to add a zip library to the Arduino IDE software.
temperature humidity sensor Arduino Code
// TECHATRONIC.COM
// SimpleDHT LIBRARY LINK
// https://github.com/winlinvip/SimpleDHT
// Library SPI.h
// https://github.com/PaulStoffregen/SPI
// Library Adafruit_GFX.h
// https://github.com/adafruit/Adafruit-GFX-Library
// Library Adafruit_SSD1306.h
// https://github.com/adafruit/Adafruit_SSD1306
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SimpleDHT.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);
#define screen_width 128 // OLED display width, in pixels
#define screen_height 64 // OLED display height, in pixels
#define OLED_RESET 4
Adafruit_SSD1306 display(screen_width, screen_height);
void setup ()
{
Serial.begin(9600);
Serial.println("TEMPERATURE AND HUMIDITY");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop ()
{
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" H");
// DHT11 sampling rate is 1HZ.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(" TEMP. & HUMIDITY");
display.setCursor(0, 25);
display.print(" TEMPERATURE : ");
display.setCursor(90, 25);
display.print((int)temperature);
display.setCursor(0, 50);
display.print(" HUMIDITY : ");
display.setCursor(90, 50);
display.print((int)humidity);
display.display();
}
We hope that you like this project if so then try to make it by yourself once. Also, check our tutorials on Arduino and Raspberry Pi. If you have any doubts regarding this project then do inform us in the comments section below.
video sample
HAPPY LEARNING!
2 thoughts on “dht11 Sensor With SSD1306 OLED | dht11 with Arduino”