[SOLVED] Issues creating a auto/manual pump control

Void Auto(){
digital.Write(relay1,HIGH);
timer.setInterval(10000,OFF);}

void OFF(){
digital.Write(relay2,LOW);

But it didnt work. Same as before, few clicks of button, Blynk disconnected.
And reconnect attempt result such error:

[1607] Failed to disable Echo

Iā€™m starting to doubt if it was the hardware problem.
5v connected to Relay Vcc and Lm1117.
Lm1117 3.3v to Vcc,CH_ of ESP8266.

Pls help. Thanks

Hi. Iā€™m using USB serial connection with arduino to connect blynk.
Auto mode > manual mode was fine. Auto mode suppose to run 5sec and idle 5sec
But when manual mode switch back to auto, therere no relay pulse. The time frame is not restoredā€¦
Iā€™m new to blynk and electronics. Please help :slight_smile:

#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <DHT.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
#define relay1 11
#define lightpin 0
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
SimpleTimer timer;
int i=0;
int button2;
int selectmode;
int timer1;
int timer2;
int timer3;
int Lux;
char auth[] = "14df01c16b1548518503a6bf1d74681c";
WidgetLED led1(8);
WidgetLED led2(9);

void setup()
{
  // Debug console
  DebugSerial.begin(9600);
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, LOW);
  pinMode(lightpin, OUTPUT);
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  dht.begin();
  Blynk.begin(Serial, auth);
  timer.setInterval(3000,senddata);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void senddata(){
    int analoglux=analogRead(lightpin); 
    int h = dht.readHumidity();
    int t = dht.readTemperature();
    
    Blynk.virtualWrite(V1, h);
    Blynk.virtualWrite(V2, t);
    Blynk.virtualWrite(V3, analoglux);
}

void Auto(){
  
  if( i==0 && selectmode ==0){
  digitalWrite(relay1, HIGH);
  timer2=timer.setTimeout(5000,OFF);}
}

void OFF(){
  digitalWrite(relay1, LOW);
  timer.disable(timer2);
}

void Manual(){


    if(button2==1&&selectmode==1){
    digitalWrite(relay1,HIGH);}

    else{
    digitalWrite(relay1,LOW);}

  }

BLYNK_WRITE(V6){
  button2 = param.asInt();
  }

  BLYNK_WRITE(V5){
  selectmode = param.asInt();
  if(selectmode ==1){
     i=1;
     led1.off();
     led2.on(); 
     timer3=  timer.setInterval(1000, Manual);
  }

  else{
   i=0;
   led1.on();
   led2.off();
   timer1 = timer.setInterval(10000, Auto);
  }
  }

  BLYNK_CONNECTED(){
  Blynk.syncVirtual(V5);
  Blynk.syncVirtual(V6);

  }

Please donā€™t create multiple topics for similar issues on the same project. I have merged this latest question back into your original.

You need to supply much more detail on what you are trying to do, what you are needing help with, what you have already tried, etc. Not everyone on this forum is able or willing to figure out your whole code based on your own terms of ā€œmanual and autoā€ā€¦ I mean, manual and auto what, automotive transmission? :wink:

Ops. Iā€™m Sorry. But im desperateā€¦
So, The auto-mode is suppose to send pulse to relay and turn on the water pump for 5 seconds and idle for the other 5 seconds which is fine at first. Next, when user clicked on manual mode. This allows user to control the relay on/off via button2.

Now, the problem comes. When i switched back to auto mode, the time frame is not restored as the same for auto mode. 5s on and 5s off. The relay on/off almost instantly.
I bet thereā€™s error here. But i just donā€™t get it.

void Auto(){
  
  if( i==0 && selectmode ==0){
  digitalWrite(relay1, HIGH);
  timer2=timer.setTimeout(5000,OFF);}
}

void OFF(){
  digitalWrite(relay1, LOW);
  timer.disable(timer2);
}

I have tried using timer.disable(timerID). However, the result stays the same. Iā€™m sorry but im super desperate for solution.

I donā€™t understand what you are doing hereā€¦ you donā€™t take a timer function and apply it to a variable.

Build your code in stagesā€¦ Create two totally separate functions, one that works automatically in a non-blocking loop, using timers as you have tried.

Create a second function that relies on manual control, with itā€™s own timers if necessary.

Then create a third function that chooses one of the two prior ones based on a button/switch stateā€¦ no timers involved for that.

Properly name your timers and comment your code. Simple names like timer1, timer2ā€¦ etcā€¦ are too easy to get confused. And no one else will even bother trying to figure it out.

And finally, please understand that your cries of desperation does not guarantee quicker or better assistance, perhaps even the opposite, as others avoid what appears to be a potential hand holding session :wink:

Thank you Gunner. Will work on that.

Actually its perfectly valid, timer functions return an integer that represents that timers specific ID. With it the programmer can delete, enable and disable that specific timer :slight_smile:

2 Likes

@Wesley can you be more specific of how you want your modes to operate?

Should your automode continously toggle at 5 seconds interval or just once?

HI Fett!

  1. Once Powered, auto-mode should be default mode. It toggle at 5 seconds interval.
  2. Once button is pushed(HIGH)(V5), Mode will be manual-mode. Controllable by user using button2(V6).
  3. It sends humidity, Temp, luminance every 5seconds to blynk server. (no problem so far).

Problem facing:

  1. Auto-mode was functional when no button was pressed.
  2. Once pressed. Manual-mode engaged. Seems normal and functional too
  3. Press button again to switch back auto-mode. The interval messed up. It did not toggle at 5 seconds, rather toggle instantly.

just a quick idea:

i think that before changing the timeout with timer2=timer.setTimeout(5000,OFF);, first you have to disable it witth timer.disable(timer2);

and it is usually good practice to use L after the values in simple timer.

so, try it like this:

 if( i == 0 && selectmode == 0) {
  digitalWrite(relay1, HIGH);
  timer.disable(timer2);
  timer2 = timer.setTimeout(5000L, OFF);}
1 Like

Hi thanks for helping. But it doesnt work. After few toggle, The Auto-mode runs forever and button donā€™t work too.

Iā€™ll take a look after I watch my show :slight_smile:
Just an fyi timer intervals canā€™t be changed, you must delete the current timer and create a new one in order to ā€œchangeā€ intervals

Alrighty. I will work on that. Thanks Fett.

Ill have to get back on this at a later point good luck Wesley, got family matters :slight_smile:

1 Like

This project works quite similiar to mine. So i follow what he wrote and auto-mode work like a charm. i delete the timer so it wont overflow to the next timer which caused an infinite cycle. YAY! Phew, after so many hours.

void Auto(){
  
  if( i==0 && selectmode ==0){
  digitalWrite(relay1, HIGH);
  //timer.disable(timer2);
  timer2=timer.setTimeout(5000L,OFF);}
  
}

void OFF(){
  timer.deleteTimer(timer2);
  digitalWrite(relay1, LOW);

}
3 Likes

Thanks @Fettkeewl, I thought that was done by the actual timer nameā€¦ I will have to dig into that more.

So you got it figured out and working then?

Yeah. Thanks Gunner and sorry :neutral_face:
Another question, Can hardware receive sensor data from blynk uploaded by another device? through this method (with same auth token)

Blynk.Read(V1){
int = the sensor value;
}

No apologies necessary! Glad you got it doing what you want it to :+1:[quote=ā€œWesley, post:23, topic:13752ā€]
Another question, Can hardware receive sensor data from blynk uploaded by another device? through this method
[/quote]

Not quite that method (but you can control multiple devices from the app with same or different auth codes) ā€¦ but yes, sharing data from device to device can be done via bridge command:

http://docs.blynk.cc/#widgets-other-bridge

If you have issues getting that to work, then you create a new topic with appropriate title, details, code, etc :wink:

1 Like

Thanks Gunner :slight_smile:

Ay the variable name is just a way to call an object of the type Simpletimer, every simpletimer object can hold 10 timed events, and every event has its specific ID for manipulation :slight_smile:

The type is SimpleTimer
You are a human

You call an object of Simpletimer, timer1
You are called doktor Emmet Brown

Timer1 can run ten timers
Emmet Brown can move ten fingers

I hope itā€™s clear enough :wink: