-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_station_final.ino
117 lines (70 loc) · 4.05 KB
/
weather_station_final.ino
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <Adafruit_Sensor.h> //In order to use DHT sensor we have to include this library first
#define BLYNK_PRINT Serial
//___________________Include Libraries_________________________________________________________
#include <DHT.h> //Including the DHT library
#include <ESP8266WiFi.h> //Including the ESP8266 WiFi library in order to usm them
#include <BlynkSimpleEsp8266.h> //library for linking up Blynk with ESP8266
#include <Wire.h> //For using I2C connection of BMP180 in order to connect it to the board
#include <Adafruit_BMP085.h> //Including the library for BMP180
Adafruit_BMP085 bmp; //Defining the object bmp
#define I2C_SCL 12 //Connect SCL pin of BMP180 to GPIO12(D6) of Nodemcu
#define I2C_SDA 13 //Connect SDA pin of BMP180 to GPIO13(D7) of Nodemcu
float dst,bt,bp,ba;
char dstmp[20],btmp[20],bprs[20],balt[20];
bool bmp085_present=true;
char auth[] = "Put your Authication key from the Blynk app here"; //Authentication Key will be there in the Blynk App
//________________________Mention the SSID and Password____________________________________________________
char ssid[] = "Your WiFi SSID"; //SSID of the WiFi hotspot available
char pass[] = "Your Password"; //Password of the WiFi
#define DHTPIN 2 //Connect the DHT11 sensor's data pin to GPIO2(D4) of Nodemcu
#define DHTTYPE DHT11 //Mention the type of sensor we are using, Here it it DHT11, for DHT22 just replace DHT11 with DHT22
DHT dht(DHTPIN, DHTTYPE); //Defining the pin and the dhttype
BlynkTimer timer;
void sendSensor()
{
//______________________________Check the working of BMP180 sensor________________________________________
if (!bmp.begin())
{
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
//______________________Getting the Humidity and temperature value from DHT11____________________________
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
//______________________________Check the working of DHT11 sensor________________________________________
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
//______________________________Measuring the Dew Point______________________________________________________
double gamma = log(h/100) + ((17.62*t) / (243.5+t));
double dp = 243.5*gamma / (17.62-gamma);
//______________________Reading the value of Pressure, Temperature, Altitude from the BMP180__________________
float bp = bmp.readPressure()/100; // Division by 100 makes it in millibars
float ba = bmp.readAltitude();
float bt = bmp.readTemperature();
float dst = bmp.readSealevelPressure()/100;
//_______________Printing the valus of the above read value on to the Virtual Pins in the Bluynk App_____________
Blynk.virtualWrite(V5 , h); //h=Humidity
Blynk.virtualWrite(V6 , t); //t=temp_dht11
Blynk.virtualWrite(V10, bp); //bp=pressure
Blynk.virtualWrite(V11, ba); //ba=altitude
Blynk.virtualWrite(V12, bt); //bt=temp_bmp180
Blynk.virtualWrite(V13, dst); //dst=sealevel pressure
Blynk.virtualWrite(V14, dp); //dp=dew point
}
void setup()
{
Serial.begin(9600); //Initializing the Serial Monitor with a Baud Rate of 9600
Blynk.begin(auth, ssid, pass);
dht.begin(); //Initializing the DHT sensor
Wire.begin(I2C_SDA, I2C_SCL); //Initializing the I2C connection
delay(10);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}