#include <OneWire.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = “galaxy@29”;
char pass[] = “24312244”;
//code written by Md iqbal
//website:-techiqbal.com
//Youtube:-Techiqbal
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define BLYNK_TEMPLATE_ID “TMPL0AKNk1ys”
#define BLYNK_DEVICE_NAME “Iot based soil monitoring and Irrigation system”
#define BLYNK_AUTH_TOKEN “wpBmCLAgVKihsvL0nommSvc4FgScrNnZ”
SimpleTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
}
void setup()
{
Serial.begin(9600);
dht.begin();
timer.setInterval(1000L, sendSensor);
Blynk.begin(auth, ssid, pass);
sensors.begin();
}
int sensor=0;
int output=0;
void sendTemps()
{
sensor=analogRead(A0);
output=(145-map(sensor,0,1023,0,100)); //in place 145 there is 100(it change with the change in sensor)
delay(1000);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Serial.print(“moisture = “);
Serial.print(output);
Serial.println(”%”);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2,output);
delay(1000);
int relaypin = D5;
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(relaypin,OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
sendTemps();
}
SECOND PROGRAM
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = “galaxy@29”; // Enter your wifi name
char pass[] = “24312244”; // Enter your wifi password
int relaypin = D5;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(relaypin,OUTPUT);
}
void loop()
{
Blynk.run();
}