ESP8266IOT Projects

IoT Weather Station Project using Nodemcu ESP8266 and Arduino Uno

IoT Weather Station Project Description:

 

IoT Weather Station Project- A few months back I posted a tutorial on Arduino based weather station, in which I displayed the humidity and temperature values on gauges.

IoT Weather Station

The software which you can see was designed in vb.net 2010 Express Edition. This project needs a computer system to display the temperature and humidity values in real-time. We can make the same exact project without using the Computer or Laptop. So I decided to make another version of the same weather station using Arduino, dht11, Nodemcu ESP8266 Wifi Module, and Blynk application. So, that we can monitor the temperature and humidity values in real-time from anywhere around the world using our cell phone.



I will also explain why we are using Arduino and Nodemcu ESP8266 together, while we can do this by only using the Nodemcu module. In this tutorial, I will cover the maximum things. If in case you find any difficulty you can watch a video Tutorial given at the end of this article.

Without any further delay, let’s get started

Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

DHT11 Temperature and Humidity Module:

Nodemcu ESP8266 WiFi Module:

LM7805 Voltage Regulator:

470uf capacitor:

330-ohm resistor:

DC Female Power Jack:

Female Headers:

Male Headers:
Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

 


Arduino and Nodemcu ESP8266 together:

I know we can make the same project using only the Nodemcu ESP8266 Wifi module, and we can reduce the project size, power and building time, etc. You know very well Nodemcu ESP8266 Wifi module has a very limited number of the IO pins, and there is only 1 analog Pin. I have been frequently asked by my followers on YouTube Channel “Electronic Clinic” that how to connect multiple analog sensors or how to increase the IO pins of the Nodemcu Module. My replay is always to use Arduino or Mega with the Nodemcu Module. We can also use a multiplexer, but that needs wiring, and complicated programming which we really don’t want. So the easiest option is to use the Arduino Uno or Mega with the Nodemcu ESP8266 Wifi module.


So, that’s the reason I am using Arduino Uno with the Nodemcu Module. In this Project, you will learn completely how to connect Nodemcu module with the Arduino and how to establish the Serial Communication. The Arduino does all the processing, reads the DHT11 sensor, make a String message and send it to the Nodemcu Module. Then in the Nodemcu Module, we split the entire message and send the desired data to the Blynk Application. Now let’s have a look at the DHT11 Temperature and Humidity sensor.

This Project is based on my previous two tutorials.

In this tutorial, you will learn how to install the Nodemcu esp8266 wifi board and how to download and use the blynk library and how to fix the USB UART driver error.

While in this tutorial you will learn how to make a power supply for Nodemcu esp8266 wifi module so that it can be easily powered up using a 12v adaptor or battery.


DHT11 Temperature and Humidity Datasheet:

First of all, let’s start with the datasheet of the DHT11 Temperature and Humidity module.

IoT Weather Station

This is the dht11 sensor that we will be using today, this datasheet consists of all the necessary information that you want to know about dht11, like for example.

IoT Weather Station

It’s product overview.

Applications, which clearly explain; where you can use this particular sensor.


IoT Weather Station

The features

Dimensions

And product parameters, which is the most important part and you should definitely read this.

The electrical characteristics, which tells you how much voltage it needs.

IoT Weather Station

As it needs 3.5 to 5.5volts so this sensor can be easily powered up using the Arduino’s 5v.

Pin description, the dht11 sensor has four pins, the left most pin which is the pin number1 can be connected with Arduino’s 5v… Pin number2 is the data pin…pin number3 is not connected…while pin number4 is the ground.


IoT Weather Station Circuit Diagram:

IoT Weather Station

So, my friends, this is the basic circuit diagram which shows how the DHT11 sensor and Nodemcu ESP8266 Wifi module will be connected with the Arduino. As you know DHT11 has four pins. Pin1 will be connected with Arduino’s 5v…pin number 2 will be connected with pin number 12 of the Arduino…A 10k resistor is connected with pin number 1 and pin number 2 of the sensor…pin number 3 is not connected while pin number 4 is connected with the ground..

J1 is the DC Female Power Jack and this is where we connect a 12v Adaptor, A Battery, or a Solar Panel. Two 470UF capacitors are connected at the input and output sides of the LM7805 voltage Regulator. In the circuit diagram above you can see the Arduino’s 5v pin is connected with the Nodemcu Vin pin, sometimes it works but usually, it fails and keeps resetting, So don’t power up the Nodemcu module from Arduino. Connect the output of the 5v regulated Power Supply with the Vin Pin of the Nodemcu ESP8266 Wifi module. and also connect the ground of the Power Supply with the Arduino’s Ground. Connect the Tx and Rx pins of the Nodemcu module with Pins 2 and 3 of the Arduino Uno.

Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.

IoT Weather Station Blynk Application Designing:

Watch video Tutorial give at the end or follow the following instructions:

  • First of all, open the Blynk application.
  • Set the project name as a weather station.
  • Click on the choose device and select Nodemcu.
  • Make sure you set the connection type to wifi.
  • then click on the create button, an authentication token will be sent on your email id, which will be then used in programming, simply copy and paste it in programming.
  • Click on the screen and add two gauges.
  • Click on the first gauge and change its name to Humidity.
  • Click on the pin and select virtual and also select v2.
  • Set the maximum value to 100.
  • Change the font size.
  • Click on the push and select 1 second.
  • Now repeat the same steps for the other gauge.


IoT Weather Station

basic application setup is completed; now let’s discuss the Arduino and Nodemcu programs.

IoT Weather Station Programming:

This Project is based on two programs. One program is written for the Arduino Uno while the other program is written for the Nodemcu ESP8266 WIFI module. For the step by step programs explanation watch video tutorial given at the end.


IoT Weather Station Arduino Programming:

#include "DHT.h"
#include <SoftwareSerial.h>

SoftwareSerial nodemcu(2,3);
#define DHTPIN 12     // what pin we're connected to

//Uncomment whatever the type of sensor we are using. 
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

boolean tflag = false; // temperature flag. 
// this flag will be used to stop unnecessary repetition of code.

int relay = 13; 

int sdata1 = 0; // humidity
int sdata2 = 0; // temperature


String cdata; // complete data, consisting of sensors values

void setup()
{
Serial.begin(9600); 
nodemcu.begin(9600);
dht.begin();


pinMode(4, OUTPUT); // dht11 vcc pin is connected with pin 4
digitalWrite(4, HIGH); 

}

void loop()
{
    // Wait a few seconds between measurements.
  delay(2000);
   // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  // Read temperature as Celsius
  int t = dht.readTemperature();
  // Read temperature as Fahrenheit
  int f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  int hi = dht.computeHeatIndex(f, h);

if ( (t > 32 ) && ( tflag == false ) )
{
 digitalWrite(relay, HIGH); 
 Serial.println("Fan is On");
tflag = true;  
}

if ( (t <= 32 ) && ( tflag == true ) )
{
 digitalWrite(relay, LOW); 
  Serial.println("Fan is Off");
tflag = false;  
}
    sdata1 = h;
    sdata2 = t; 
   cdata = cdata + sdata1+","+sdata2; // comma will be used a delimeter
   Serial.println(cdata); 
   nodemcu.println(cdata);
delay(500);
   cdata = ""; 

}


IoT Weather Station Nodemcu Programming:

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>

char auth[] = "001935f6f7be4ed780f62e840c34f564";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZONG MBB-E8231-6E63";
char pass[] = "08659650";

SimpleTimer timer;

String myString; // complete message from arduino, which consists of snesors data
char rdata; // received characters

int firstVal, secondVal,thirdVal; // sensors 
// This function sends Arduino's up time every second to Virtual Pin (1).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  
}



void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

    timer.setInterval(1000L,sensorvalue1); 
     timer.setInterval(1000L,sensorvalue2); 

}

void loop()
{
   if (Serial.available() == 0 ) 
   {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
   }
   
  if (Serial.available() > 0 ) 
  {
    rdata = Serial.read(); 
    myString = myString+ rdata; 
   // Serial.print(rdata);
    if( rdata == '\n')
    {

String l = getValue(myString, ',', 0);
String m = getValue(myString, ',', 1);
 


firstVal = l.toInt();
secondVal = m.toInt();


  myString = "";
// end new code
    }
  }

}

void sensorvalue1()
{
int sdata = firstVal; // humidity value
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, sdata);

}
void sensorvalue2()
{
int sdata = secondVal; // temperature value
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V3, sdata);

}

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

IoT Weather Station Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button