Weather Station Using Arduino and NodeMCU

Weather Station Using Arduino and NodeMCU © GPL3+

In this tutorial I am going to show you guys how to make an Arduino or NodeMCU based Weather Station using DHT11 or DHT22 and OLED Display

  • 499 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

In this tutorial I am going to show you guys how to make an Arduino or NodeMCU based Weather Station using DHT11 or DHT22 temperature and humidity sensor and display it using an OLED Display.

DHT11 vs DHT22

The DHT11 and DHT22 are both low-cost very basic and slow temperature and humidity sensors which can be used for basic data logging.

Despite being slower, they are very stable and consumes low power and provides relatively high measurement accuracy. The single-bus digital signal is output through a built-in ADC which is easy to read using any microcontroller. Single bus interface saves the I/O resources of any microcontroller board.

The operating voltage is between 3.3V to 5V and the sampling period for DHT11 is 1Hz or one reading every second and for DHT22 is 0.5Hz or one reading every two seconds. Hence, you can not query them more than once every second or two.

The DHT sensors are made of two parts, a capacitive humidity sensor and a Negative Temperature Coefficient or NTC temperature sensor (or thermistor).

The NTC temperature sensor is actually a variable resistor whose resistance decreases with increase in the temperature.

For measuring humidity, two electrodes with a moisture holding substrate between them is used. When the humidity changes, the conductivity of the substrate changes or in other words the resistance between these electrodes changes. This change in resistance is measured and processed and is sent to the microcontroller.

A very basic chip inside the sensor does the analog to digital conversion and spits out a digital signal which is read using a microcontroller.

Here is a comparison chart of the two sensors. Looking at this it is very clear that DHT22 outshines the DHT11 in every aspect.

However, if accuracy is your concern, and you are ready to pay a bit higher price, go for DHT22. Otherwise, DHT11 should be good enough for you.

OLED Display

OLED or organic light-emitting diode is a light-emitting diode (LED) in which the emissive electroluminescent layer is a film of organic compound (millions of small LED lights) that emits light in response to an electric current.

OLEDs are used to create digital displays in devices such as television screens, computer monitors, portable systems such as mobile phones, hand-held game consoles and PDAs. An OLED display works without a backlight because it emits visible light.

There are many types of OLED displays available in the market based on their:

  • Sizes
  • Color
  • Brands
  • Protocol
  • SPI (Serial Peripheral Interface) or I2C
  • Passive-matrix (PMOLED) or active-matrix (AMOLED) control scheme

To know more about OLED Display and to know how to connect multiple OLED Displays using TCA9548 multiplexer check out my tutorial number 7

OLED Display with Arduino and NodeMCU link is in the description below: https://www.youtube.com/watch?v=_e_0HJY0uIo

Lets have a closer at these two displays.

At the back of these displays there are heaps of SMD capacitors and resistors soldered on-board; but, since its an I2C device we only care about these 2 pins (SCL and SDA)

The display connects to Arduino using only four wires – two for power (VCC and GND) and two for data (serial clock SCL and serial data SDA), making the wiring very simple. The data connection is I2C (I²C, IIC or Inter-Integrated Circuit) and this interface is also called TWI (Two Wire Interface).

The on-board pins can be in different order, so always triple check before hooking it up to your project.

Operating voltage is between 3v to 5v but, it is best to use the guidance from the manufacturer's datasheet.

Sometimes we need to use 2 displays in our projects. So, how can we achieve this?

The trick is to have a configurable address on your display. This unit has a configurable address between 0x78 and 0x7A. Just by unsoldering the 0Ohm resistor from one side and hoking it up to the other side or just by putting a global solder we can change the address.

In picture these displays look very big. But, practically speaking they are tiny. They are made of 128 x 32/64 individual OLED pixels and do not require any back-light. Just have a look at this and see how small it is. Even though they are small they can be very useful in any electronic projects.

This is how an OLED Display is connected to either Arduino or NodeMCU.

Setup Using Arduino

The setup using either Arduino or NodeMCU is very simple.

We just need to connect the OLED to the I2C Pins and the Temperature and Humidity sensor to any one of the Digital pins.

In this setup I have connected the OLED to A5 and A4 and the Sensor to D8.

Now, lets look at the code. Lets start by including the DHT and OLED libraries.

Then, in the setup section we initialize the display and then in the loop section we loop through every 2 seconds and read the sensor and display the result on the OLED display.

Here is a quick demo using Arduino.

Setup Using NodeMCU

Same as the previous setup, the OLED display connects to the NodeMCU using D2 and D1 pins and the Sensor connects to the D3 pin.

The code starts by including the DHT and OLED libraries.

Then, in the setup section we initialize the display and then in the loop section we loop through every 2 seconds and read the sensor and display the result on the OLED display.

So, this is how the actual setup looks like.

The Board

So, this is how my board looks like in 2d and 3d.

There are 3 breakout boards in this 100cm x 100cm assembly. Each board can be used with either Arduino or NodeMCU and DHT11 or DHT22 sensor or sensor module.

The Board can be used with either NodeMCU or Arduino Nano.

Temperature and humidity readings can be collected using either a DHT11 or DHT22 Module or by using one of these sensors with a 10K resistor.

The bottom section of the board is for the OLED display. The attached gerber is bit different from what you see on screen. I made some modifications in the final version and moved the sensors a bit far from the microcontrollers.

Soldering

Since I care a lot about my Sensors and Microcontrollers I am not soldering them directly to the board. Instead I am soldering, female pin headers to the board which will house all the sensors and microcontrollers.

Just for the sake of this video I am soldering female pin headers on both sides for Arduino and NodeMCU. However, In your setup you will need either Arduino or NodeMCU.

Final Demo

Lets first test this with an Arduino.

Now, lets test this setup using a NodeMCU board.

Looks perfect, I am going to use this board in my next project where I will be sending Temperature and Humidity readings to my Raspberry Pi based home server where I will be storing it in a MySQL database, so stay tuned....

Thanks

Thanks again for checking my post. I hope it helps you.

If you want to support me subscribe to my YouTube Channel: https://www.youtube.com/user/tarantula3

Blog Posts:

1. DHT11 & DHT22: https://diyfactory007.blogspot.com/2021/09/temperature-and-humidity-monitor-using.html

2. OLED Tutorial: https://diyfactory007.blogspot.com/2018/07/oled-i2c-display-arduinonodemcu-tutorial.html

Video references:

1. DHT11 & DHT22: https://youtu.be/w5tBtHsl7b4

2. OLED Tutorial: https://www.youtube.com/watch?v=_e_0HJY0uIo

Gerber: https://drive.google.com/file/d/1H9noO2ppm0SM8HcJg1NWE2uTUJKw9SXH/view?usp=sharing

Schema: https://drive.google.com/file/d/1tWCxXBw3vzssVm6FtZDRI8ZIPCtmXp1t/view?usp=sharing

Code:

Code_With_OLED_Arduino : https://drive.google.com/file/d/1EEdhPuUiy8xWSD_s41iYAccTz8w-QF9C/view?usp=sharing

Code_With_OLED_NodeMCU : https://drive.google.com/file/d/1WFtdyu90gAqxhJq-Pur7w8fvXuuM85lt/view?usp=sharing

Code_With_PHP_NodeMCU : https://drive.google.com/file/d/1bT08x-h39NS1LdkCCH2F3ySG3hrht9U4/view?usp=sharing

Code_With_PHP_OLED_NodeMCU: https://drive.google.com/file/d/1ji5TEvLbhe3GJiDgQRowDws5PdZZXqf9/view?usp=sharing

Libraries:

"DHTStable.h" : https://github.com/RobTillaart/DHTstable

"SSD1306.h" : https://github.com/squix78/esp8266-oled-ssd1306

Adafruit display library: https://github.com/adafruit/Adafruit_SSD1306

Adafruit GFX library: https://github.com/adafruit/Adafruit-GFX-Library

Support My Work:

BTC: 1M1PdxVxSTPLoMK91XnvEPksVuAa4J4dDp

LTC: MQFkVkWimYngMwp5SMuSbMP4ADStjysstm

DOGE: DDe7Fws24zf7acZevoT8uERnmisiHwR5st

ETH: 0x939aa4e13ecb4b46663c8017986abc0d204cde60

BAT: 0x939aa4e13ecb4b46663c8017986abc0d204cde60

LBC: bZ8ANEJFsd2MNFfpoxBhtFNPboh7PmD7M2

Thanks, ca again in my next tutorial.

Code

Code_With_OLED_NodeMCU.inoArduino
/***************** DHT ******************/
#define DHTPIN D3
#include "DHTStable.h"        // DHT library test sketch for DHT22/DHT11 && Arduino "AUTHOR: Rob Tillaart"
                              // URL: https://github.com/RobTillaart/DHTstable
DHTStable DHT;                // Initialize the DHT Library
int HUM  = 0;
int TEMP = 0;
/***************************************/
/**************** OLED *****************/
#include <Wire.h>             // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h"          // Alias for `#include "SSD1306Wire.h"`
                              // URL: https://github.com/squix78/esp8266-oled-ssd1306
SSD1306  display(0x3c, 5, 4); // Initialize the OLED display using Wire library
/***************************************/

void setup()
{
  Serial.begin(115200);
  display.init(); // Initialising the UI will init the display too.
  display.flipScreenVertically();
}

void loop() 
{ 
  /****** For DHT22 *******/
  //int chk = DHT.read22(DHTPIN);
  /************************/
  /****** For DHT11 *******/
  int chk = DHT.read11(DHTPIN);
  /************************/
  HUM  = DHT.getHumidity();
  TEMP = DHT.getTemperature();
  
  display.clear();
  drawDHT(); 
  display.display();
  delay (2000);
}

/*************** Generate OLED Display ***************/
void drawDHT() 
{
  int x=0; int y=0;
  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(0 + x, 5 + y, "Hum");
  
  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(38 + x, y, "OUTDOOR");

  display.setFont(ArialMT_Plain_24);
  String hum = String(HUM) + "%";
  display.drawString(0 + x, 15 + y, hum);
  int humWidth = display.getStringWidth(hum);
  Serial.println(hum);

  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(96 + x, 5 + y, "Temp");

  display.setFont(ArialMT_Plain_24);
  String temp = String(TEMP) + "C";
  display.drawString(71 + x, 15 + y, temp);
  int tempWidth = display.getStringWidth(temp);
  Serial.println(temp);
}
Code_With_OLED_Arduino.inoArduino
/***************** DHT ******************/
#define DHTPIN 8
#include "DHTStable.h" // DHT library test sketch for DHT22/DHT11 && Arduino "AUTHOR: Rob Tillaart"
                       // URL: https://github.com/RobTillaart/DHTstable
DHTStable DHT;         // Initialize the DHT Library
int HUM  = 0;
int TEMP = 0;
/***************************************/
/**************** OLED *****************/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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(115200);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  };
}

void loop() 
{
  /****** For DHT22 *******/
  //int chk = DHT.read22(DHTPIN);
  /************************/
  /****** For DHT11 *******/
  int chk = DHT.read11(DHTPIN);
  /************************/
  HUM  = DHT.getHumidity();    // Read the humidity
  TEMP = DHT.getTemperature(); // Read the temperature

  /**** Display Data *****/
  Serial.print("Humidity");Serial.println(HUM);
  Serial.print("Temperature");Serial.println(TEMP);
  display.clearDisplay();
  oledDisplayHeader();
  oledDisplay(3,5,28,HUM,"%");  // Display humidity
  oledDisplay(2,70,16,TEMP,"C");// Display temperature 
  display.display();
  /************************/
  delay(2000); 
}

/*************** Generate OLED Header ***************/
void oledDisplayHeader()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print("Humidity");
  display.setCursor(60, 0);
  display.print("Temperature");
}

/*************** Generate OLED Display ***************/
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);
  };
}

Schematics

gerber_weather_station_v1_0_1_66CAdEtw4Q.zip
gerber_weather_station_v1_0_1_66CAdEtw4Q.zip

Comments

Similar projects you might like

Pocket Weather Station Using Arduino

Project tutorial by Tech Nuttiez

  • 3,817 views
  • 0 comments
  • 11 respects

Weather Station Based On Arduino And NodeMCU

Project tutorial by miklas

  • 10,623 views
  • 0 comments
  • 28 respects

Arduino & ASP.NET Core Project: Weather Station

Project tutorial by Zhang Yuexin

  • 14,178 views
  • 2 comments
  • 21 respects

Local Weather Station

Project tutorial by Abid hossain

  • 9,399 views
  • 9 comments
  • 29 respects

IoT | TensorFlow Weather Station Predicts Rainfall Intensity

Project tutorial by Kutluhan Aktar

  • 8,361 views
  • 12 comments
  • 22 respects
Add projectSign up / Login