Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.0 kB
3
Indexable
Never
#define BLYNK_PRINT Serial
//Ibahin na lang to kada device sa blynk pang soil to
#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_TEMPLATE_NAME "xxxx"
#define BLYNK_AUTH_TOKEN "xxxx"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// Your Blynk Auth Token
char auth[] = "xxxx";

// Threshold values for the notification alert
#define RAIN_SENSOR_THRESHOLD 500
#define RAIN_SENSOR_THRESHOLD2 800
#define SOIL_SENSOR_THRESHOLD 800

// DHT pin for ESP8266
#define DHTPIN 14            // D5 (kung anong pins kinabit GPIO pins)
#define DHTTYPE DHT11
#define rainSensor A0

// Functions of sensor 0 & 1
float sensor0; // Rain sensor

// For DHT function and type
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

char ssid[] = "xxxx";
char pass[] = "xxxx";

void setup() {

  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  dht.begin();

// The interval of values being refreshed
  timer.setInterval(1000L, rain);
  timer.setInterval(1100L, sendSensor);


}

void rain() {

  sensor0 = analogRead(rainSensor);

// Converting the map values of the sensor into 0 - 100 percentage
  float sensorValue0 = map(sensor0, 1024, 325, 0, 100);

// Display on Blynk
  Blynk.virtualWrite(V2, sensorValue0);

// The condition for rain alert notification
  if (sensor0 < RAIN_SENSOR_THRESHOLD) {
    Blynk.logEvent("rainalert");
  }
    else if (sensor0 < RAIN_SENSOR_THRESHOLD2) {
      Blynk.logEvent("slightrain");
  }
}
void sendSensor() {

// Functions of DHT sensor
  float h = dht.readHumidity();
  float t = dht.readTemperature();

// For checking if the DHT is working
if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

// Display on Blynk
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V4, h);
}

void loop() {

  Blynk.run();
  timer.run();
  
  Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  ESP.deepSleep(30e6); 

}
Leave a Comment