This post shows how to build a temperature and relative humidity measurements station using Arduino and DHT11/DHT22 sensor where the measured values of the temperature and the humidity are displayed on 128×64 OLED screen with SSD1306 driver. (OLED: Organic Light-Emitting Diode)
The SSD1306 OLED used in this post projects is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode or I2C mode) such as soldering, placing jumpers …. To see how to connect the SSD1306 OLED with Arduino read the post below:
Interfacing Arduino with SSD1306 OLED display
I used Adafruit SSD1306 OLED library to simplify the connection of the Arduino with the screen and Adafruit DHT library for the connection between the Arduino and the DHT11/DHT22 sensors. Both libraries can be downloaded through Arduino IDE Library Manager of manually from the links below (after downloading, unzip the folder and place it in Arduino libraries folder, for example C:\Program Files\Arduino\libraries)
Adafruit SSD1306 OLED library — direct link
Adafruit DHT library — direct link
We also need Adafruit graphics library:
Adafruit GFX library — direct link
Related Projects:
Arduino interfacing with DHT11 sensor and LCD
Arduino with DHT22 sensor and LCD
Hardware Required:
- Arduino board
- SSD1306 OLED screen (128×64 Pixel)
- DHT11/DHT22 temperature and humidity sensor
- 4.7k ohm resistor
- Breadboard
- Jumper wires
Interfacing Arduino with SSD1306 OLED and DHT11 sensor:
Circuit connections are shown below where:
SSD1306 OLED GND goes to Arduino GND (ground)
SSD1306 OLED VDD to Arduino 5V
SSD1306 OLED SDA pin (serial data) to pin A4 (Arduino UNO I2C SDA pin)
SSD1306 OLED SCK pin (serial clock) to pin A5 (Arduino UNO I2C SCL pin)
SSD1306 OLED RES pin (reset) to Arduino pin 4
DHT11 data pin to Arduino pin 8
(DHT11 sensor = RHT01 sensor)
Arduino Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // Arduino with SSD1306 OLED and DHT11 relative humidity and temperature sensor. #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> // Include DHT library code #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); #define DHTPIN 8 // DHT11 data pin is connected to Arduino pin 8 #define DHTTYPE DHT11 // DHT11 sensor is used DHT dht(DHTPIN, DHTTYPE); // Configure DHT library char temperature[] = "00.0 C"; char humidity[] = "00.0 %"; void setup(void) { // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) // init done dht.begin(); // Initialize the DHT library delay(1000); // Clear the display buffer. display.clearDisplay(); display.drawFastHLine(0, 32, SSD1306_LCDWIDTH, WHITE); display.setTextSize(1); display.setTextColor(WHITE, BLACK); display.setCursor(10, 5); display.print("DHT11 TEMPERATURE:"); display.setCursor(19, 37); display.print("DHT11 HUMIDITY:"); display.display(); } void loop() { // Read humidity byte RH = dht.readHumidity(); //Read temperature in degree Celsius byte Temp = dht.readTemperature(); temperature[0] = Temp / 10 + 48; temperature[1] = Temp % 10 + 48; humidity[0] = RH / 10 + 48; humidity[1] = RH % 10 + 48; display.setCursor(46, 20); display.print(temperature); display.setCursor(46, 52); display.print(humidity); display.drawRect(71, 20, 3, 3, WHITE); // Put degree symbol ( ° ) display.display(); delay(1000); } |
The video below shows the simulation of the project with Proteus ISIS:
Proteus simulation file download (use it with version 8.6 or higher):
Arduino + SSD1306 OLED + DHT11
Interfacing Arduino with SSD1306 OLED and DHT22 sensor:
Circuit diagram is shown below.
(DHT22 sensor = AM2302 sensor = RHT03 sensor)
Arduino Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | // Arduino with SSD1306 OLED and DHT22 relative humidity and temperature sensor. #include <Wire.h> // Include Wire library (required for I2C devices) #include <Adafruit_GFX.h> // Include Adafruit graphics library #include <Adafruit_SSD1306.h> // Include Adafruit SSD1306 OLED driver #include <DHT.h> // Include DHT library code #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); #define DHTPIN 8 // DHT22 data pin is connected to Arduino pin 8 #define DHTTYPE DHT22 // DHT22 sensor is used DHT dht(DHTPIN, DHTTYPE); // Configure DHT library char temperature[] = " 00.0 C"; char humidity[] = " 00.0 %"; void setup(void) { delay(1000); // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) // init done dht.begin(); // Initialize the DHT library // Clear the display buffer. display.clearDisplay(); display.drawFastHLine(0, 32, SSD1306_LCDWIDTH, WHITE); display.setTextSize(1); display.setTextColor(WHITE, BLACK); display.setCursor(10, 5); display.print("DHT22 TEMPERATURE:"); display.setCursor(19, 37); display.print("DHT22 HUMIDITY:"); display.display(); } void loop() { // Read humidity int RH = dht.readHumidity() * 10; //Read temperature in degree Celsius int Temp = dht.readTemperature() * 10; if(Temp < 0){ temperature[0] = '-'; Temp = abs(Temp); } else temperature[0] = ' '; temperature[1] = (Temp / 100) % 10 + 48; temperature[2] = (Temp / 10) % 10 + 48; temperature[4] = Temp % 10 + 48; if(RH >= 1000) humidity[0] = '1'; else humidity[0] = ' '; humidity[1] = (RH / 100) % 10 + 48; humidity[2] = (RH / 10) % 10 + 48; humidity[4] = RH % 10 + 48; display.setCursor(40, 20); display.print(temperature); display.setCursor(40, 52); display.print(humidity); display.drawRect(71, 20, 3, 3, WHITE); // Put degree symbol ( ° ) display.display(); delay(1000); } |
Proteus simulation video:
Proteus simulation file download (use it with version 8.6 or higher):
Arduino + SSD1306 OLED + DHT22
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.