NodeMcu Solar Weather Station
Let's Go Make Deep Sleep Mode ThingSpeak Solar Weather Station
Components and supplies
1
DHT22 Temperature Sensor
1
LDR, 5 Mohm
1
Li-Ion Battery 1000mAh
1
PiJuice Solar Panel - 6 Watt
1
Step-Up Voltage Regulator - 5V
1
Charging Board
1
Rain Sensor
1
Resistor 10k ohm
1
NodeMCU ESP8266 Breakout Board
3
1N4007 – High Voltage, High Current Rated Diode
1
Linear Regulator (7805)
1
Bmp 180
Apps and platforms
1
Arduino IDE
1
ThingSpeak API
Project description
Code
Code
c_cpp
1//Alican Duran 2//D. ARGE Labs 3 4#include <DHT.h> 5#define DHTTYPE DHT22 6#include <ESP8266WiFi.h> 7#include <Wire.h> 8#include <Adafruit_Sensor.h> 9#include <Adafruit_BMP085_U.h> 10Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); 11 12String apiKey = "Yours apiKey"; 13const char* ssid = "yours ssid"; 14const char* password = "Yours Password"; 15const char* server = "api.thingspeak.com"; 16#define DHTPIN 0 17 18const int sleepTimeS = 1800; // duration of deep sleep in seconds 19 20DHT dht(DHTPIN, DHT22, 2); 21WiFiClient client; 22 23int sensorPin = A0; 24int enable1 = 15; 25int enable2 = 13; 26 27int sensorValue1 = 0; 28int sensorValue2 = 0; 29 30void setup() { 31 32 pinMode(enable1, OUTPUT); 33 pinMode(enable2, OUTPUT); 34 35 Serial.begin(115200); 36 delay(10); 37 38 dht.begin(); 39 40 WiFi.begin(ssid, password); 41 42 Serial.println(); 43 Serial.println(); 44 Serial.print("Connecting to "); 45 Serial.println(ssid); 46 Serial.print(".........."); 47 Serial.println(); 48 WiFi.begin(ssid, password); 49 50 while (WiFi.status() != WL_CONNECTED) { 51 delay(500); 52 53 } 54 Serial.println("WiFi connected"); 55 Serial.println(); 56 57} 58 59void loop() { 60 61 float h = dht.readHumidity(); 62 float t = dht.readTemperature(); 63 64 65 if (isnan(h) || isnan(t)) { 66 Serial.println("Failed to read from DHT sensor!"); 67 return; 68 } 69 70 71 Serial.print("Temperature: "); 72 Serial.print(t); 73 Serial.print(" degrees Celcius "); 74 Serial.println(); 75 76 Serial.print("Humidity: "); 77 Serial.print(h); 78 Serial.print("%"); 79 Serial.println(); 80 81 double gamma = log(h / 100) + ((17.62 * t) / (243.5 + t)); 82 double dp = 243.5 * gamma / (17.62 - gamma); 83 84 Serial.print("Dew point: "); 85 Serial.print(dp); 86 Serial.print(" degrees Celcius "); 87 Serial.println(); 88 89 if (!bmp.begin()) { 90 Serial.print("Failed to read from BMP sensor!!"); 91 while (1); 92 } 93 94 sensors_event_t event; 95 bmp.getEvent(&event); 96 97 Serial.print("Pressure: "); 98 Serial.print(event.pressure); 99 Serial.println(" hPa"); 100 101 float temperature; 102 bmp.getTemperature(&temperature); 103 Serial.print("Temperature: "); 104 Serial.print(temperature); 105 Serial.println(" degrees Celcius "); 106 107 float seaLevelPressure = 1015; 108 Serial.print("Altitude: "); 109 Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure)); 110 Serial.println(" m"); 111 112 digitalWrite(enable1, HIGH); 113 sensorValue1 = analogRead(sensorPin); 114 sensorValue1 = constrain(sensorValue1, 300, 850); 115 sensorValue1 = map(sensorValue1, 300, 850, 0, 1023); 116 Serial.print("Light intensity: "); 117 Serial.println(sensorValue1); 118 digitalWrite(enable1, LOW); 119 delay(100); 120 121 digitalWrite(enable2, HIGH); 122 delay(500); 123 sensorValue2 = analogRead(sensorPin); 124 sensorValue2 = constrain(sensorValue2, 150, 440); 125 sensorValue2 = map(sensorValue2, 150, 440, 1023, 0); 126 Serial.print("Rain value: "); 127 Serial.println(sensorValue2); 128 Serial.println(); 129 delay(100); 130 digitalWrite(enable2, LOW); 131 132 if (client.connect(server, 80)) { 133 String postStr = apiKey; 134 postStr += "&field1="; 135 postStr += String(t); 136 postStr += "&field2="; 137 postStr += String(h); 138 postStr += "&field3="; 139 postStr += String(event.pressure); 140 postStr += "&field4="; 141 postStr += String(dp); 142 postStr += "&field5="; 143 postStr += String(sensorValue1); 144 postStr += "&field6="; 145 postStr += String(sensorValue2); 146 postStr +="&field8="; 147 postStr += String(bmp.pressureToAltitude(seaLevelPressure,event.pressure)); 148 postStr += "\ \ 149\ \ 150\ \ 151\ \ 152\ \ 153\ \ 154\ \ 155\ \ 156"; 157 158 client.print("POST /update HTTP/1.1\ 159"); 160 client.print("Host: api.thingspeak.com\ 161"); 162 client.print("Connection: close\ 163"); 164 client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\ 165"); 166 client.print("Content-Type: application/x-www-form-urlencoded\ 167"); 168 client.print("Content-Length: "); 169 client.print(postStr.length()); 170 client.print("\ 171\ 172\ 173\ 174\ 175\ 176\ 177\ 178"); 179 client.print(postStr); 180 181 delay(500); 182 Serial.println("entered deepsleep mode"); 183 ESP.deepSleep(sleepTimeS * 1000000); //multiplier value to convert microseconds to seconds 184 } 185 186 client.stop(); 187 188 Serial.println("Client Stopped."); 189 delay(500); 190}
Downloadable files
Schematics diagrams
Schematics diagrams

Schematics diagrams
Schematics diagrams

Comments
Only logged in users can leave comments