Relay water pump not pump out water but I got notification already pump

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.

  1. 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);
}
}
*

is it normal ? don’t mix pin Dpin and GPIO
did you try to put a led at D2 ?

Unless you fill-in the rest of the requested/required information, this topic will also be closed….

  1. Add details :
    • Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
    • Smartphone OS (iOS or Android) + version
    • Blynk server or local server
    • Blynk Library version

Pete.

I’m sorry but I dont understand, because I never use this before. could you explain more? I use led just for rain sensor at D8.

okayy

I wanna be sure that D2 is triggered :stuck_out_tongue_winking_eye:
So a led with a resistor between GND and D2 will help

There is no such version of the Blynk library.
Please try again.

Pete.

1 Like

Does this mean I have to change WATER_PUMP D2 or DHTPIN 2?

Do you mean D2 to GPIO4 ?
D2 = GPIO 4 and GPIO2 = D4
So there is no problem with that

You also need to state which version of the Blynk Android app you are using.

Pete,

1 Like

You should be running version 0.6.1, because you are using the old version of Blynk (which will be retired shortly).

Pete.

Yes…For DHT11 I use D4. For water pump I use D2. I got notification saying that I already water my plant when I press on the button. But do you know why my water pump cannot open relay?

Which relay board do you use?

I use this one

I assume that your relay isn’t actually connected to the OneWire bus?

Also, your void loop is commented-out, so the code youve posted wont compile or run.

When you un-comment your void loop it needs to be cleaned-up from this:

void loop()
{
  getPirValue();
  Blynk.run();
  timer.run();
  sendTemps();
  sensorState = digitalRead(sensorPin);
  Serial.println(sensorState);
}

as described here:

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Pete.

2 Likes

Give us a link to the seller , because I can’t know if this board is compatible w 3.3V ESP8266 ouput

I buy from this. (https://shopee.com.my/Single-Relay-Module-With-Optocoupler-Isolation-5V-Arduino-i.89524452.3418977403)

Ok, this board need a 5V signal trigger input , so it can’t work with the ESP8266 !

How do I uncomment it? Means that in the void loop onle have Blynk.run() and timer.run()?

That’s right ! you have to use timer in setup

1 Like