Blynktimer not responding

i have problem with my code, it’s just hang in void (setup), void (loop) not procces, my lcd is blank and my app not responding, here is my code and it using minimum system atmeg328, somebody help me please… !!!

    #define TINY_GSM_MODEM_SIM800

    #include <TinyGsmClient.h>
    #include <BlynkSimpleSIM800.h>
    #include <LCD5110_Graph.h>
    #include <SoftwareSerial.h>

    #define echoPin 8 // Echo Pin
    #define trigPin 9 // Trigger Pin
    char auth[] = "b370cbceae9c4800b00fe36185fdbebf";
    char apn[]  = "3";
    char user[] = "3gprs";
    char pass[] = "3gprs";
    extern uint8_t SmallFont[];
    extern uint8_t TinyFont[];
    extern uint8_t MediumNumbers[];
    int buttonPin = 0;
    int buttonValue = 0;
    byte sensorInt = 0;
    byte flowsensor = 2;
    volatile byte pulseCount;
    float debit, flow, laju, pulse, luas, vol, duration, distance, tinggi;
    unsigned long oldTime;
    int lebar = 0;
    int ok = 0;
    WidgetLED led(V11);

    LCD5110 lcd(3,4,5,6,7);
    SoftwareSerial SerialAT(12, 11); // RX, TX
    TinyGsm modem(SerialAT);
    BlynkTimer timer;

    void(* reset) (void) = 0; 

    void setup(void)
    {
      Serial.begin(9600);
      lcd.InitLCD();
      pinMode(flowsensor, INPUT);
      digitalWrite(flowsensor, HIGH);
      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);
      pulseCount = 0;
      oldTime = 0;
      laju = 0.0;
      lebar = 0;
      attachInterrupt(sensorInt, pulseCounter, FALLING);
      delay(10);
      SerialAT.begin(19200);
      delay(3000);
      modem.restart();
      Blynk.begin(auth, modem, apn, user, pass);
      while (Blynk.connect() == false) 
        {
        led.on(); // Wait until connected
        }
      timer.setInterval(1000L, kirim); 
    }

    BLYNK_CONNECTED(){
      Blynk.virtualWrite(V1, lebar);
      Blynk.virtualWrite(V2, tinggi);
      Blynk.virtualWrite(V3, laju);
      Blynk.virtualWrite(V4, vol);
      Blynk.virtualWrite(V5, flow);
      Blynk.virtualWrite(V6, debit);
    }
    BLYNK_READ(V1)
    {
      Blynk.virtualWrite(V1, lebar);
    }

    BLYNK_WRITE(V7)
        {
          int state = param.asInt();
          if (state == 1) {
            ok = 1;
          }
         }
    BLYNK_WRITE(V8)
        {
          int state = param.asInt();
          if (state == 1) {
             lebar+=5;
          }
         }
    BLYNK_WRITE(V9)
        {
          int state = param.asInt();
          if (state == 1) {
             if ( lebar>= 5 ){
             lebar-=5;
            }
         }
        }    
    BLYNK_WRITE(V10)
        {
          int state = param.asInt();
          if (state == 1) {
            reset();
          }
          else {
            reset();
          }
         }

    void loop(void)
    {
      Blynk.run();
      timer.run();
    }

    void sensor(){
      //delay(1000);
      led.off();
        digitalWrite(trigPin, LOW);                   
        delayMicroseconds(2);
        digitalWrite(trigPin, HIGH);          
        delayMicroseconds(10);               
        digitalWrite(trigPin, LOW);           
        duration = pulseIn(echoPin,HIGH);        
        distance = duration/56.2; //58.2-56.7(9358.56)
        tinggi = 200 - distance;
         if (tinggi <= 0 ) {
            tinggi = 0; 
          }    
          
          detachInterrupt(sensorInt); 
          flow = ((1000.0/(millis() - oldTime)) * pulseCount)/ 2.9;       
          debit = ((1000.0/(millis() - oldTime)) * pulseCount) / 60;
          oldTime = millis();
          
          pulse = pulseCount++;
          laju = (pulse * 7.5) / 60;
          luas = (tinggi * lebar) / 100 ;
          vol = luas * laju;     
      
      lcd.clrScr();
      lcd.setFont(TinyFont);
      lcd.printNumF(debit, 2, RIGHT, 0);
      lcd.printNumF(pulseCount, 2, CENTER, 0);
      lcd.printNumF(flow, 2, LEFT, 0);
      lcd.printNumF(tinggi, 2, RIGHT, 32); 
      lcd.printNumF(distance, 2, CENTER, 32);
      lcd.printNumI(lebar, LEFT, 32, 3, ' ');     
      lcd.setFont(SmallFont);
      lcd.print("FLOW", 5, 8);
      lcd.print("DEBIT", 50, 8);   
      lcd.print("m/s", 8, 24);
      lcd.print("m3/s", 57, 24);     
      lcd.printNumF(laju, 2, 2, 16);  
      lcd.printNumF(vol, 2, 53, 16);
      lcd.update();
      
    pulseCount = 0;
    attachInterrupt(sensorInt, pulseCounter, FALLING);
    }
    void kirim(){ 
    Blynk.virtualWrite(V1, lebar);
      Blynk.virtualWrite(V2, tinggi);
      Blynk.virtualWrite(V3, laju);
      Blynk.virtualWrite(V4, vol);
      Blynk.virtualWrite(V5, flow);
      Blynk.virtualWrite(V6, debit);
    }

    void pulseCounter()
    {
      //increment the pulse counter
      pulseCount++;
    }

Start pulling out chunks of code until it works. It’s very hard for people who dont understand your project to try and work out where your code is breaking.

Troubleshooting begins with breaking down the code until it works, then adding bits back in.

2 Likes