Connecting, disconnecting problem please fix the problem

#define BLYNK_TEMPLATE_ID           "TMPL32u7FuTK"
#define BLYNK_TEMPLATE_NAME         "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "VQVdGFEkxzUB1GWN5tym_9pHiiUMgFdl"




#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <analogWrite.h>
#include <WiFi.h>
#include <SPI.h>
#include <WiFiclient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>




char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "poco m3 pro 5g";
char pass [] = "12345789";





#define IR1 5 // IR sensor 1
#define IR2 18 // IR sensor 2
#define IR3 19 // IR sensor 3
#define IR4 23 // IR sensor 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET
#define SCREEN_ADDRESS 0x3C




//end……………………………………………………………………………




Adafruit_SSD1306 display('SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET');
int pos;
int med1 = 0;
int med2 = 0;
int med3 = 0;
int med4 = 0;
boolean counter1 = false;
boolean counter2 = false;
boolean counter3 = false;
boolean counter4 = false;
int x = 0;
int y = 16;



// Servo 


const int servoCount = 4;
static const int servosPins[servoCount] = {12, 14, 27, 26};
Servo servos[servoCount] ;
//—----------------------------------------------------------------------------------


void countmed1 (){
if (counter1 == true) {
   counter1 = false;
   med1 = med1 + 1;
   Serial.print("Number og medl = ") ;
   Serial.println (med1/2) ;
   Blynk.virtualWrite(V0,med1/2) ;
   if (med1 >= 30) {
     Blynk.logEvent("containerl_full") ;
  }  
}




}
void countmed2 () {
if (counter2 == true) {
    counter2 = false;
    med2 = med2 + 1;
    Serial. print ("Number og med2 = ") ;
    Serial. println (med2/2) ;
    Blynk . virtualWrite (V1, med2/2) ;
    if (med2 >= 30) {
      Blynk.logEvent ("container2_full") ;
    }
  } 


}
//end……………………………………………………………………………




void countmed3(){
if (counter3 == true) {
   counter3 = false;
   med3 = med3 + 1;
   Serial. print ("Number og med3 = ");
   Serial. println (med3/2) ;
   Blynk . virtualWrite (V2, med3/2);
   if (med3 >= 30) {
     Blynk.logEvent ("container3_full");
    }
  }

}      
void countmed4() {
  if (counter4 == true) {
    counter4 = false;
    med4 = med4 + 1;
    Serial. print ("Number og med4 = ") ;
    Serial. println (med4/2) ;
    Blynk . virtualWrite (V3, med4/2) ;
    if (med4 >= 30) {
      Blynk.logEvent ("container4_full") ;

//end………………………………………………………..
    }
  }

}

void docounter1 () {
  counter1 = true;
}
void docounter2 () {
  counter2 = true;
}
void docounter3 () {
  counter3 = true;
}
void docounter4 () {
  counter4 = true;
}
void myTimerEvent()
{
    // You can send any value at any time.
    // Please don't send more that 10 values per second.
    Blynk.virtualWrite (V4, millis() / 1000);
} 


void oledAleart () {

//end………………………………………………………………………………
  if (med1 <= 4 && med2 <= 4 && med3 <= 4 && med4<=4 ) {
     display. clearDisplay () ;
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display . println (F ("LOW DRUGS") ) ;
     display. setCursor (1, 30) ;
     display . setTextSize (1) ;
     display . println (F ("Please fill") ) ;
     display . setCursor (1, 37) ;
     display. println (F("all container")) ;
     display. display () ;
  }
  else if (med1 >= 30 && med2 >= 30 && med3 >= 30 && med4 >= 30) {
     display . clearDisplay ();
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display. println (F ("FULL DRUGS") ) ;
     display . setCursor (1, 30) ;
     display . setTextSize (1) ;




//end…………………………………………………………………………………………………….
     display . println (F ("Have a") ) ;
     display . setCursor (1, 37) ;
     display . println (F ("nice day") ) ;
     display . display () ;
   }
}
//end……………………………………………………………………………………………..
  BlynkTimer timer;

  BLYNK_WRITE (V4) {
    int value = param. asInt ( ) ;
    if (value = true) {
      med1 = 0;  
      med2 = 0;
      med3 = 0;
      med4 = 0;
      Blynk . virtualWrite (V0, med1/2) ;
      Blynk . virtualWrite (V1, med2/2) ;
      Blynk . virtualWrite (V2, med3/2) ;
      Blynk . virtualWrite (V3, med4/2) ;
      display . clearDisplay () ;
      display . setTextSize (2) ;
      display . setTextColor (SSD1306_WHITE) ;
      display . setCursor (20, 2) ;
      display . println (F ("RESETING") ) ;
      display . display () ;
      delay (3000) ;
   }
}
//end………………………………………………………………………………………………….




  BLYNK_WRITE (V5) {
    int value = param. asInt () ;
    int pos = 0 ;
    Serial. println ("Now, Container 1 is working") ;
    Serial. println (value) ;
    if (value >= 1) {
      med1 = med1 - 2;
      Serial. print ("Number og medi = ") ;
      Serial. println (med1/2) ;
      Blynk . virtualWrite (V0, med1/2) ;
      for (pos = 0; pos <= 61; pos += 1) {
        servos [0] . write (pos) ;
        delay (15) ;
      }
      for (pos = 61; pos >= 0; pos -= 1) {
        servos [0].write (pos) ;
      }        
      if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
         Blynk.logEvent("out_off medicine", "Please fill up all containers ! ! ! !");
         display.clearDisplay();
         display.setTextSize(2);
         display.setTextColor(SSD1306_WHITE);
         display.setCursor(1,4);
         display.println (F("OUT OFF"));
         display.setCursor (1,20);
         display.println (F ("Medicine"));




//end………………………………………………………………………………………………..




      }
      else if (med1 <= 4) {
      Blynk.logEvent("container_1_low","Please fill medicine in the container 1" ) ;
      }
    }
}
BLYNK_WRITE (V6) {
   int value = param. asInt () ;
   int pos = 0 ;
   Serial. println ("Now, Container 2 is working") ;
   if (value >= 1) {
     med2 = med2 - 2;
     Serial. print ("Number og med2 = ") ;
     Serial . println (med2/2) ;
//end………………………………………………………………………………………


     delay (15) ;
   }
   for (pos = 61; pos >= 0; pos -= 1) {
     servos [0].write(pos) ;
   }
   if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
      Blynk.logEvent ("out_off medicine", "Please fill up all containers ! ! ! !");
      display.clearDisplay ();
      display.setTextSize (2) ;
      display.setTextColor(SSD1306_WHITE);
      display.setCursor (1,4);
      display.println (F("OUT OFF"));
      display.setCursor (1,20) ;
      display.println (F ("Medicine"));
  }
  else if (med1 <= 4)
  {
    Blynk.logEvent("container_1_low","Please fill medicine in the container 1" );
  }

}


BLYNK_WRITE (V7) {
  int value = param.asInt();
  int pos = 0 ;
  Serial.println("Now, Container 2 is working") ;
  if (value >= 1)
  {
    med2 = med2 - 2;
    Serial.print ("Number og med2 = ") ;
    Serial.println (med2/2) ;
    Blynk.virtualWrite(V1,med2/2);
  } 

//end………………………………………………………………………………………………… 

}
   void setup(){
   Serial.begin(115200);
   Blynk.begin(auth,ssid,pass) ;
   pinMode(IR1, INPUT);
   pinMode(IR2, INPUT);
   pinMode(IR3, INPUT);
   pinMode(IR4, INPUT);
   attachInterrupt(digitalPinToInterrupt(IR1) , docounter1, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR2) , docounter2, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR3), docounter3, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR4) , docounter4, RISING) ;
   timer.setInterval(1000L, myTimerEvent);
   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
      Serial.println(F("SSD1306 allocation failed") ) ;
      for (;;) ; // Don't proceed, loop forever
   }
   display . display () ;
   delay (2000) ;
   // Clear the buffer
   display.clearDisplay();
   display.setTextSize(2); // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE);          // Draw white text
   display.setCursor (1,4);               // Start at top-left corner
   display.println (F("STARTING.."));
   display.setTextSize(1.5);
   display.setCursor(2,25);          // Start at top-left corner
   //end…………………………………………………………………………………
   
   display.println(F("PLEASE SETUP"));
   display.setCursor(2,40);
   display.println(F("ON BLYNK"));
   display.drawLine(0, 0, 0, 60, SSD1306_WHITE);
   display.drawLine(0, 60, 127, 60, SSD1306_WHITE);
   display.drawLine(127, 60, 127, 0, SSD1306_WHITE);
   display.drawLine(127, 0, 0, 0, SSD1306_WHITE);
   display.display();
   delay(5000);
   for(int i = 0; i < servoCount; ++i) {
     servos [i] .attach (servosPins[i]);
   }
    }  
    void loop() {
   Blynk.run () ;
   timer.run () ;
   countmed1 () ;
   countmed2 () ;
   countmed3 () ;
   countmed4 () ;
   oledAleart () ;
} 

//end

please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly. Triple backticks look like this: ```

BTW why are you showing us your code? Is there something amazing going on in it or having problems?

1 Like

You did not answer my question. Please explain the problem you are facing.

Also read this :point_down:t2:

@Sree I’d start by posting the ACTUAL CODE you are running, not a sketch that wont even compile.

I’d also read this:

I’ve also deleted your other two topics that are about the same issue. Please stop spamming the forum in this way, otherwise your login will be suspended.

Pete.

Can you please fix that problem

Anyone please help :pensive:.

The person that is going to fix the problem is you. It’s your project, and you have the hardware in front of you to do the testing. You also understand what the project is meant to do - which we don’t - and you know all the answers to the questions asked in the “Recommendations for creating a new topic…” post - something else that we don’t have.

@Madhukesh has already pointed-out one problem with the structure of the sketch you’ve posted, but personally I’m not looking any further than the lines of code that tell me that this isn’t the actual sketch you are using, because it’s going to be impossible to compile.

Forum members will help you by pointing you in the right direction - provided you follow the forum rules and provide the necessary background information - but they won’t (and can’t) solve your problems for you.

Pete.

@Madhukesh pointed one problem
But still we facing the same issue
@PeteKnight this is a code for Automatic medicine dispensor using esp32 and other components servo moters, oled display,Photoelectric IR counter. Please fix the app related issue. :pray:

#define BLYNK_TEMPLATE_NAME         "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "VQVdGFEkxzUB1GWN5tym_9pHiiUMgFdl"




#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <analogWrite.h>
#include <WiFi.h>
#include <SPI.h>
#include <WiFiclient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>




char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "poco m3 pro 5g";
char pass [] = "12345789";





#define IR1 5 // IR sensor 1
#define IR2 18 // IR sensor 2
#define IR3 19 // IR sensor 3
#define IR4 23 // IR sensor 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C




//end……………………………………………………………………………




Adafruit_SSD1306 display('SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET');
int pos;
int med1 = 0;
int med2 = 0;
int med3 = 0;
int med4 = 0;
boolean counter1 = false;
boolean counter2 = false;
boolean counter3 = false;
boolean counter4 = false;
int x = 0;
int y = 16;



// Servo 


const int servoCount = 4;
static const int servosPins[servoCount] = {12, 14, 27, 26};
Servo servos[servoCount] ;
//—----------------------------------------------------------------------------------


void countmed1 (){
if (counter1 == true) {
   counter1 = false;
   med1 = med1 + 1;
   Serial.print("Number og medl = ") ;
   Serial.println (med1/2) ;
   Blynk.virtualWrite(V0,med1/2) ;
   if (med1 >= 30) {
     Blynk.logEvent("containerl_full") ;
  }  
}




}
void countmed2 () {
if (counter2 == true) {
    counter2 = false;
    med2 = med2 + 1;
    Serial. print ("Number og med2 = ") ;
    Serial. println (med2/2) ;
    Blynk . virtualWrite (V1, med2/2) ;
    if (med2 >= 30) {
      Blynk.logEvent ("container2_full") ;
    }
  } 


}
//end……………………………………………………………………………




void countmed3(){
if (counter3 == true) {
   counter3 = false;
   med3 = med3 + 1;
   Serial. print ("Number og med3 = ");
   Serial. println (med3/2) ;
   Blynk . virtualWrite (V2, med3/2);
   if (med3 >= 30) {
     Blynk.logEvent ("container3_full");
    }
  }

}      
void countmed4() {
  if (counter4 == true) {
    counter4 = false;
    med4 = med4 + 1;
    Serial. print ("Number og med4 = ") ;
    Serial. println (med4/2) ;
    Blynk . virtualWrite (V3, med4/2) ;
    if (med4 >= 30) {
      Blynk.logEvent ("container4_full") ;

//end………………………………………………………..
    }
  }

}

void docounter1 () {
  counter1 = true;
}
void docounter2 () {
  counter2 = true;
}
void docounter3 () {
  counter3 = true;
}
void docounter4 () {
  counter4 = true;
}
void myTimerEvent()
{
    // You can send any value at any time.
    // Please don't send more that 10 values per second.
    Blynk.virtualWrite (V4, millis() / 1000);
} 


void oledAleart () {

//end………………………………………………………………………………
  if (med1 <= 4 && med2 <= 4 && med3 <= 4 && med4<=4 ) {
     display. clearDisplay () ;
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display . println (F ("LOW DRUGS") ) ;
     display. setCursor (1, 30) ;
     display . setTextSize (1) ;
     display . println (F ("Please fill") ) ;
     display . setCursor (1, 37) ;
     display. println (F("all container")) ;
     display. display () ;
  }
  else if (med1 >= 30 && med2 >= 30 && med3 >= 30 && med4 >= 30) {
     display . clearDisplay ();
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display. println (F ("FULL DRUGS") ) ;
     display . setCursor (1, 30) ;
     display . setTextSize (1) ;




//end…………………………………………………………………………………………………….
     display . println (F ("Have a") ) ;
     display . setCursor (1, 37) ;
     display . println (F ("nice day") ) ;
     display . display () ;
   }
}
//end……………………………………………………………………………………………..
  BlynkTimer timer;

  BLYNK_WRITE (V4) {
    int value = param. asInt ( ) ;
    if (value = true) {
      med1 = 0;  
      med2 = 0;
      med3 = 0;
      med4 = 0;
      Blynk . virtualWrite (V0, med1/2) ;
      Blynk . virtualWrite (V1, med2/2) ;
      Blynk . virtualWrite (V2, med3/2) ;
      Blynk . virtualWrite (V3, med4/2) ;
      display . clearDisplay () ;
      display . setTextSize (2) ;
      display . setTextColor (SSD1306_WHITE) ;
      display . setCursor (20, 2) ;
      display . println (F ("RESETING") ) ;
      display . display () ;
      delay (3000) ;
   }
}
//end………………………………………………………………………………………………….




  BLYNK_WRITE (V5) {
    int value = param. asInt () ;
    int pos = 0 ;
    Serial. println ("Now, Container 1 is working") ;
    Serial. println (value) ;
    if (value >= 1) {
      med1 = med1 - 2;
      Serial. print ("Number og medi = ") ;
      Serial. println (med1/2) ;
      Blynk . virtualWrite (V0, med1/2) ;
      for (pos = 0; pos <= 61; pos += 1) {
        servos [0] . write (pos) ;
        delay (15) ;
      }
      for (pos = 61; pos >= 0; pos -= 1) {
        servos [0].write (pos) ;
      }        
      if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
         Blynk.logEvent("out_off medicine", "Please fill up all containers ! ! ! !");
         display.clearDisplay();
         display.setTextSize(2);
         display.setTextColor(SSD1306_WHITE);
         display.setCursor(1,4);
         display.println (F("OUT OFF"));
         display.setCursor (1,20);
         display.println (F ("Medicine"));




//end………………………………………………………………………………………………..




      }
      else if (med1 <= 4) {
      Blynk.logEvent("container_1_low","Please fill medicine in the container 1" ) ;
      }
    }
}
BLYNK_WRITE (V6) {
   int value = param. asInt () ;
   int pos = 0 ;
   Serial. println ("Now, Container 2 is working") ;
   if (value >= 1) {
     med2 = med2 - 2;
     Serial. print ("Number og med2 = ") ;
     Serial . println (med2/2) ;
//end………………………………………………………………………………………


     delay (15) ;
   }
   for (pos = 61; pos >= 0; pos -= 1) {
     servos [0].write(pos) ;
   }
   if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
      Blynk.logEvent ("out_off medicine", "Please fill up all containers ! ! ! !");
      display.clearDisplay ();
      display.setTextSize (2) ;
      display.setTextColor(SSD1306_WHITE);
      display.setCursor (1,4);
      display.println (F("OUT OFF"));
      display.setCursor (1,20) ;
      display.println (F ("Medicine"));
  }
  else if (med1 <= 4)
  {
    Blynk.logEvent("container_1_low","Please fill medicine in the container 1" );
  }

}


BLYNK_WRITE (V7) {
  int value = param.asInt();
  int pos = 0 ;
  Serial.println("Now, Container 2 is working") ;
  if (value >= 1)
  {
    med2 = med2 - 2;
    Serial.print ("Number og med2 = ") ;
    Serial.println (med2/2) ;
    Blynk.virtualWrite(V1,med2/2);
  } 

//end………………………………………………………………………………………………… 

}
   void setup(){
   Serial.begin(115200);
   Blynk.begin(auth,ssid,pass) ;
   pinMode(IR1, INPUT);
   pinMode(IR2, INPUT);
   pinMode(IR3, INPUT);
   pinMode(IR4, INPUT);
   attachInterrupt(digitalPinToInterrupt(IR1) , docounter1, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR2) , docounter2, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR3), docounter3, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR4) , docounter4, RISING) ;
   timer.setInterval(1000L, myTimerEvent);
   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
      Serial.println(F("SSD1306 allocation failed") ) ;
      for (;;) ; // Don't proceed, loop forever
   }
   display . display () ;
   delay (2000) ;
   // Clear the buffer
   display.clearDisplay();
   display.setTextSize(2); // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE);          // Draw white text
   display.setCursor (1,4);               // Start at top-left corner
   display.println (F("STARTING.."));
   display.setTextSize(1.5);
   display.setCursor(2,25);          // Start at top-left corner
   //end…………………………………………………………………………………
   
   display.println(F("PLEASE SETUP"));
   display.setCursor(2,40);
   display.println(F("ON BLYNK"));
   display.drawLine(0, 0, 0, 60, SSD1306_WHITE);
   display.drawLine(0, 60, 127, 60, SSD1306_WHITE);
   display.drawLine(127, 60, 127, 0, SSD1306_WHITE);
   display.drawLine(127, 0, 0, 0, SSD1306_WHITE);
   display.display();
   delay(5000);
   for(int i = 0; i < servoCount; ++i) {
     servos [i] .attach (servosPins[i]);
   }
    }  
    void loop() {
   Blynk.run () ;
   timer.run () ;
   countmed1 () ;
   countmed2 () ;
   countmed3 () ;
   countmed4 () ;
   oledAleart () ;
} 

//end




@Madhukesh help me

As I’ve just said to you, I’m not going to be fixing anything - you are.

But, I’m not going to be looking at possible causes of your issue until you provide all of the information requested in the link I provided (which you don’t appear to have read) and posted the actual sketch that you’re using.

Pete.

In addition, posting your serial monitor might help too.


Serial monitor output

I suspect interrupt issue, you have to use “void IRAM_ATTR”

void IRAM_ATTR docounter1 () {
  counter1 = true;
}

Serial monitor

Its code.can you correct this problem.
Please…

#define BLYNK_TEMPLATE_ID           "TMPL32u7FuTK"
#define BLYNK_TEMPLATE_NAME         "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "VQVdGFEkxzUB1GWN5tym_9pHiiUMgFdl"




#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <analogWrite.h>
#include <WiFi.h>
#include <SPI.h>
#include <WiFiclient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>




char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "poco m3 pro 5g";
char pass [] = "12345789";





#define IR1 5 // IR sensor 1
#define IR2 18 // IR sensor 2
#define IR3 19 // IR sensor 3
#define IR4 23 // IR sensor 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C




//end……………………………………………………………………………




Adafruit_SSD1306 display('SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET');
int pos;
int med1 = 0;
int med2 = 0;
int med3 = 0;
int med4 = 0;
boolean counter1 = false;
boolean counter2 = false;
boolean counter3 = false;
boolean counter4 = false;
int x = 0;
int y = 16;



// Servo 


const int servoCount = 4;
static const int servosPins[servoCount] = {12, 14, 27, 26};
Servo servos[servoCount] ;
//—----------------------------------------------------------------------------------


void countmed1 (){
if (counter1 == true) {
   counter1 = false;
   med1 = med1 + 1;
   Serial.print("Number og medl = ") ;
   Serial.println (med1/2) ;
   Blynk.virtualWrite(V0,med1/2) ;
   if (med1 >= 30) {
     Blynk.logEvent("containerl_full") ;
  }  
}




}
void countmed2 () {
if (counter2 == true) {
    counter2 = false;
    med2 = med2 + 1;
    Serial. print ("Number og med2 = ") ;
    Serial. println (med2/2) ;
    Blynk . virtualWrite (V1, med2/2) ;
    if (med2 >= 30) {
      Blynk.logEvent ("container2_full") ;
    }
  } 


}
//end……………………………………………………………………………




void countmed3(){
if (counter3 == true) {
   counter3 = false;
   med3 = med3 + 1;
   Serial. print ("Number og med3 = ");
   Serial. println (med3/2) ;
   Blynk . virtualWrite (V2, med3/2);
   if (med3 >= 30) {
     Blynk.logEvent ("container3_full");
    }
  }

}      
void countmed4() {
  if (counter4 == true) {
    counter4 = false;
    med4 = med4 + 1;
    Serial. print ("Number og med4 = ") ;
    Serial. println (med4/2) ;
    Blynk . virtualWrite (V3, med4/2) ;
    if (med4 >= 30) {
      Blynk.logEvent ("container4_full") ;

//end………………………………………………………..
    }
  }

}

void docounter1 () {
  counter1 = true;
}
void docounter2 () {
  counter2 = true;
}
void docounter3 () {
  counter3 = true;
}
void docounter4 () {
  counter4 = true;
}
void myTimerEvent()
{
    // You can send any value at any time.
    // Please don't send more that 10 values per second.
    Blynk.virtualWrite (V4, millis() / 1000);
} 


void oledAleart () {

//end………………………………………………………………………………
  if (med1 <= 4 && med2 <= 4 && med3 <= 4 && med4<=4 ) {
     display. clearDisplay () ;
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display . println (F ("LOW DRUGS") ) ;
     display. setCursor (1, 30) ;
     display . setTextSize (1) ;
     display . println (F ("Please fill") ) ;
     display . setCursor (1, 37) ;
     display. println (F("all container")) ;
     display. display () ;
  }
  else if (med1 >= 30 && med2 >= 30 && med3 >= 30 && med4 >= 30) {
     display . clearDisplay ();
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display. println (F ("FULL DRUGS") ) ;
     display . setCursor (1, 30) ;
     display . setTextSize (1) ;




//end…………………………………………………………………………………………………….
     display . println (F ("Have a") ) ;
     display . setCursor (1, 37) ;
     display . println (F ("nice day") ) ;
     display . display () ;
   }
}
//end……………………………………………………………………………………………..
  BlynkTimer timer;

  BLYNK_WRITE (V4) {
    int value = param. asInt ( ) ;
    if (value = true) {
      med1 = 0;  
      med2 = 0;
      med3 = 0;
      med4 = 0;
      Blynk . virtualWrite (V0, med1/2) ;
      Blynk . virtualWrite (V1, med2/2) ;
      Blynk . virtualWrite (V2, med3/2) ;
      Blynk . virtualWrite (V3, med4/2) ;
      display . clearDisplay () ;
      display . setTextSize (2) ;
      display . setTextColor (SSD1306_WHITE) ;
      display . setCursor (20, 2) ;
      display . println (F ("RESETING") ) ;
      display . display () ;
      delay (3000) ;
   }
}
//end………………………………………………………………………………………………….




  BLYNK_WRITE (V5) {
    int value = param. asInt () ;
    int pos = 0 ;
    Serial. println ("Now, Container 1 is working") ;
    Serial. println (value) ;
    if (value >= 1) {
      med1 = med1 - 2;
      Serial. print ("Number og medi = ") ;
      Serial. println (med1/2) ;
      Blynk . virtualWrite (V0, med1/2) ;
      for (pos = 0; pos <= 61; pos += 1) {
        servos [0] . write (pos) ;
        delay (15) ;
      }
      for (pos = 61; pos >= 0; pos -= 1) {
        servos [0].write (pos) ;
      }        
      if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
         Blynk.logEvent("out_off medicine", "Please fill up all containers ! ! ! !");
         display.clearDisplay();
         display.setTextSize(2);
         display.setTextColor(SSD1306_WHITE);
         display.setCursor(1,4);
         display.println (F("OUT OFF"));
         display.setCursor (1,20);
         display.println (F ("Medicine"));




//end………………………………………………………………………………………………..




      }
      else if (med1 <= 4) {
      Blynk.logEvent("container_1_low","Please fill medicine in the container 1" ) ;
      }
    }
}
BLYNK_WRITE (V6) {
   int value = param. asInt () ;
   int pos = 0 ;
   Serial. println ("Now, Container 2 is working") ;
   if (value >= 1) {
     med2 = med2 - 2;
     Serial. print ("Number og med2 = ") ;
     Serial . println (med2/2) ;
//end………………………………………………………………………………………


     delay (15) ;
   }
   for (pos = 61; pos >= 0; pos -= 1) {
     servos [0].write(pos) ;
   }
   if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
      Blynk.logEvent ("out_off medicine", "Please fill up all containers ! ! ! !");
      display.clearDisplay ();
      display.setTextSize (2) ;
      display.setTextColor(SSD1306_WHITE);
      display.setCursor (1,4);
      display.println (F("OUT OFF"));
      display.setCursor (1,20) ;
      display.println (F ("Medicine"));
  }
  else if (med1 <= 4)
  {
    Blynk.logEvent("container_1_low","Please fill medicine in the container 1" );
  }

}


BLYNK_WRITE (V7) {
  int value = param.asInt();
  int pos = 0 ;
  Serial.println("Now, Container 2 is working") ;
  if (value >= 1)
  {
    med2 = med2 - 2;
    Serial.print ("Number og med2 = ") ;
    Serial.println (med2/2) ;
    Blynk.virtualWrite(V1,med2/2);
  } 

//end………………………………………………………………………………………………… 

}
   void setup(){
   Serial.begin(115200);
   Blynk.begin(auth,ssid,pass) ;
   pinMode(IR1, INPUT);
   pinMode(IR2, INPUT);
   pinMode(IR3, INPUT);
   pinMode(IR4, INPUT);
   attachInterrupt(digitalPinToInterrupt(IR1) , docounter1, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR2) , docounter2, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR3), docounter3, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR4) , docounter4, RISING) ;
   timer.setInterval(1000L, myTimerEvent);
   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
      Serial.println(F("SSD1306 allocation failed") ) ;
      for (;;) ; // Don't proceed, loop forever
   }
   display . display () ;
   delay (2000) ;
   // Clear the buffer
   display.clearDisplay();
   display.setTextSize(2); // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE);          // Draw white text
   display.setCursor (1,4);               // Start at top-left corner
   display.println (F("STARTING.."));
   display.setTextSize(1.5);
   display.setCursor(2,25);          // Start at top-left corner
   //end…………………………………………………………………………………
   
   display.println(F("PLEASE SETUP"));
   display.setCursor(2,40);
   display.println(F("ON BLYNK"));
   display.drawLine(0, 0, 0, 60, SSD1306_WHITE);
   display.drawLine(0, 60, 127, 60, SSD1306_WHITE);
   display.drawLine(127, 60, 127, 0, SSD1306_WHITE);
   display.drawLine(127, 0, 0, 0, SSD1306_WHITE);
   display.display();
   delay(5000);
   for(int i = 0; i < servoCount; ++i) {
     servos [i] .attach (servosPins[i]);
   }
    }  
    void loop() {
   Blynk.run () ;
   timer.run () ;
   countmed1 () ;
   countmed2 () ;
   countmed3 () ;
   countmed4 () ;
   oledAleart () ;
} 

//end

We facing the issue after ‘Blink iot’
Update…
before update, the working of app is perfect.

The issue isn’t with the app, it’s with your sketch.
But, you still haven’t posted a sketch that’s capable of being compiled.

Pete.

1 Like

I dont understand sketch.
Is that. (. ino) file

Sorry to say,

You are not taking any inputs from the forum members. You are just seeking straight help.

Without your effort in taking the inputs from us and reflecting the same on your code, your project will not move even a bit.

No one will write the code from scratch. You will have to analyse yourself from our inputs and start working on your code.

I told you to go through this link

Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Did you read? What did you understand? Did you implement? If not, why so?

I don’t understand.
Do you mean it works with an old Blynk library or it works without Blynk?

Sketch = your C++ code, which will be saved as a .ino file.

The three sketches that you’ve posted so far do not compile (at least when using the Arduino IDE, which is what the majority of forum members seem to use).

Also, you really should follow the link to the topic called “Recommendations for creating a new topic…” that I linked to in post #4 and read it.

If you did that, you’d know the correct way to post your serial output (which isn’t as a screenshot) and also know the information that is needed before we can begin to help you with your problems.

As I’ve said before, I‘m not going to look at your code issues until you post something that compiles, and until you provide the information requested in the topic I linked to.

This is the last time that I’ll ask for this information, and after that I’ll take a step back from this topic and only intervene when moderator input is required.

Pete.

1 Like

• esp32 dev module with WiFi.
• Smartphone OS (Android) +version (12 SP1A.210812.016)
• Blynk server
• Blynk Library version = latest


• Add your sketch code. Loading Google Docs

why this code is not connected to blink server properly.
when booting the esp32 it shows online, after a little seconds it disconnected and shows offline and this is continues repeating.

Its code, with( no compailation error).
If anyone know please correct it.


#define BLYNK_TEMPLATE_ID           "TMPL32u7FuTK"
#define BLYNK_TEMPLATE_NAME         "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "VQVdGFEkxzUB1GWN5tym_9pHiiUMgFdl"




#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <analogWrite.h>
#include <WiFi.h>
#include <SPI.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>




char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "poco m3 pro 5g";
char pass [] = "12345789";





#define IR1 5 // IR sensor 1
#define IR2 18 // IR sensor 2
#define IR3 19 // IR sensor 3
#define IR4 23 // IR sensor 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C




//end……………………………………………………………………………




Adafruit_SSD1306 display('SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET');
int pos;
int med1 = 0;
int med2 = 0;
int med3 = 0;
int med4 = 0;
boolean counter1 = false;
boolean counter2 = false;
boolean counter3 = false;
boolean counter4 = false;
int x = 0;
int y = 16;



// Servo 


const int servoCount = 4;
static const int servosPins[servoCount] = {12, 14, 27, 26};
Servo servos[servoCount] ;
//—----------------------------------------------------------------------------------


void countmed1 (){
if (counter1 == true) {
   counter1 = false;
   med1 = med1 + 1;
   Serial.print("Number og medl = ") ;
   Serial.println (med1/2) ;
   Blynk.virtualWrite(V0,med1/2) ;
   if (med1 >= 30) {
     Blynk.logEvent("containerl_full") ;
  }  
}




}
void countmed2 () {
if (counter2 == true) {
    counter2 = false;
    med2 = med2 + 1;
    Serial. print ("Number og med2 = ") ;
    Serial. println (med2/2) ;
    Blynk . virtualWrite (V1, med2/2) ;
    if (med2 >= 30) {
      Blynk.logEvent ("container2_full") ;
    }
  } 


}
//end……………………………………………………………………………




void countmed3(){
if (counter3 == true) {
   counter3 = false;
   med3 = med3 + 1;
   Serial. print ("Number og med3 = ");
   Serial. println (med3/2) ;
   Blynk . virtualWrite (V2, med3/2);
   if (med3 >= 30) {
     Blynk.logEvent ("container3_full");
    }
  }

}      
void countmed4() {
  if (counter4 == true) {
    counter4 = false;
    med4 = med4 + 1;
    Serial. print ("Number og med4 = ") ;
    Serial. println (med4/2) ;
    Blynk . virtualWrite (V3, med4/2) ;
    if (med4 >= 30) {
      Blynk.logEvent ("container4_full") ;

//end………………………………………………………..
    }
  }

}

void docounter1 () {
  counter1 = true;
}
void docounter2 () {
  counter2 = true;
}
void docounter3 () {
  counter3 = true;
}
void docounter4 () {
  counter4 = true;
}
void myTimerEvent()
{
    // You can send any value at any time.
    // Please don't send more that 10 values per second.
    Blynk.virtualWrite (V4, millis() / 1000);
} 


void oledAleart () {

//end………………………………………………………………………………
  if (med1 <= 4 && med2 <= 4 && med3 <= 4 && med4<=4 ) {
     display. clearDisplay () ;
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display . println (F ("LOW DRUGS") ) ;
     display. setCursor (1, 30) ;
     display . setTextSize (1) ;
     display . println (F ("Please fill") ) ;
     display . setCursor (1, 37) ;
     display. println (F("all container")) ;
     display. display () ;
  }
  else if (med1 >= 30 && med2 >= 30 && med3 >= 30 && med4 >= 30) {
     display . clearDisplay ();
     display . setTextSize (2) ;
     display . setTextColor (SSD1306_WHITE) ;
     display . setCursor (1, 4) ;
     display. println (F ("FULL DRUGS") ) ;
     display . setCursor (1, 30) ;
     display . setTextSize (1) ;




//end…………………………………………………………………………………………………….
     display . println (F ("Have a") ) ;
     display . setCursor (1, 37) ;
     display . println (F ("nice day") ) ;
     display . display () ;
   }
}
//end……………………………………………………………………………………………..
  BlynkTimer timer;

  BLYNK_WRITE (V4) {
    int value = param. asInt ( ) ;
    if (value = true) {
      med1 = 0;  
      med2 = 0;
      med3 = 0;
      med4 = 0;
      Blynk . virtualWrite (V0, med1/2) ;
      Blynk . virtualWrite (V1, med2/2) ;
      Blynk . virtualWrite (V2, med3/2) ;
      Blynk . virtualWrite (V3, med4/2) ;
      display . clearDisplay () ;
      display . setTextSize (2) ;
      display . setTextColor (SSD1306_WHITE) ;
      display . setCursor (20, 2) ;
      display . println (F ("RESETING") ) ;
      display . display () ;
      delay (3000) ;
   }
}
//end………………………………………………………………………………………………….




  BLYNK_WRITE (V5) {
    int value = param. asInt () ;
    int pos = 0 ;
    Serial. println ("Now, Container 1 is working") ;
    Serial. println (value) ;
    if (value >= 1) {
      med1 = med1 - 2;
      Serial. print ("Number og medi = ") ;
      Serial. println (med1/2) ;
      Blynk . virtualWrite (V0, med1/2) ;
      for (pos = 0; pos <= 61; pos += 1) {
        servos [0] . write (pos) ;
        delay (15) ;
      }
      for (pos = 61; pos >= 0; pos -= 1) {
        servos [0].write (pos) ;
      }        
      if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
         Blynk.logEvent("out_off medicine", "Please fill up all containers ! ! ! !");
         display.clearDisplay();
         display.setTextSize(2);
         display.setTextColor(SSD1306_WHITE);
         display.setCursor(1,4);
         display.println (F("OUT OFF"));
         display.setCursor (1,20);
         display.println (F ("Medicine"));




//end………………………………………………………………………………………………..




      }
      else if (med1 <= 4) {
      Blynk.logEvent("container_1_low","Please fill medicine in the container 1" ) ;
      }
    }
}
BLYNK_WRITE (V6) {
   int value = param. asInt () ;
   int pos = 0 ;
   Serial. println ("Now, Container 2 is working") ;
   if (value >= 1) {
     med2 = med2 - 2;
     Serial. print ("Number og med2 = ") ;
     Serial . println (med2/2) ;
//end………………………………………………………………………………………


     delay (15) ;
   }
   for (pos = 61; pos >= 0; pos -= 1) {
     servos [0].write(pos) ;
   }
   if (med1 <= 0 && med2 <= 0 && med3 <= 0 && med4<=0) {
      Blynk.logEvent ("out_off medicine", "Please fill up all containers ! ! ! !");
      display.clearDisplay ();
      display.setTextSize (2) ;
      display.setTextColor(SSD1306_WHITE);
      display.setCursor (1,4);
      display.println (F("OUT OFF"));
      display.setCursor (1,20) ;
      display.println (F ("Medicine"));
  }
  else if (med1 <= 4)
  {
    Blynk.logEvent("container_1_low","Please fill medicine in the container 1" );
  }

}


BLYNK_WRITE (V7) {
  int value = param.asInt();
  int pos = 0 ;
  Serial.println("Now, Container 2 is working") ;
  if (value >= 1)
  {
    med2 = med2 - 2;
    Serial.print ("Number og med2 = ") ;
    Serial.println (med2/2) ;
    Blynk.virtualWrite(V1,med2/2);
  } 

//end………………………………………………………………………………………………… 

}
   void setup(){
   Serial.begin(115200);
   Blynk.begin(auth,ssid,pass) ;
   pinMode(IR1, INPUT);
   pinMode(IR2, INPUT);
   pinMode(IR3, INPUT);
   pinMode(IR4, INPUT);
   attachInterrupt(digitalPinToInterrupt(IR1) , docounter1, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR2) , docounter2, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR3), docounter3, RISING) ;
   attachInterrupt(digitalPinToInterrupt(IR4) , docounter4, RISING) ;
   timer.setInterval(1000L, myTimerEvent);
   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
      Serial.println(F("SSD1306 allocation failed") ) ;
      for (;;) ; // Don't proceed, loop forever
   }
   display . display () ;
   delay (2000) ;
   // Clear the buffer
   display.clearDisplay();
   display.setTextSize(2); // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE);          // Draw white text
   display.setCursor (1,4);               // Start at top-left corner
   display.println (F("STARTING.."));
   display.setTextSize(1.5);
   display.setCursor(2,25);          // Start at top-left corner
   //end…………………………………………………………………………………
   
   display.println(F("PLEASE SETUP"));
   display.setCursor(2,40);
   display.println(F("ON BLYNK"));
   display.drawLine(0, 0, 0, 60, SSD1306_WHITE);
   display.drawLine(0, 60, 127, 60, SSD1306_WHITE);
   display.drawLine(127, 60, 127, 0, SSD1306_WHITE);
   display.drawLine(127, 0, 0, 0, SSD1306_WHITE);
   display.display();
   delay(5000);
   for(int i = 0; i < servoCount; ++i) {
     servos [i] .attach (servosPins[i]);
   }
    }  
    void loop() {
   Blynk.run () ;
   timer.run () ;
   countmed1 () ;
   countmed2 () ;
   countmed3 () ;
   countmed4 () ;
   oledAleart () ;
} 

//end

Serial monitor output

Blink app, hardware status