GPRS Shield + Arduino UNO + DHT11

I am working with a GPRS Shield, an Arduino UNO and a DHT11 for the temperature. When I am testing it in mi office it works pretty well, but when I connect it in the same socket as the refrigerator it works for like 30min - 1hr and then it disconnect from the Blynk Server.

I have tried to change the way I connect it to the socket with different voltage sources and buck converters, but I keep having the same problem.

Now I want to try to reset the Arduino when it disconnect but I dont know if there is any function or something that I can use to know when it disconnects.

Someone can help me please.

Thanks.


/**************************************************************
 * 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.
 *
 **************************************************************
 *
 * This example shows how to use SIM800 or SIM900 modem series
 * to connect your project to Blynk.
 *
 * Attention! Please check out TinyGSM guide:
 *   http://tiny.cc/tiny-gsm-readme
 *
 * WARNING: SIM module support is for BETA testing.
 *
 * Change GPRS apm, user, pass, and Blynk auth token to run :)
 * Feel free to apply it to any other example. It's simple!
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
#define TINY_GSM_MODEM_SIM900
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include "DHT.h"
#define DHTTYPE DHT11 

const int DHTPin = 3;
DHT dht(DHTPin, DHTTYPE);

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
float h, t;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "9e942b9c1c114a6b8689e880f5f9d0bb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "broadband.tigo.gt"; //APN of your service provider
char user[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(7, 8); // RX, TX

TinyGsm modem(SerialAT);

void powerUpOrDown()
{
    pinMode(9, OUTPUT);
    digitalWrite(9,LOW);
    delay(1000);
    digitalWrite(9,HIGH);
    delay(2000);
    digitalWrite(9,LOW);
    delay(3000);
}

void setup()
{
  // Set console baud rate
  Serial.begin(19200);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(19200);
  delay(3000);

  Serial.println("Enciende GPRS Shield");
  powerUpOrDown();
  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  modem.init();

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  Blynk.begin(auth, modem, apn, user, pass);
}

void loop()
{
  Blynk.run();
  h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  // float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) ) {
    Serial.println("Failed to read from DHT sensor!");
    strcpy(celsiusTemp,"Failed");
    strcpy(fahrenheitTemp, "Failed");
    strcpy(humidityTemp, "Failed");   
    tempErrBlynk();      
  } else {
    // Computes temperature values in Celsius + Fahrenheit and Humidity
    float hic = dht.computeHeatIndex(t, h, false);       
    dtostrf(hic, 6, 2, celsiusTemp);             
    // float hif = dht.computeHeatIndex(f, h);
    // dtostrf(hif, 6, 2, fahrenheitTemp);         
    dtostrf(h, 6, 2, humidityTemp);
    // You can delete the following Serial.print's, it's just for debugging purposes
    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C ");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.println(" *C ");
    sendBlynk();
    }
 delay(30000);
}        

void sendBlynk() {  
    Blynk.virtualWrite(V5,h);
    Blynk.virtualWrite(V6,t);
    if(t>30){ //set temperatur level for notificat
      //Blynk.email("josesagas94@gmail.com", "ESP8266 Alert", "Temperature Increased over limit");
      Blynk.notify("Temperatura mayor a 30°C");
    }
}

void tempErrBlynk() {
  Blynk.notify("Error lectura de sensor");  
}


Probably the refrigerator compressor is causing some voltage spikes… try a battery option?

Most of Blynk’s Firmware Connection Management is meant for standalone ESP based MCUs…

When an ESP is used as a shield, it basically becomes a simple adapter and is no longer “accessible” the way needed for connection management commands to work.

There have been a few Arduino “hacks” that allow the WDT (watch dog timer) to reset the arduino if is senses loss of connection with the server, etc… search this forum for keywords like WDT, Arduino, Shield, etc.

1 Like

Thanks I will search for those keywords

I have tried the battery option and it doesnt work either.

Then, assuming you are not placing the whole Arduino INTO the fridge :wink: … look into the WDT and see if that helps.

1 Like

Ok I will look into de WDT.

And no I am not placing the whole Arduino into the fridge jaja :slight_smile:

Are you using the DHT11 to measure fridge temperature?

Until everything is running correctly forget the fridge and hook it all up to your PC so you can read the debug messages.

1 Like

Yes, I am using the DHT11 to measure fridge temperature.

I am doing that right now, I am reading the Serial output form the arduino. And I have the problem that it get stock and stop sending data. I dont know why is that.

There is a photo where I was reading the Serial but it stopped sending data and then it disconnects from Blynk.

The problem is your loop(), keep it to a maximum of 2 lines of code. See PUSH_DATA example of how to call functions at timed intervals.

2 Likes

Ok, thanks. I will check it.
I will notify here if it works or not after fixing my loop().

1 Like

It seems that it is working fine. Thanks for the help.

Here is my new code.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  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
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  WARNING :
  For this example you'll need Adafruit DHT sensor libraries:
    https://github.com/adafruit/Adafruit_Sensor
    https://github.com/adafruit/DHT-sensor-library

  App project setup:
    Value Display widget attached to V5
    Value Display widget attached to V6
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#define TINY_GSM_MODEM_SIM900
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "9e942b9c1c114a6b8689e880f5f9d0bb";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "broadband.tigo.gt"; //APN of your service provider
char user[] = "";
char pass[] = "";

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(7, 8); // RX, TX
TinyGsm modem(SerialAT);

#define DHTPIN 3          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  Serial.print("Humidity: ");
  Serial.println(h);
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  if(t>30){ //set temperatur level for notificat
    //Blynk.email("josesagas94@gmail.com", "ESP8266 Alert", "Temperature Increased over limit");
    Blynk.notify("Temperatura mayor a 30°C");
  }
}

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 powerUpOrDown()
{
    pinMode(9, OUTPUT);
    digitalWrite(9,LOW);
    delay(1000);
    digitalWrite(9,HIGH);
    delay(2000);
    digitalWrite(9,LOW);
    delay(3000);
}

void setup()
{
  // Debug console
  Serial.begin(19200);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(19200);
  delay(3000);

  Serial.println("Enciende GPRS Shield");
  powerUpOrDown();
  delay(10000);
  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  modem.init();
 
  Blynk.begin(auth, modem, apn, user, pass);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
  timer.setInterval(1000L, myTimerEvent);
}

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


1 Like