Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Alican Duran
Published © GPL3+

NodeMcu Solar Weather Station

Let's Go Make Deep Sleep Mode ThingSpeak Solar Weather Station

IntermediateFull instructions provided2,535
NodeMcu Solar Weather Station

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Bmp 180
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Rain Sensor
×1
Charging Board
×1
Step-Up Voltage Regulator - 5V
SparkFun Step-Up Voltage Regulator - 5V
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×3
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
PiJuice Solar Panel - 6 Watt
PiJuice Solar Panel - 6 Watt
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Schematics diagrams

Code

Code

C/C++
//Alican Duran
//D. ARGE Labs

#include <DHT.h>
#define DHTTYPE DHT22
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

String apiKey = "Yours apiKey";
const char* ssid = "yours wiffi ssid";
const char* password = "Yours wiffi Password";
const char* server = "api.thingspeak.com";
#define DHTPIN 0

const int sleepTimeS = 1800; 

DHT dht(DHTPIN, DHT22, 2);
WiFiClient client;

int sensorPin = A0;
int enable1 = 15;
int enable2 = 13;
int enable3 = 14;

int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;

void setup() {

  pinMode(enable1, OUTPUT);
  pinMode(enable2, OUTPUT);
  pinMode(enable3, OUTPUT);

  Serial.begin(115200);
  delay(10);

  dht.begin();

  WiFi.begin(ssid, password);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  Serial.print("..........");
  Serial.println();
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);

  }
  Serial.println("WiFi connected");
  Serial.println();

}

void loop() {

  float h = dht.readHumidity();
  float t = dht.readTemperature();


  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


  Serial.print("Temperature:      ");
  Serial.print(t);
  Serial.print(" degrees Celcius ");
  Serial.println();

  Serial.print("Humidity:         ");
  Serial.print(h);
  Serial.print("%");
  Serial.println();

  double gamma = log(h / 100) + ((17.62 * t) / (243.5 + t));
  double dp = 243.5 * gamma / (17.62 - gamma);

  Serial.print("Dew point:        ");
  Serial.print(dp);
  Serial.print(" degrees Celcius ");
  Serial.println();

  if (!bmp.begin()) {
    Serial.print("Failed to read from BMP sensor!!");
    while (1);
  }

  sensors_event_t event;
  bmp.getEvent(&event);

  Serial.print("Pressure:         ");
  Serial.print(event.pressure);
  Serial.println(" hPa");

  float temperature;
  bmp.getTemperature(&temperature);
  Serial.print("Temperature:      ");
  Serial.print(temperature);
  Serial.println(" degrees Celcius ");

  float seaLevelPressure = 1015;
  Serial.print("Altitude:         ");
  Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure));
  Serial.println(" m");

  digitalWrite(enable1, HIGH);
  delay(100);
  sensorValue1 = analogRead(sensorPin);
  sensorValue1 = constrain(sensorValue1, 300, 850);
  sensorValue1 = map(sensorValue1, 300, 850, 0, 1023);
  Serial.print("Light intensity:  ");
  Serial.println(sensorValue1);
  digitalWrite(enable1, LOW);
  delay(100);

  digitalWrite(enable2, HIGH);
  delay(500);
  sensorValue2 = analogRead(sensorPin);
  sensorValue2 = constrain(sensorValue2, 150, 440);
  sensorValue2 = map(sensorValue2, 150, 440, 1023, 0);
  Serial.print("Rain value:       ");
  Serial.println(sensorValue2);
  Serial.println();
  delay(100);
  digitalWrite(enable2, LOW);

  digitalWrite(enable3, HIGH);
  delay(500);
  int moisture_percentage;
 
  sensorValue3 = ( 100.00 - ( (analogRead(sensorPin)/1023.00) * 100.00 ) );
 
    Serial.print("Soil Moisture(in Percentage) = ");
    Serial.print(sensorValue2);
    Serial.println("%");
 
  delay(100);
  digitalWrite(enable3, LOW);

  

  if (client.connect(server, 80)) {
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(t);
    postStr += "&field2=";
    postStr += String(h);
    postStr += "&field3=";
    postStr += String(event.pressure);
    postStr += "&field4=";
    postStr += String(dp);
    postStr += "&field5=";
    postStr += String(sensorValue1);
    postStr += "&field6=";
    postStr += String(sensorValue2);
    postStr +="&field7=";
    postStr += String(sensorValue3);
    postStr +="&field8=";
    postStr += String(bmp.pressureToAltitude(seaLevelPressure,event.pressure));
    postStr += "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
    
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n\n\n\n\n\n\n");
    client.print(postStr);

 delay(500);
        Serial.println("deepsleep moduna girdi ");
        ESP.deepSleep(sleepTimeS * 1000000);
    }

    client.stop(); 

    Serial.println("Client Stopped.");
    delay(500);
}

Credits

Alican Duran
0 projects • 0 followers

Comments