You are currently viewing Arduino Weather Monitor using DHT 11 using OLED

Arduino Weather Monitor using DHT 11 using OLED

Arduino Weather Monitor using DHT 11 using OLed

Using DHT (Temperature and Humidity Sensor) and OLED

A Weather Station is considered as a technical method that allows measuring weather parameters based on atmospheric conditions. In this project, we design a  Real-Time weather station monitoring system using Arduino, DHT11” temperature and humidity sensor”, 0.96 OLED display.  DHT  measures the temperature and humidity of the environment with a very fair degree of accuracy. This project guides us with some features of the OLED display, how to connect it to the Arduino board, and how to write text, draw shapes, and display bitmap images. Finally, we’ll build a project that displays temperature and humidity readings.

 

Requirements :
● Computer with an internet connection
● Download and install Arduino IDE

Components

DHT11 Temperature and humidity sensor

1 nos

0.96 inch OLED display(SSD1306)

1 nos

Arduino UNO

1 nos

Jumper wires

1 nos

Hardware

ARDUINO UNO

Although there are many types of boards from arduino . Here we are going to be using the Arduino UNO as it is the most commonly used one. The arudino UNO has :

  • The operating voltage is 5V
  • The recommended input voltage will range from 7v to 12V
  • Digital input/output pins are 14
  • Analog i/p pins are 6
  • DC Current for each input/output pin is 40 mA
  • Flash Memory is 32 KB
  • SRAM is 2 KB
  • EEPROM is 1 KB
  • CLK Speed is 16MHz

Another wonderful feature of the arduino is the option of using a add-on boards to the arduino which comes as a module and they are known as “Shields”

Pin out diagram
Arduino UNO

DHT11 Temperature and Humidity Sensor

The DHT 11 is a low powered electronic device with lets us get the value of the temperature and the moisture and it use 1 wire protocol

The three pins of the DHT 11 is the VCC , GND , and DATA pin and through the DATA pin will the information of the temperature and the humidity will be sent. DHT 11 is not the best temperature and humidity sensing module out in the market but it is reasonably accurate .It is about +-5% and +-2% accurate for temperature and humidity 

 

What is humidity?

Humidity is the amount of moisture content in the air , here we are checking the humidity as the percentage (sofor example if the DHT module is showing 60%, that means the amount of water vapor in the air is about 60%. In case if the DHT is showing 100%, indicates that the DHT module might not be working or if the DHT module is under water.

The world’s lowest recorded relative humidity value occurred at Coober Pedy in the South Australia desert when the temperature was 93 degrees and the dew point was minus 21 degrees producing a relative humidity of 1 percent. (source: ‘www.chicagotribune.com’)

0.96 inch OLED display(SSD1306)

Introducing the 0.96 inch OLED display

This is a 0.96″ inch OLED display which we can use to connect to an Arduino so we can display an output. We can interface using an SPI/I2C protocol. This is a very advanced module if you look in terms of features. It has HIGH brightness, HIGH viewing angles, LOW power consumption, and a very THIN form factor. It also has a very HIGH resolution (128*64 pixels). It doesn’t need a backlight like the LCD display. It takes around 0.06 W for normal operations.

The module we are using here has 4 pins and we will be communicating with it using I2C protocol with the Arduino.
there are models that come with an extra RESET pin /There are also ones that communicate with SPI protocol.

Pin Wiring to Arduino Uno Vin 5V GND GND SCL A5 SDA A4

Circuit Diagram

Wire up the DHT 
With Arduino

 

STEP1:

CONNECTING  0.96 inch OLED display 

Because the OLED display uses I2C communication protocol, wiring is very simple. You just need to connect to the Arduino Uno I2C pins as shown in the table below.

PinWiring to Arduino Uno

OLED Vin         5V

OLED GND      GND

OLED SCL        A5

OLED SDA       A4

STEP2: CONNECTING A THREE PIN DHT11

  •   DHT11 VCC -> Arduino Vcc
  •  DHT11 Signal -> Arduino Digital Pin 7
  •  DHT11  GND -> Arduino GND

Getting started with Arduino

Before starting any project, we need to interface Arduino with a computer. So we have to write and compile code for the Arduino to execute, as well as providing Arduino to function with the computer.

Installing The Arduino Software Package On Windows

Download a version of Arduino software suitable for your version of Windows from Arduino website / superkitzs.com. After downloading, check the instructions below to install the Arduino Integrated Development Environment (IDE).

Download Arduino IDE

 

Connect your Arduino Uno board with an A B USB cable; sometimes this cable is called a USB printer cable.

In order to program the board, the USB connection with the PC is necessary to program the board and not just to power it up. The Arduino Uno is capable of withdrawing power from either the USB or an external power supply. Connect the board to your computer using the USB cable. The green power LED (labelled PWR) should go on.

If you used the Installer, as soon as you connect your board the Windows – from XP up to 10 – will install drivers automatically

If the board is not properly recognized when the zip package is downloaded and expanded, please follow the procedure below.

  • START menu> CONTROL PANEL MENU
  • From the control panel, check for System and Security
  • Select system
  • Select Device Manager from the System window
  • Select open port named “Arduino UNO (COMxx)”, under Ports (COM & LPT). If there is no COM & LPT section, check “Other Devices” for “Unknown Device”.
  • Choose the “Update Driver Software” option by right-clicking on the “Arduino UNO (COmxx)” port
  • Navigate to the “Browse my computer for Driver software” option.
  • Choose the driver file named “arduino. inf”, located in the “Drivers” folder of the Arduino Software download (not the “FTDI USB Drivers” sub-directory). If you are using an old version of the IDE (1.0.3 or older), Choose the Uno driver file named “Arduino UNO.inf”, If an old version of the IDE (1.0.3 or older) is used
  • Thus the windows driver installation is completed

Install DHT11 Library for Arduino IDE

 

 1.Install DHT11 as ZIP file in Arduino IDE.

DHT11 library is available as a downloadable ZIP.

  • Download DHT11 Library
  • In the Arduino IDE, select to Sketch > Include Library > Add .ZIP Library from the drop-down list in menu
  • Choose the library zip file you have already downloaded.
  • Return to the Sketch > Include Library menu at the bottom of the drop-down menu. Now it’s ready to be used in your sketch. In your Arduino sketches directory, the zip file will already have been expanded in the libraries folder.

2.Install Adafruit_SSD1306 as ZIP file in Arduino IDE

  • Repeat the above process for the Adafruit_SSD1306 library is available as a downloadable ZIP.
  • Download Adafruit_SSD1306 Library by clicking the button: Download Adafruit_SSD1306 Library

 3.Install Adafruit_GFX as ZIP file in Arduino IDE

  • Repeat the above steps for the Adafruit_GFX library is available as a downloadable ZIP.
  • Download Adafruit_GFX Library by clicking the button: Download Adafruit_GFX Libray
  • Download Adafruit_GFX library

.

Select your board type  : Arduino Uno and port

Choose  Tools | Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Press CNTRL + A & press DELETE to clear the Arduino IDE page

Upload the program

After that click on the “Upload” button. Then we can  see the RX and TX LEDS on the board flashing. The message “Done uploading.” will appear  if the uploading is success

 

Sketch Code

#include "DHT.h"
#define DHT11Pin 7
#define DHTType DHT11
//OLED
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

DHT HT(DHT11Pin,DHTType);
float humi;
float tempC;
float tempF;

//OLED define
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(9600);
  //For DHT11
  HT.begin();
  //For OLED I2C
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display(); //Display logo
  delay(1000); 
  display.clearDisplay();
}

void loop() {
 delay(1000);
 humi = HT.readHumidity();
 tempC = HT.readTemperature();
 tempF = HT.readTemperature(true);

 Serial.print("Humidity:");
 Serial.print(humi,0);
 Serial.print("%");
 Serial.print(" Temperature:");
 Serial.print(tempC,1);
 Serial.print("C ~ ");
 Serial.print(tempF,1);
 Serial.println("F");

 display.clearDisplay();
 oledDisplayHeader();
 

 oledDisplay(3,5,28,humi,"%");
 oledDisplay(2,70,16,tempC,"C");
 oledDisplay(2,70,44,tempF,"F");
 
 display.display(); 
 
}
void oledDisplayHeader(){
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(0, 0);
 display.print("Humidity");
 display.setCursor(60, 0);
 display.print("Temperature");
}
void oledDisplay(int size, int x,int y, float value, String unit){
 int charLen=12;
 int xo=x+charLen*3.2;
 int xunit=x+charLen*3.6;
 int xval = x; 
 display.setTextSize(size);
 display.setTextColor(WHITE);
 
 if (unit=="%"){
   display.setCursor(x, y);
   display.print(value,0);
   display.print(unit);
 } else {
   if (value>99){
    xval=x;
   } else {
    xval=x+charLen;
   }
   display.setCursor(xval, y);
   display.print(value,0);
   display.drawCircle(xo, y+2, 2, WHITE);  // print degree symbols (  )
   display.setCursor(xunit, y);
   display.print(unit);
 }
 
} 

Output

You should see the humidity and temperature readings displayed at one second intervals.

You should see the humidity and temperature readings displayed at on OLED,

Leave a Reply