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

*SOLVED* MKR1000 - after 10 seconds it disconnects

Hi,
I’m doing this project from a homemade egg-hatcher. But I’m having a problem, it works perfectly, but after 10 seconds it disconnects from the internet there I get without receiving the data, although it keeps working…
Could someone tell me why she’s disconnecting from the network? After ±10s.
I’m using:
MKR 1000 arduino
IPhone 11

My Code:

/Incubadora de ovos
 **************************************************************/
#include <Wire.h>
#include <EduIntro.h>
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include <SimpleTimer.h>
#include <DHT.h>

#define pRELE        7        //(relé con calefactor conectado al pin 7)
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define DHTPIN 2    // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22 
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " ";

int vcc= 11; //crear pines de 5v // acrescentei

SimpleTimer timer;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = " ";
char pass[] = " ";


void TimerEvent()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  int C; 
  C = dht.readTemperature(); //acrescentei
  Blynk.virtualWrite(V6, h);
  Blynk.virtualWrite(V5, t);
  Serial.println(C); //acrescentei
}

ServoMotor servo(D6);    // creating the object 'servo' on pin D10

void setup()
{

  pinMode(pRELE,OUTPUT);
  pinMode(vcc,OUTPUT); 
  Serial.begin(115200);
  //Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  Blynk.begin(auth, ssid, pass, "46.101.143.225", 80);
  timer.setInterval(2000L, TimerEvent);
  dht.begin();
}

void loop()
{

  
  Blynk.run();
  timer.run();

  digitalWrite(vcc,HIGH); 
  //DHT.read t(dht_apin); // Read apin on DHT11 or DHT22

  if(dht.readTemperature()<37)
{
  digitalWrite(pRELE,LOW);
  delay(2000);
  }
  else
  {
    digitalWrite(pRELE,HIGH);  // digitalWrite (pVENTILADOR,HIGH);
   
    }
  
{
  servo.write(135);
  delay (7200000);   // wait for two horas
  servo.write(50);
  delay (7200000);   // wait for a second
}
  
}```

Read this and all will become clear:

Pete.

Pete
Thank you very much, it was perfect now… Just one little thing missing, the temperature is taking about 13 seconds to update and that’s a lot, because it will elevate the temperature of the hatch a lot. You could guide me as I shorten the time for DHT to read the temperature…
Thank you.
here goes the code as it did after his guidance.

 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 **************************************************************/
#include <Wire.h>
#include <EduIntro.h>
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include <SimpleTimer.h>
#include <DHT.h>

#define pRELE        7        //(relé con calefactor conectado al pin 7)
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define DHTPIN 2    // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22 
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

int vcc= 11; //crear pines de 5v // acrescentei

SimpleTimer timer;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NosAky";
char pass[] = "";


void TimerEvent()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  int C; 
  C = dht.readTemperature(); //acrescentei
  Blynk.virtualWrite(V6, h);
  Blynk.virtualWrite(V5, t);
  Serial.println(C); //acrescentei
}

ServoMotor servo(D6);    // creating the object 'servo' on pin D10

void setup()
{

  pinMode(pRELE,OUTPUT);
  pinMode(vcc,OUTPUT); 
  Serial.begin(115200);
  //Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  Blynk.begin(auth, ssid, pass, "46.101.143.225", 80);
  timer.setInterval(2000L, TimerEvent);
  dht.begin();
}

void Iftemperature()
{
  digitalWrite(vcc,HIGH); 
  //DHT.read t(dht_apin); // Read apin on DHT11 or DHT22

  if(dht.readTemperature()<37)
{
  digitalWrite(pRELE,LOW);
  delay(1000);
  }
  else
  {
    digitalWrite(pRELE,HIGH);  // digitalWrite (pVENTILADOR,HIGH);
   
    }
}
void loop0()

{
  servo.write(135);
  delay (6000);   // wait for two horas
  servo.write(50);
  delay (6000);   // wait for a second
}


void loop()
{
  
  Blynk.run();
  timer.run();
  loop0();
  Iftemperature();
  
}  ```

You can’t just move the offending items out of your void loop and into their own functions, then call them on every execution of the void loop!

You should take a temperature reading, then (in the same function) check whether the temperature is within your desired range and take the appropriate actions.

Pete.

1 Like

Your information helped me solve the problem.
Thanks again.

1 Like