Hello, I tried the project of “Apgar” I found it interesting and easy to implement all works well or nearly so, I added a LCD.widgets that indicates the status of the “Zone” and the moisture level of the soil, there are two problems one minor that is that when the area is active on the LCD the message “zone 1 ON” also flashes the moisture level of the soil is flashing, the second pigrave and where I’m banging my head for a long, it is that I added, compared to original project a daily timer more per day to irrigate twice a day, but when you are in 'zone 1 prog. A "the relay works intermittently (on-off-on-off-on etc.etc) to the duration of the timer, the problem presents himself with the “zone 2 prog. A” but it works properly “zone 1 Prog. B” and “zone 2 Prog. B” why? you can help me?
Try removing the analog read, lcd commands and the delay from the loop. Put them in a separate timer function. All you should have in your loop is Blynk and timer function.
Also I think your if statements in your zone controls may need an and looking at the status of the digital outputs. I can help you more tonight by testing your code myself n find out what’s going on.
I did a little test ( attaching the new sketch ) , I created the individual " timer.setInterval " - I separate function timers , I temporarily removed the moisture reading function of the ground , unfortunately the problem remains , and I noticed that if it moves the " delay" from within the " loop " can not connect to Blynk server must remain necessarily within the " loop " do not understand . if I look carefully the program can not figure out where the error !!!
#define BLYNK_PRINT Serial // Enables Serial Monitor
#define MOISTURE A0
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
int moisture= A0;
int value= A0;
char auth[] = "dccf2b9318544a72bb0803b5442492b4"; //insert here your token generated by Blynk
WidgetLCD lcd(V7);
SimpleTimer timer;
int enableZone1 = LOW; // set variables here to be available globally
int timerZone1 = LOW;
int timerZone3 = LOW;
int manualZone1 = LOW;
int enableZone2 = LOW; // set variables here to be available globally
int timerZone2 = LOW;
int timerZone4 = LOW;
int manualZone2 = LOW;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "TPLINK", "41713031"); //insert here your SSID and password
// Setup a function to be called every second
timer.setInterval(500L, manageZone1);
timer.setInterval(500L, manageZone2);
timer.setInterval(500L, manageZone3);
timer.setInterval(500L, manageZone4);
pinMode(moisture, INPUT);
pinMode(2, OUTPUT); // Zone 1
digitalWrite(2, HIGH);
pinMode(5, OUTPUT); // Zone 2
digitalWrite(5, HIGH);
}
// Zone 1
BLYNK_WRITE(0)
{ enableZone1 = param.asInt(); }
BLYNK_WRITE(1)
{ timerZone1 = param.asInt(); }
BLYNK_WRITE(2)
{ manualZone1 = param.asInt(); }
BLYNK_WRITE(3)
{ timerZone3 = param.asInt(); }
// Zone 2
BLYNK_WRITE(10)
{ enableZone2 = param.asInt(); }
BLYNK_WRITE(11)
{ timerZone2 = param.asInt(); }
BLYNK_WRITE(12)
{ manualZone2 = param.asInt(); }
BLYNK_WRITE(13)
{ timerZone4 = param.asInt(); }
void loop(){ // run over and over again
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
delay(300);
}
// manage Sprinkler Zone 1
void manageZone1() {
if (((enableZone1 == HIGH) && (timerZone1 == HIGH)) || (manualZone1 == HIGH)) {
digitalWrite(2, LOW);
lcd.print(4, 1, "Zona 1 ON");}
else {
digitalWrite(2, HIGH);
lcd.clear();
}
}
// manage Sprinkler Zone 2
void manageZone2() {
if (((enableZone2 == HIGH) && (timerZone2 == HIGH)) || (manualZone2 == HIGH)) {
digitalWrite(5, LOW);
lcd.print(4, 1, "Zona 2 ON");}
else {
digitalWrite(5, HIGH);
lcd.clear();
}
}
// manage Sprinkler Zone 3
void manageZone3() {
if (((enableZone1 == HIGH) && (timerZone3 == HIGH)) || (manualZone1 == HIGH)) {
digitalWrite(2, LOW);
lcd.print(4, 1, "Zona 1 ON");}
else {
digitalWrite(2, HIGH);
lcd.clear();
}
}
// manage Sprinkler Zone 4
void manageZone4() {
if (((enableZone2 == HIGH) && (timerZone4 == HIGH)) || (manualZone2 == HIGH)) {
digitalWrite(5, LOW);
lcd.print(4, 1, "Zona 2 ON");}
else {
digitalWrite(5, HIGH);
lcd.clear();
}
}
I am testing your code. But I am a little confused on what you are trying to accomplish. The logic for zone1 & zone3 control the same output with different conditions and that’s why u get the flashing. The same with zone2 & zone4. You are also clearing the lcd ever scan when conditions are not true. All these writes to the LCD every 500ms is too much.
I re-did the code to what I think you want. I’ve done a two second timer that updates the LCD to the status of each zone. I removed wifi info and auth token. Also verify the pins I defined for the zones.
#define BLYNK_PRINT Serial // Enables Serial Monitor
#define MOISTURE A0
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
int moisture= A0;
int value= A0;
#define Zone1 2 //define pins for outputs to zones
#define Zone2 5
#define Zone3 12
#define Zone4 14
SimpleTimer timer;
char auth[] = ""; //insert here your token generated by Blynk
boolean enableZone1 = LOW; // set variables here to be available globally
boolean timerZone1 = LOW;
boolean timerZone3 = LOW;
boolean manualZone1 = LOW;
boolean enableZone2 = LOW; // set variables here to be available globally
boolean timerZone2 = LOW;
boolean timerZone4 = LOW;
boolean manualZone2 = LOW;
boolean Zone1_Status = HIGH;
boolean Zone2_Status = HIGH;
boolean Zone3_Status = HIGH;
boolean Zone4_Status = HIGH;
WidgetLCD lcd(V7);
// Zone 1
BLYNK_WRITE(V0)
{ enableZone1 = param.asInt(); }
BLYNK_WRITE(V1)
{ timerZone1 = param.asInt(); }
BLYNK_WRITE(V2)
{ manualZone1 = param.asInt(); }
BLYNK_WRITE(V3)
{ timerZone3 = param.asInt(); }
// Zone 2
BLYNK_WRITE(V10)
{ enableZone2 = param.asInt(); }
BLYNK_WRITE(V11)
{ timerZone2 = param.asInt(); }
BLYNK_WRITE(V12)
{ manualZone2 = param.asInt(); }
BLYNK_WRITE(V13)
{ timerZone4 = param.asInt(); }
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
// Setup a function to be called every second
timer.setInterval(500L, manageZone1);
timer.setInterval(500L, manageZone2);
timer.setInterval(500L, manageZone3);
timer.setInterval(500L, manageZone4);
timer.setInterval(2000L, LCD_Update);
pinMode(moisture, INPUT);
pinMode(Zone1, OUTPUT); // Zone 1
digitalWrite(Zone1, Zone1_Status);
pinMode(Zone2, OUTPUT); // Zone 2
digitalWrite(Zone2, Zone2_Status);
pinMode(Zone3, OUTPUT); // Zone 3
digitalWrite(Zone3, Zone3_Status);
pinMode(Zone4, OUTPUT); // Zone 4
digitalWrite(Zone4, Zone4_Status);
lcd.clear();
}
void loop(){ // run over and over again
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
// manage Sprinkler Zone 1
void manageZone1() {
if (((enableZone1 == HIGH) && (timerZone1 == HIGH)) || (manualZone1 == HIGH)) {
Zone1_Status=LOW;
}
else {
Zone1_Status=HIGH;
}
digitalWrite(Zone1,Zone1_Status);
}
// manage Sprinkler Zone 2
void manageZone2() {
if (((enableZone2 == HIGH) && (timerZone2 == HIGH)) || (manualZone2 == HIGH)) {
Zone2_Status=LOW;
}
else {
Zone2_Status=HIGH;
}
digitalWrite(Zone2,Zone2_Status);
}
// manage Sprinkler Zone 3
void manageZone3() {
if (((enableZone1 == HIGH) && (timerZone3 == HIGH)) || (manualZone1 == HIGH)) {
Zone3_Status=LOW;
}
else {
Zone3_Status=HIGH;
}
digitalWrite(Zone3,Zone3_Status);
}
// manage Sprinkler Zone 4
void manageZone4() {
if (((enableZone2 == HIGH) && (timerZone4 == HIGH)) || (manualZone2 == HIGH)) {
Zone4_Status=LOW;
}
else {
Zone4_Status=HIGH;
}
digitalWrite(Zone4,Zone4_Status);
}
void LCD_Update(void){
lcd.print(0, 0, "Z1 Z2 Z3 Z4");
String str;
if(Zone1_Status==HIGH){
str+="OFF ";}
else{str+="ON ";}
if(Zone2_Status==HIGH){
str+="OFF ";}
else{str+="ON ";}
if(Zone3_Status==HIGH){
str+="OFF ";}
else{str+="ON ";}
if(Zone4_Status==HIGH){
str+="OFF ";}
else{str+="ON ";}
lcd.print(0,1,str);
}
thanks for the time that you gave me, I saw that you have worked hard on the sketch, are now at work in the afternoon will test the whole thing, you asked me that hardware use? is a esp8266 (nodemcu), then you asked that I use exactly should I do? I have a lawn to water have two lines and I would be able to program two daily irrigations (to us it is very hot) which is why my sketch in the “zone 3 and zone 4” activated the same areas of relay (zona 1 and zona 2), but thanks to your help I think we are close to the solution … When I get home I try
everything works great, you did a great job , unfortunately my work has remained very little and tells me to be still far away, now I’m making minor adjustments as shown soil moisture , I put a DHT11 , with its graph , allert with an email for when the soil is too dry , you upgrade when it will complete and publish it in the new projects section etc. I keep you updated thanks again .
I’m glad it works for you. I just took your basic design and made it work. However if it was my project I would do it totally different. Let me know when you are done and how it is working for you.
well … you tell me what would you change ? tips and suggestions are always welcome , forums and communities they serve just to exchange tips and suggestions for will improve their knowledge
I have to realize it as soon as I am now planning to add it in an enclosure , and make the connections and replace the existing irrigation computer which is the traditional … when it’s complete post a picture or video
I would use a RTC in the controller and have set times that are adjustable for the timers instead of using the timer widgets. That way if the internet is down or you loose connection everything will still works. I would also do away with the LCD widget and use value displays instead. If you would like to try it that way I could help you out.
@pavel@Dmitriy as it has been brought up here I will make a comment about an enhancement to the timer widget. How about making it a scheduler widget?
At the moment if you ‘miss’ the on / off trigger times (network down etc) then your project will ‘fail’. How about if time is before on trigger time do x, if time is between on and off do y and if time is after off trigger time then do z? Not too difficult and only applying to a 24 hour period (for now).
As far as I know there is no easy way of making full use of the timer widget. There is a complex way associated with parsing json data but it’s not for the faint hearted.
in fact, with " timer.widgets " even the sketch is leaner , certainly less professional but more basic , I wanted to use LCD.widgets is to have a simulation of a real sprinkler , you can do with LEDs that indicate the status of " zones " and " value.widgets " indicating temperature and humidity , but do not give the same visual effect and visual elegance and retro effect of LCD.widgets … regard to the request that i make to the authors of " Blynk " is a timer.widgets " more advanced with multiple activations in 24 hours and maybe schedule weekly so kind with just widgets have three functions .