BLYNK_WRITE command not working after some seconds

Hello everyone, i have 6 sensors and 4 led on my circuit. And 4 button for leds. After blynk connected i am getting last status of led. But after my all sensor read i cant control the buttons. When sensor read not completed i can control leds with button but after the sensor read connection drops. Can someone help me ? Thanks for the help


#define BLYNK_PRINT SwSerial

#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleStream.h>
#define ledPin1    4 
#define ledPin2    5
#define ledPin3    6
#define ledPin4    7


#define vPin1    V12 
#define vPin2    V13
#define vPin3    V14
#define vPin4    V15 

#define sensor1  A0
#define sensor2  A1
#define sensor3  A2
#define sensor4  A3
#define sensor5  A4

float temp;


char auth[] = "Rn4MzFKwTAxOIljim9N_O6mGI3XUtgcQ";

int i=0;
int switch_1_ON = 0;
int ledPinState1 = LOW;
int ledPinState2 = LOW;
int ledPinState3 = LOW;
int ledPinState4 = LOW;


BlynkTimer timer; 

BLYNK_CONNECTED() {

  // Request the latest state from the server

  Blynk.syncVirtual(vPin1);
  Blynk.syncVirtual(vPin2);
  Blynk.syncVirtual(vPin3);
  Blynk.syncVirtual(vPin4);

  // Alternatively, you could override server state using:
 // Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
 // Blynk.virtualWrite(VPIN_BUTTON_2, relay2State);
 // Blynk.virtualWrite(VPIN_BUTTON_3, relay3State);
 // Blynk.virtualWrite(VPIN_BUTTON_4, relay4State);

}


void oku(){
  
  //sensör 1 için
  int SensorValue = analogRead(sensor1);   
  float SensorVolts = analogRead(sensor1)*0.0048828125;
  float SensorYuzde= analogRead(sensor1)/10;   
  if(SensorYuzde >= 100){
    SensorYuzde = 100;
  }
  Blynk.virtualWrite(V5,SensorYuzde);
 //sensor 2 için
 int SensorValue2 = analogRead(sensor2);   
  float SensorVolts2 = analogRead(sensor2)*0.0048828125;
  float SensorYuzde2= analogRead(sensor2)/10;   
  if(SensorYuzde2 >= 100){
    SensorYuzde2 = 100;
  }
  
    Blynk.virtualWrite(V6,SensorYuzde2);
  //sensor 3 için
 int SensorValue3 = analogRead(sensor3);   
  float SensorVolts3 = analogRead(sensor3)*0.0048828125;
  float SensorYuzde3= analogRead(sensor3)/10;   
  if(SensorYuzde3 >= 100){
    SensorYuzde3 = 100;
  }
  Blynk.virtualWrite(V2,SensorYuzde3);
  //sensor 4 için
 int SensorValue4 = analogRead(sensor4);   
  float SensorVolts4 = analogRead(sensor4)*0.0048828125;
  float SensorYuzde4= analogRead(sensor4)/10;   
  if(SensorYuzde4 >= 100){
    SensorYuzde4 = 100;
    
  }
  Blynk.virtualWrite(V1,SensorYuzde4);
  //sensor water için
int SensorValue5 = analogRead(sensor5);   
  float SensorVolts5 = analogRead(sensor5)*0.0048828125;
  float SensorYuzde5= analogRead(sensor5)/10;   
  if(SensorYuzde5 >= 100){
    SensorYuzde5 = 100;
  }
  Blynk.virtualWrite(V4,SensorYuzde5);
//sıcaklık için
  temp= analogRead(A5);
  int temperature = (temp * 500)/1024;
  Blynk.virtualWrite(V3,temperature);
  
  
  lcd.setCursor(14, 2);  
  lcd.print(SensorValue);
  lcd.setCursor(9, 3);  
  lcd.print(SensorVolts);     
  lcd.print(" V");
  delay(1000);

}
/*int sensorOkuma(int SensorPin){
  int Value = analogRead(SensorPin);   
  float volts = analogRead(SensorPin)*0.0048828125;
  float yuzde= analogRead(SensorPin)/10;   
  if(yuzde >= 100){
    yuzde = 100;
  }
  return yuzde;
}*/

BLYNK_WRITE(vPin1) {
  ledPinState1 = param.asInt();
  digitalWrite(ledPin1, ledPinState1);
}

BLYNK_WRITE(vPin2) {
  ledPinState2 = param.asInt();
  digitalWrite(ledPin2, ledPinState2);
}
BLYNK_WRITE(vPin3) {
  ledPinState3 = param.asInt();
  digitalWrite(ledPin3, ledPinState3);
}
BLYNK_WRITE(vPin4) {
  ledPinState4 = param.asInt();
  digitalWrite(ledPin4, ledPinState4);
}



void setup()
{
  
 pinMode(ledPin1, OUTPUT);
  digitalWrite(ledPin1, ledPinState1);
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin2, ledPinState2);
  pinMode(ledPin3, OUTPUT);
  digitalWrite(ledPin3,ledPinState3);
  pinMode(ledPin4, OUTPUT);
  digitalWrite(ledPin4,ledPinState4);

  
 
  
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  // Print a message to the LCD.
  lcd.setCursor(0,2);
  lcd.print("Analog Value: ");
  lcd.setCursor(0,3);
  lcd.print("Voltage: ");
  // Debug console
  SwSerial.begin(9600);
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop() {
  Blynk.run();
 timer.run();
  timer.setInterval(500L, oku);



}

Here on blynk side

This should be in void setup, not void loop.

You have a 1 second blocking delay in your oku function, and that functions is being called once every 0.5 seconds. Can you see why that might be an issue?

You should remove the delay, and increase the timer interval - you really don’t need to be reading your sensors twice per second!

Do you have an FTDI adapter attached to your software serial port?

Pete.

Thanks for the help sir. Deleting delay solved my problem. Thanks a lot

1 Like