[SOLVED] Issues creating a auto/manual pump control

Void Auto(){

void OFF(){

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
#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
  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
  Blynk.begin(Serial, auth);

void loop()

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);

void OFF(){
  digitalWrite(relay1, LOW);

void Manual(){




  button2 = param.asInt();

  selectmode = param.asInt();
  if(selectmode ==1){
     timer3=  timer.setInterval(1000, Manual);

   timer1 = timer.setInterval(10000, Auto);



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);

void OFF(){
  digitalWrite(relay1, LOW);

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:


@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);
  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);

void OFF(){
  digitalWrite(relay1, LOW);


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)

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

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:


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: