BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Where do I put my Code y Blynk?

Hi All

I´ve been having some problem integrating my code with Blynk, by integrating I mean having my Arduino run as normal and reporting the sensor metrics to Blynk. I have created a VOID to read all sensors from my Arduino with no problem. But I can’t have the Arduino running its own functions while doing so, because if I insert the functions in the Loop the connection crashes, and if I insert them using Blynk Timer it also crashes connection.

I have read some info here to keep the loop clean, but where do I put my code and working functions??
I don’t need all these functions to be sent to Blynk, I just need them to be running in my Arduino.

Ps: I have commented the functions that crash the connection,

example1 with loop (connection crash):

void loop()
{   
        Blynk.run();
        timer.run();
//      MuestraSerial();
//      sensorAmbiente();
//      sensorLuz();
//      macet(humedad1, bomba1, Macet[0], Flor);
//      macet(humedad2, bomba2, Macet[1], Germina);
}

example2 with Blynk timer (connection crash):

 void setuo(){
  //(ather stup has been deleted from the post, for beter undestanding)

 timer.setInterval(1000L, lecturaBlynk);
//  timer.setInterval(1000L, macet(humedad1, bomba1, Macet[0], Flor));
//  timer.setInterval(1000L, macet(humedad1, bomba1, Macet[0], Germina));"*
}

lecturaBlync = is my function where I have stored all readings and I’m able to visualize in the app
macet = is the function for local control of the variables connected to Arduino and all the logic behind it

Do I need to recode everything? or is there a workaround?

Systrem Specs:
Arduino UNO
ESP01 Shield
IDE 1.8.12

HI,

Check this out, lost of info, examples and explanation . . .

help.blynk.cc

Keep your void loop() clean

Troubleshooting of one of the most popular mistakes of newbie Blynk users.

Try something like this . .

void setup() {
  timer.setInterval(3000L, myFirstFunction());
  timer.setInterval(3000L, mySecondFunction());
  timer.setInterval(3000L, myThirdFunction());
…….
}

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

cul
billd

Thanks a lot @Bill_Donnelly

I was putting an Int not a function… thanks for the heads-up!!

Rookie mistake lol

Sorry @Bill_Donnelly… False Alarm… still crashing

if I uncomment the function I have a repetitive connection failure,

 void setup ()
     timer.setInterval(1000L, lecturaBlynk);
     //timer.setInterval(1000L, Riego);

The void I created to insert in BlynkTimer:

void Riego()
    {
      macet(humedad1, bomba1, Macet[0], Flor);
      macet(humedad2, bomba2, Macet[1], Germina);      
      }`

This is the variable I have:

int macet(int S, int B, char* N, int Tipo) 
    {
     int SensorValue = analogRead(S); //Toma Muestra1
     int LecturaPorcentaje = map(SensorValue, 0, 1021, 100, 0); //Conversor de lectura a Porcentaje
     unsigned long currentTime = millis(); 
     
     if(SensorValue >=1000)
        {       
        Serial.print("**Sensor ");
        Serial.print(N);
        Serial.println(" Desconectado**");       
        }       
     else if(SensorValue >= (Tipo) && lightMeter.readLightLevel() <= Luzriego)    //Variante para riego solo de Noche)
        {       
        if( currentTime - previousTime2 >= TpropRiego && digitalRead(B) == HIGH)
            {
            digitalWrite(B, LOW);
//            Serial.print("Regando");  
            previousTime2 = currentTime;        
             }           
        if( currentTime - previousTime2 >= Triego && digitalRead(B)==LOW)
            {
            digitalWrite(B, HIGH);
            previousTime2 = currentTime;        
             }         
        }
      }      

Could it be something to do with millis working in there???
Is there a way I can have my code running permanently without Blynk??

Cheers,

1 Like