BLYNK_WRITE function not working when code loop() function code extends

I written below code. its working fine when only this code is in program. when i write some 200 lines of code, its not working when i press the virtual button in app. some one pls help.

BLYNK_WRITE(14) {
if (param.asInt()) {
analogWrite(D2, BRIGHT); SWITCH1 = 1;
LED1.on(); LED2.on(); LED3.on(); LED4.on();
} else {
analogWrite(D2, OFF); SWITCH1 = 0;
LED1.off(); LED2.off(); LED3.off(); LED4.off();
}
}

BLYNK_WRITE(12) {
if (param.asInt()) {
analogWrite(D3, BRIGHT); SWITCH2 = 1;
LED5.on(); LED6.on(); LED7.on(); LED8.on();
} else {
analogWrite(D3, OFF); SWITCH2 = 0;
LED5.off(); LED6.off(); LED7.off(); LED8.off();
}
}

This is the full code.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define DARK 100
#define DIM  95
#define OFF  0
#define BRIGHT  255

char auth[] = "19ae3bf62e6f4dfb8b1a8a2acfece730";
char ssid[] = "DIESEC";
char pass[] = "Dream@456";

WidgetLED IR1(V1), IR2(V2), LED1(V3), LED2(V4), LED3(V5), LED4(V6), LED5(V7), LED6(V8), LED7(V9), LED8(V10);

String binary, bit1, bit2, bit3, bit4, bit5;
const int AnalogIn  = A0;
int AnalogValue;

int LDR_VALUE, IR1_SENSOR, IR2_SENSOR, SWITCH1, SWITCH2;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(D2, OUTPUT);  pinMode(D3, OUTPUT);
  digitalWrite(D2, LOW);  digitalWrite(D3, LOW);
  pinMode(D0, INPUT);  pinMode(D1, INPUT);
}

BLYNK_WRITE(14) {
  if (param.asInt()) {
    analogWrite(D2, BRIGHT); SWITCH1 = 1;
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
  } else {
    analogWrite(D2, OFF); SWITCH1 = 0;
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
  }
}

BLYNK_WRITE(12) {
  if (param.asInt()) {
    analogWrite(D3, BRIGHT); SWITCH2 = 1;
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
  } else {
    analogWrite(D3, OFF); SWITCH2 = 0;
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
  }
}

void loop()
{
  Blynk.run();

  AnalogValue = analogRead(AnalogIn);
  IR1_SENSOR = digitalRead(D0);
  IR2_SENSOR = digitalRead(D1);

  Serial.print("LDR_VALUE:"); Serial.println(LDR_VALUE);
  Serial.print("IR1_SENSOR:"); Serial.println(IR1_SENSOR);
  Serial.print("IR2_SENSOR:"); Serial.println(IR2_SENSOR);
  Serial.print("SWITCH1:"); Serial.println(SWITCH1);
  Serial.print("SWITCH2:"); Serial.println(SWITCH2);


  if (AnalogValue <= 100){
    LDR_VALUE = 0;
    bit1 = "0";
  }
  else{
    LDR_VALUE = 1;
    bit1 = "1";
  }    
  if (IR1_SENSOR == 0) {
    bit2 = "0"; IR1.off();
  }
  else {
    bit2 = "1"; IR1.on();
  }
  if (IR2_SENSOR == 0) {
    bit3 = "0"; IR2.off();
  }
  else {
    bit3 = "1"; IR2.on();
  }
  if (SWITCH1 == 0)
    bit4 = "0";
  else
    bit4 = "1";
  if (SWITCH2 == 0)
    bit5 = "0";
  else
    bit5 = "1";

  binary = bit1 + bit2 + bit3 + bit4 + bit5;

  Blynk.virtualWrite(V11, binary);
  Serial.print("Binary:"); Serial.println(binary);
  Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  
  if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
//    delay(2000);
//    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
//    delay(2000);
//    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
//    delay(2000);
//    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
//    delay(2000);
//    analogWrite(D2, DIM);
//    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
//    delay(2000);
//    analogWrite(D2, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
//    delay(2000);
//    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
}

Are trying for the longest loop() record?

Your target for loop() is 2 lines.

SimpleTimer.

2 Likes

Indeed, wow!!

Hi.Thanks. Sorry i am new to blynk. How can i use the timer for loop

Is the below method correct?

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#define DARK 100
#define DIM  95
#define OFF  0
#define BRIGHT  255

char auth[] = "19ae3bf62e6f4dfb8b1a8a2acfece730";
char ssid[] = "DIESEC";
char pass[] = "Dream@456";

WidgetLED IR1(V1), IR2(V2), LED1(V3), LED2(V4), LED3(V5), LED4(V6), LED5(V7), LED6(V8), LED7(V9), LED8(V10);

SimpleTimer readTimer, writeTimer;

String binary, bit1, bit2, bit3, bit4, bit5;

const int AnalogIn  = A0;
const int LIGHT1 = D2;
const int LIGHT2 = D3;
const int IRS1 = D0;
const int IRS2 = D1;

int AnalogValue;

int LDR_VALUE, IR1_SENSOR, IR2_SENSOR, SWITCH1, SWITCH2;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(LIGHT1, OUTPUT);  pinMode(LIGHT2, OUTPUT);
  digitalWrite(LIGHT1, LOW);  digitalWrite(LIGHT2, LOW);
  pinMode(IRS1, INPUT);  pinMode(IRS2, INPUT);
  readTimer.setInterval(1000, readInput);
  writeTimer.setInterval(1000, setOutput);
}

BLYNK_WRITE(12) {
  if (param.asInt()) {
    LED1_ON();
  } else {
    LED1_OFF();
  }
}

BLYNK_WRITE(13) {
  if (param.asInt()) {
    LED2_ON();
  } else {
    LED2_OFF();
  }
}
void LED1_ON() {
  analogWrite(LIGHT1, BRIGHT);
  SWITCH1 = 1;
  LED1.on(); LED2.on(); LED3.on(); LED4.on();
}
void LED1_OFF() {
  analogWrite(LIGHT1, BRIGHT);
  SWITCH1 = 0;
  LED1.off(); LED2.off(); LED3.off(); LED4.off();
}
void LED1_DIM() {
  analogWrite(LIGHT1, DIM);
  SWITCH1 = 1;
  LED1.on(); LED2.on(); LED3.on(); LED4.on();
}
void LED2_ON() {
  analogWrite(LIGHT2, BRIGHT);
  SWITCH2 = 1;
  LED5.on(); LED6.on(); LED7.on(); LED8.on();
}
void LED2_OFF() {
  analogWrite(LIGHT2, BRIGHT);
  SWITCH2 = 0;
  LED5.off(); LED6.off(); LED7.off(); LED8.off();
}
void LED2_DIM() {
  analogWrite(LIGHT2, DIM);
  SWITCH2 = 1;
  LED5.on(); LED6.on(); LED7.on(); LED8.on();
}
void readInput() {
  AnalogValue = analogRead(AnalogIn);
  IR1_SENSOR = digitalRead(D0);
  IR2_SENSOR = digitalRead(D1);

  Serial.print("LDR_VALUE:"); Serial.println(LDR_VALUE);
  Serial.print("IR1_SENSOR:"); Serial.println(IR1_SENSOR);
  Serial.print("IR2_SENSOR:"); Serial.println(IR2_SENSOR);
  Serial.print("SWITCH1:"); Serial.println(SWITCH1);
  Serial.print("SWITCH2:"); Serial.println(SWITCH2);


  if (AnalogValue <= 100) {
    LDR_VALUE = 0;
    bit1 = "0";
  }
  else {
    LDR_VALUE = 1;
    bit1 = "1";
  }
  if (IR1_SENSOR == 0) {
    bit2 = "0"; IR1.off();
  }
  else {
    bit2 = "1"; IR1.on();
  }
  if (IR2_SENSOR == 0) {
    bit3 = "0"; IR2.off();
  }
  else {
    bit3 = "1"; IR2.on();
  }
  if (SWITCH1 == 0)
    bit4 = "0";
  else
    bit4 = "1";
  if (SWITCH2 == 0)
    bit5 = "0";
  else
    bit5 = "1";

  binary = bit1 + bit2 + bit3 + bit4 + bit5;

  Blynk.virtualWrite(V11, binary);
  Serial.print("Binary:"); Serial.println(binary);
  Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
void setOutput() {
  if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
    //    delay(2000);
    //    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, DIM);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
    //    delay(2000);
    //    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
    //    delay(2000);
    //    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
    //    delay(2000);
    //    analogWrite(D2, DIM);
    //    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
    //    delay(2000);
    //    analogWrite(D2, DIM);
  }
  else if (LDR_VALUE == 0 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
    //    delay(2000);
    //    analogWrite(D3, DIM);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 0 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 0 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 0) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, OFF);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 0 && SWITCH2 == 1) {
    LED1.off();    LED2.off();    LED3.off();    LED4.off();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, OFF);
    analogWrite(D3, BRIGHT);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 0) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.off();    LED6.off();    LED7.off();    LED8.off();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, OFF);
  }
  else if (LDR_VALUE == 1 && IR1_SENSOR == 1 && IR2_SENSOR == 1 && SWITCH1 == 1 && SWITCH2 == 1) {
    LED1.on();    LED2.on();    LED3.on();    LED4.on();
    LED5.on();    LED6.on();    LED7.on();    LED8.on();
    analogWrite(D2, BRIGHT);
    analogWrite(D3, BRIGHT);
  }
}
void loop()
{
  Blynk.run();
  readTimer.run();
  writeTimer.run();
}

@rravivarman had a quick look at your code and that looks much better.

You should check that all the widgets are set as PUSH frequency in your app now that you have set the hardware to send and receive the data with the timer. ESP’s can get confused if the app and the hardware are making the requests at the same time.

thanks. how to set that. i am not able to find PUSH Frequency settings in application.

given the video link of my app. pls verify.

https://dl.dropboxusercontent.com/u/12382973/2017_02_06_20_46_41.mp4

@rravivarman PUSH is not a general setting in the app, it is specific to certain widgets.

So Value Display’s, LCD and Gauge’s etc have a READING FREQUENCY option of PUSH 250ms, 500ms right up to 59 seconds. You might not have any widgets that use READING FREQUENCY, e.g. buttons and sliders, but if you do I would set them all as PUSH.

Most Blynkers have at least one Value Display widget and the default setting is a reasonable 1s but can cause problems if your sketch has the same virtualWrite’s being sent to the server.

You need to go into each of your widgets to check the setting and go for PUSH unless you have a specific need not to PUSH the data to the server from your sketch. PUSH gives you more control, stop, start etc.

@rravivarman watched your video and I saw LDR widget set at 1 second and you need to check the one with the value of 10000. Others should be OK.

thanks friend. will make the changes and update you.

OK Friend :slight_smile: