Hi there, it is 4 am here and I've spent my whole night on this so please help. I've got a 12V DC pump connected to esp8266 via a relay . I'm building an 'automated irrigation system' and the pump needs to be controlled based on soil moisture levels , I've automated the condition for pump on Blynk but the Problem is that the pump is running NON STOP from when i upload the code so blynk can't control it
Pins:
Relay VCC to esp Vin
Relay GND to esp G
Relay IN to esp D3
Relay COM powered by 12V adapter
Relay ON to pump
12v adapter and pump grounded directly
I want the pump to only run when i give command ( press button ) from blynk , before that the pump shouldn't work, this way the automation condition applied on blink can do it's job
#include <Wire.h>
#include <SPI.h>
#include <ACROBOTIC_SSD1306.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_TEMPLATE_ID "TMPLn3apCeAb"
#define BLYNK_DEVICE_NAME "Quickstart Template"
char auth[] = "***";//Enter your Auth token
char ssid[] = "***";//Enter your WIFI name
char pass[] = "***";//Enter your WIFI password
BlynkTimer timer;
bool Relay = 0;
//Define component pins
#define SCL D1
#define SDA D2
#define sensor A0
#define waterPump D3
#define DRY_SOIL 40
#define TIME_PUMP_ON 5
int value = 0;
void setup() {
Serial.begin(9600);
pinMode(waterPump, OUTPUT);
digitalWrite(waterPump, HIGH);
Wire.begin();
oled.init(); // Initialze SSD1306 OLED display
oled.clearDisplay();
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
oled.setTextXY(1, 0);
oled.putString("System Loading");
for (int a = 0; a <= 15; a++) {
oled.setTextXY(a, 1);
oled.putString(".");
delay(500);
}
oled.clearDisplay();
//Call the function
timer.setInterval(100L, soilMoistureSensor);
// timer.setInterval(60L * 1000, autoControlPlantation);
}
//Get the button value
BLYNK_WRITE(1) {
Relay = param.asInt();
if (Relay == 1) {
digitalWrite(waterPump, LOW);
oled.setTextXY(0, 1);
oled.putString("Motor is ON ");
}
else {
digitalWrite(waterPump, HIGH);
oled.setTextXY(0, 1);
oled.putString("Motor is OFF");
}
}
//Get the soil moisture values
void soilMoistureSensor() {
value = 0;
int value = analogRead(sensor);
value = map(value, 0, 1024, 0, 100);
value = (value - 100) * -1;
Blynk.virtualWrite(0, value);
oled.setTextXY(0, 0);
oled.putString("Moisture :");
oled.putString(String(value));
oled.putString(" ");
}
void loop() {
Blynk.run();//Run the Blynk library
timer.run();//Run the Blynk timer
}
// void autoControlPlantation(void)
// {
// if (value < DRY_SOIL)
// {
// Blynk.notify("AutoFarm: Warning ==>> Pump ON");
// digitalWrite(waterPump, LOW);
// oled.setTextXY(0, 1);
// oled.putString("Motor is ON ");
// }
// else {
// digitalWrite(waterPump, HIGH);
// oled.setTextXY(0, 1);
// oled.putString("Motor is OFF");
// }
// delay (TIME_PUMP_ON * 1000);
// }


