Hello guys, can you help me? I can upload the code, then my phone also can receive notification if I turn on the pump button. But, my relay does not turn on the water pump. Here is my code.
- Add details :
• Hardware model + communication type : ESP 8266 + Wi-Fi
• Smartphone OS (iOS or Android) + version : Android Vivo
• Blynk Android Version : 2.27.29
• Blynk server
• Blynk Library version : v1.0.0-beta.3
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
String apiKey = “”; //API Key from ThingSpeak channel
char auth[] = “”; //Authentication code sent by Blynk
char ssid[] = “”; //WiFi SSID
char pass[] = “”; //WiFi Password
//PIR
#define pirPin D1
int pirValue;
int pinValue;
const int buzzerPin = D7;
//SOIL MOISTURE
#define sensorPin D6
//RAIN
#define rainPin D5
int enable2 = D8;
int sensorState = 0;
int rainState = 0;
int lastState = 0;
int lastRainState = 0;
//DHT11
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
//WATER PUMP RELAY
#define WATER_PUMP D2
boolean state = 0;
/INPUT_OUTPUT*/
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(sensorPin, INPUT);
pinMode(rainPin, INPUT);
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(WATER_PUMP, OUTPUT);
pinMode(enable2, OUTPUT);
dht.begin();
timer.setInterval(1000L, sendSensor);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
sensors.begin();
}
/*DHT11/
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V6, t); //V6 is for Temperature
Serial.print("Current temperature = “);
Serial.print(t);
Serial.print(” ");
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Serial.print("Current humidity = ");
Serial.print(h);
}
/*SOIL/
int sensor=0;
void sendTemps()
{
sensor=analogRead(A0);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Serial.print("Soil Moisture is : ");
Serial.println(sensor);
if (sensor > 900)
{
digitalWrite (WATER_PUMP, HIGH);
}
if (sensor > 900 && sensor < 950)
{
digitalWrite(WATER_PUMP, HIGH);
}
if (sensor < 700)
{
digitalWrite(WATER_PUMP, LOW);
}
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2,sensor);
delay(1000);
}
/****WATER_PUMP((/
void loop()
{
getPirValue();
Blynk.run();
timer.run();
sendTemps();
sensorState = digitalRead(sensorPin);
Serial.println(sensorState);
}
/****MOTION/
void getPirValue(void)
{
pirValue = digitalRead(pirPin);
Serial.println(pirValue);
if (pirValue == 0)
{
Serial.print(“Motion detected”);
Serial.print(pirValue);
Blynk.notify(“Motion detected”);
digitalWrite(buzzerPin, HIGH);
Blynk.virtualWrite(V0, pirValue); //V0 is for Motion
}
else
{
digitalWrite (buzzerPin, LOW);
}
delay(100);
/RAIN***/
rainState = digitalRead(rainPin);
Serial.println(rainState);
if (rainState == 0 && lastRainState == 0) {
Serial.println(“Its Raining!”);
Blynk.notify(“Its Raining!”);
digitalWrite(enable2, HIGH);
lastRainState = 1;
delay(100);
} else {
Serial.println(“No Rains”);
digitalWrite(enable2, LOW);
lastRainState = 0;
delay(100);
}
}
BLYNK_WRITE(V1)
{
if (state == 0) {
state = 1;
digitalWrite(WATER_PUMP,HIGH);
Serial.println(“You just watered your plant”);
Blynk.notify(“You just watered your plant.”);
delay(1000);
}
else {
state = 0;
digitalWrite(WATER_PUMP,LOW);
}
}
*