Getting Error with timer

hello! blynkers
Getting error in serial monitor as well as nothing works blynk keeps connecting and disconnecting

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

here is the code



/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char auth[] = "***************************";
/* WiFi credentials */
char ssid[] = "**********";
char pass[] = "************";


/// OTA dependencies ///
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <WiFiClient.h>
WiFiClient client;
/* TIMER */
#include <SimpleTimer.h>

BlynkTimer timer1;
#define TRIGGERPIN D0
#define ECHOPIN    D1

//float temp;
float Dist;
unsigned long Settime;
float duration, distance1, distance2;
float distance3;
int relay1 = 4;
int relay2 = 0;
int relay3 = 2;
int relay4 = 14;
int relay5 = 12;
int relay6 = 13;
int relay7 = 15;
int relay8 = 1;

const char* fwImageURL = "url here";
void setup() 
{
  Serial.begin(115200);
  pinMode(TRIGGERPIN, OUTPUT);
  pinMode(ECHOPIN, INPUT);
   pinMode(relay1, OUTPUT);  // declare LED as output
  pinMode(relay2, OUTPUT);  // declare LED as output
  pinMode(relay3, OUTPUT);  // declare LED as output
  pinMode(relay4, OUTPUT);  // declare LED as output
  pinMode(relay5, OUTPUT);  // declare LED as output
  pinMode(relay6, OUTPUT);  // declare LED as output
  pinMode(relay7, OUTPUT);  // declare LED as output
  pinMode(relay8, OUTPUT);  // declare LED as output
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
    digitalWrite(relay3, HIGH);
      digitalWrite(relay4, HIGH);
        digitalWrite(relay5, HIGH);
          digitalWrite(relay6, HIGH);
            digitalWrite(relay7, HIGH);
              digitalWrite(relay8, HIGH);
  Blynk.begin(auth, ssid, pass);

  SimpleTimer timer1; 
}
 
 void loop() 
{
   readinputs();
   controlOutputs();
   controlOutputoff();
   
   Blynk.run();
  timer1.run();

}

BLYNK_WRITE(V100)
{
  int pinValue = param.asInt();

  if (pinValue == 1) {
    InstallUpdates();
  }

}
void InstallUpdates() {
  Serial.println( "OTA Update Request Received" );
  Serial.print( "Firmware URL: " );
  Serial.println( fwImageURL );

  HTTPClient httpClient;
  httpClient.begin( fwImageURL );
  int httpCode = httpClient.GET();
  if ( httpCode == 200 ) {

    Serial.println( "Update file found, starting update" );
    // Set virtual pin to 1023 so the LED widget in the Blynk app lights up to show that the upgrade started
    Blynk.virtualWrite(V101, 255);
    Blynk.setProperty(V101, "label", "UPDATING");

    t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL );

    switch (ret) {
      case HTTP_UPDATE_FAILED:
        Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
        break;
    }
  }
  else {
    Serial.print( "Firmware check failed, got HTTP response code " );
    Serial.println( httpCode );
  }
  httpClient.end();
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/


void readinputs()
//Sends data values to Blynk
{
 
  float duration, distance1, distance2;
  float distance3;
  digitalWrite(TRIGGERPIN, LOW);  
  delayMicroseconds(3); 
  
  digitalWrite(TRIGGERPIN, HIGH);
  delayMicroseconds(12); 
  
  digitalWrite(TRIGGERPIN, LOW);
  duration = pulseIn(ECHOPIN, HIGH);
  distance1 = (duration/2) / 29.1;
  distance2 = (duration/2) / 74.1;
  distance3 =  distance2/12;
  
  Serial.println(distance1);
  Serial.println(distance2);
  Serial.println(distance3);
  Serial.println("Cm");
   Serial.println("In");
   Serial.println("feet");
}
BLYNK_WRITE(V1)
{
  Dist = param.asInt();
  Serial.print (" Set Distance ");
  Serial.println (Dist);
 Blynk.syncVirtual(V1);
}
BLYNK_WRITE(V2)
{
  Settime = param.asInt();
  Serial.print ("Set Time ");
  Serial.println (Settime);
 Blynk.syncVirtual(V2);
}
void controlOutputs()

  {
   if (distance3 <= Dist)
   {
  digitalWrite (relay1, LOW);
    digitalWrite (relay2, LOW);
    digitalWrite (relay3, LOW);
    digitalWrite (relay4, LOW);
    digitalWrite (relay5, LOW);
    digitalWrite (relay6, LOW);
    digitalWrite (relay7, LOW);
    digitalWrite (relay8, LOW);
    timer1.setTimeout(Settime*60000, controlOutputoff);
    Serial.print("Relays are On");
    }                                  

  }

  void controOutputoff()
  {
        
 digitalWrite (relay1, HIGH);
    digitalWrite (relay2, HIGH);
    digitalWrite (relay3, HIGH);
    digitalWrite (relay4, HIGH);
    digitalWrite (relay5, HIGH);
    digitalWrite (relay6, HIGH);
    digitalWrite (relay7, HIGH);
    digitalWrite (relay8, HIGH);

    }
  
  
  


Okay, a few observations…

You’ve not included much of the important information that yuou were asked for whne you created this topic:

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

You are mixing “D” pin numbers with GPIO pin numbers, which makes your code very difficult to unpick/ I’d suggest that you stick with GPIO numbers.

You are trying to do too much with a single ESP8266, and I’m guessing that your board is going into programming mode because pin GPIO0 is being pulled LOW at startup by you hardware.

You can test thus by removing the connections from your board (except the USB cable) and see if it boots.

You should read this:

and if you want to control an 8-way relay then either:

  • use multiple ESP8266’s and some Blynk Bridge code
  • switch to an ESP32
  • or use an MCP23017 IO Expansion Board like this:

Your void loop is a mess, and you need to read this:

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

then take these out of your void loop:

Pete.

Thanks for swift reply
Board is Node MCU and hc-sr04 ultrasonic sensor
Phone Android
Blynk Server
blynk Library 0.6.1
using slider in blynk app for setting distance and time

Nothing is connected to GPIO 0 only declared

Changed The code a bit now the error is gone but not working neither see any serial data in monitor


/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char auth[] = "***************";
/* WiFi credentials */
char ssid[] = "********";
char pass[] = "********";


/// OTA dependencies ///
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <WiFiClient.h>
WiFiClient client;
/* TIMER */
#include <SimpleTimer.h>

BlynkTimer timer1;
BlynkTimer timer2;
BlynkTimer timer3;
#define TRIGGERPIN 16
#define ECHOPIN    5

//float temp;
float Dist;
unsigned long Settime;
float duration, distance1, distance2;
float distance3;
int relay1 = 4;
int relay2 = 0;
int relay3 = 2;
int relay4 = 14;
int relay5 = 12;
int relay6 = 13;
int relay7 = 15;
int relay8 = 1;

const char* fwImageURL = "url here";
void setup() 
{
  Serial.begin(115200);
  pinMode(TRIGGERPIN, OUTPUT);
  pinMode(ECHOPIN, INPUT);
   pinMode(relay1, OUTPUT);  // declare LED as output
  pinMode(relay2, OUTPUT);  // declare LED as output
  pinMode(relay3, OUTPUT);  // declare LED as output
  pinMode(relay4, OUTPUT);  // declare LED as output
  pinMode(relay5, OUTPUT);  // declare LED as output
  pinMode(relay6, OUTPUT);  // declare LED as output
  pinMode(relay7, OUTPUT);  // declare LED as output
  pinMode(relay8, OUTPUT);  // declare LED as output
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
    digitalWrite(relay3, HIGH);
      digitalWrite(relay4, HIGH);
        digitalWrite(relay5, HIGH);
          digitalWrite(relay6, HIGH);
            digitalWrite(relay7, HIGH);
              digitalWrite(relay8, HIGH);
  Blynk.begin(auth, ssid, pass);
  timer2.setInterval(1000,readinputs);

  SimpleTimer timer1; 
}
 
 void loop() 
{
   
   
   
   
   Blynk.run();
  timer1.run();
  timer2.run();
 
}

BLYNK_WRITE(V100)
{
  int pinValue = param.asInt();

  if (pinValue == 1) {
    InstallUpdates();
  }

}
void InstallUpdates() {
  Serial.println( "OTA Update Request Received" );
  Serial.print( "Firmware URL: " );
  Serial.println( fwImageURL );

  HTTPClient httpClient;
  httpClient.begin( fwImageURL );
  int httpCode = httpClient.GET();
  if ( httpCode == 200 ) {

    Serial.println( "Update file found, starting update" );
    // Set virtual pin to 1023 so the LED widget in the Blynk app lights up to show that the upgrade started
    Blynk.virtualWrite(V101, 255);
    Blynk.setProperty(V101, "label", "UPDATING");

    t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL );

    switch (ret) {
      case HTTP_UPDATE_FAILED:
        Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
        break;
    }
  }
  else {
    Serial.print( "Firmware check failed, got HTTP response code " );
    Serial.println( httpCode );
  }
  httpClient.end();
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/


void readinputs()
//Sends data values to Blynk
{
 
  float duration, distance1, distance2;
  float distance3;
  digitalWrite(TRIGGERPIN, LOW);  
  delayMicroseconds(3); 
  
  digitalWrite(TRIGGERPIN, HIGH);
  delayMicroseconds(12); 
  
  digitalWrite(TRIGGERPIN, LOW);
  duration = pulseIn(ECHOPIN, HIGH);
  distance1 = (duration/2) / 29.1;
  distance2 = (duration/2) / 74.1;
  distance3 =  distance2/12;
  
  Serial.println(distance1);
  Serial.println(distance2);
  Serial.println(distance3);
  Serial.println("Cm");
   Serial.println("In");
   Serial.println("feet");
}
BLYNK_WRITE(V1)
{
  Dist = param.asInt();
  Serial.print (" Set Distance ");
  Serial.println (Dist);
 Blynk.syncVirtual(V1);
}
BLYNK_WRITE(V2)
{
  Settime = param.asInt();
  Serial.print ("Set Time ");
  Serial.println (Settime);
 Blynk.syncVirtual(V2);
}
void controlOutputs()

  {
   if (distance3 <= Dist)
   {
  digitalWrite (relay1, LOW);
    digitalWrite (relay2, LOW);
    digitalWrite (relay3, LOW);
    digitalWrite (relay4, LOW);
    digitalWrite (relay5, LOW);
    digitalWrite (relay6, LOW);
    digitalWrite (relay7, LOW);
    digitalWrite (relay8, LOW);
    timer1.setTimeout(Settime*60000, controlOutputoff);
    Serial.print("Relays are On");
    }                                  

  }

  void controlOutputoff()
  {
        
 digitalWrite (relay1, HIGH);
    digitalWrite (relay2, HIGH);
    digitalWrite (relay3, HIGH);
    digitalWrite (relay4, HIGH);
    digitalWrite (relay5, HIGH);
    digitalWrite (relay6, HIGH);
    digitalWrite (relay7, HIGH);
    digitalWrite (relay8, HIGH);

    }
  
  
  

Well, you don’t need to declare multiple timer objects. Each BlynkTimer object can support 16 different timers.
And things are going to get5 very messy with this line in there:

What baud rate are you selecting in your serial monitor?
Have you removed all of the connections to your board except the USB cable?

Pete.

Baud Rate 115200
Yes all he connection have ben removed

I am not sure how to implement this thing


BlynkTimer timer;


  Blynk.run();
  timer.run();


 timer.setInterval(1000,readinputs);

 timer.setTimeout(Settime*60000, controlOutputoff);

You only need one timer object.

I’d recommend that you set your serial monitor to 74880 and use the same baud rate in your Serial.begin command, as the native baud rate for most NodeMCUs is 74880

This should allow you to see boot messages (like the data that you thought was an error message) and debug messages in the same serial monitor screen without changing baud rates.

Pete.

this line is causing reset boot error how to resolve this now
taking value from blynk slider and multiply it with 60000 to convert it to minute

Well, without seeing what you’ve done with your latest version of the code, it’s very difficult to comment.

But, before you do post your latest code I’d suggest that you take a few minutes to sort-out the formatting so that it’s easier to read.

Pete.

I was having problem with HC-SR04 ultrasonic sensor so I have changed that to HC-SR501 PIR Motion Sensor
Now the problem is Cant get PIR state

code for setting delay for relay on time through blynk app

BLYNK_WRITE(V0) {
slider_time = param.asInt() * 60000L; // timer switch
  Serial.println(slider_time);
 
}

Here is the full code

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "*********************"; //Auth Token in the Blynk App.


// Set password to "" for open networks.
char ssid[] = "***********"; // WiFi SSID.
char pass[] = "***********";  // WiFi Password.


//Start Initialize PIN//

int Status = 12;
int sensor = 16;
int relay1 = 5;
int relay2 = 4;
int relay3 = 0;
int relay4 = 14;
int relay5 = 12;
int relay6 = 13;
int relay7 = 15;
int relay8 = 3;
long slider_time;
int state = LOW;
int val = 0;
//End Initialize Pin//

BlynkTimer timer;
//get data stored in virtual pin V0 from server
BLYNK_CONNECTED() {

  Blynk.syncVirtual(V0);
}

BLYNK_WRITE(V0) {
slider_time = param.asInt() * 60000L; // timer switch
  Serial.println(slider_time);
 
}



void setup() {


  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  pinMode(sensor, INPUT); // declare sensor as input
  pinMode(Status, OUTPUT);  // declare LED as output
  pinMode(relay1, OUTPUT);  // declare LED as output
  pinMode(relay2, OUTPUT);  // declare LED as output
  pinMode(relay3, OUTPUT);  // declare LED as output
  pinMode(relay4, OUTPUT);  // declare LED as output
  pinMode(relay5, OUTPUT);  // declare LED as output
  pinMode(relay6, OUTPUT);  // declare LED as output
  pinMode(relay7, OUTPUT);  // declare LED as output
  pinMode(relay8, OUTPUT);  // declare LED as output
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  digitalWrite(relay5, HIGH);
  digitalWrite(relay6, HIGH);
  digitalWrite(relay7, HIGH);
  digitalWrite(relay8, HIGH);
 timer.setInterval(1000L, read_sensor);

}

void read_sensor()
{
 int state = digitalRead(sensor);
 }

void relays_on()
{
if (state == HIGH)
  {
    digitalWrite (Status, HIGH);
    digitalWrite (relay1, LOW);
    digitalWrite (relay2, LOW);
    digitalWrite (relay3, LOW);
    digitalWrite (relay4, LOW);
    digitalWrite (relay5, LOW);
    digitalWrite (relay6, LOW);
    digitalWrite (relay7, LOW);
    digitalWrite (relay8, LOW);

    Serial.println("Motion detected!");
    
   timer.setTimeout(slider_time, relays_off);
  }
}

  void relays_off()
{
    digitalWrite (Status, LOW);
    digitalWrite (relay1, HIGH);
    digitalWrite (relay2, HIGH);
    digitalWrite (relay3, HIGH);
    digitalWrite (relay4, HIGH);
    digitalWrite (relay5, HIGH);
    digitalWrite (relay6, HIGH);
    digitalWrite (relay7, HIGH);
    digitalWrite (relay8, HIGH);
   Serial.println("Motion absent!");
  }





void loop() {


  Blynk.run();
  timer.run();

}

How do you know this?

Pete.

R

Relays not turning on

Well, that’s because you aren’t calling the relays_on or relays_off functions.

Pete.

Thanks now it works…