Blynk+Arduino Uno+GSM+DHT21

Hi. This is my first time using Blynk and it always shows that my device is not yet online.
So these are the hardware I’m using:

  • Arduino Uno (connected to PC using USB cable)
  • GPRS Shield V3.0 SIM900 (connected to Arduino, powered by external 5VDC power source)

I’ve also updated both the Blynk app and Blynk library (1.0.0_beta.3). I’ve searched for similar problems regarding “device wasn’t online yet”, and tried similar examples but it just never worked for me.

#define BLYNK_PRINT Serial  /* Comment this out to disable prints and save space */
#define TINY_GSM_MODEM_SIM900 // Default heartbeat interval for GSM is 60

#include "DHT.h"            //for DHT21 sensor
#include <SPI.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

char auth[] = "";
char apn[]  = "";
char user[] = "";
char pass[] = "";

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX (Software Serial on Uno)

TinyGsm modem(SerialAT);

#define DHTPIN 13            // Digital pin connected to the DHT sensor
#define DHTTYPE DHT21       // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE); 
  
BlynkTimer timer;

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();  // Read temperature as Celsius (the default)
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.println(F("%"));
  Serial.print(F("Temperature: "));
  Serial.print(t);
  Serial.println(F("°C "));
   
  Blynk.virtualWrite(V5, t);
  Blynk.virtualWrite(V6, h);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(1000);

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

  Blynk.begin(auth, modem, apn, user, pass);
 
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

This is what shows in the serial port:

23:16:06.968 -> Initializing modem...
23:16:17.002 -> [11022] 
23:16:17.002 ->     ___  __          __
23:16:17.002 ->    / _ )/ /_ _____  / /__
23:16:17.049 ->   / _  / / // / _ \/  '_/
23:16:17.102 ->  /____/_/\_, /_//_/_/\_\
23:16:17.102 ->         /___/ v1.0.0-beta.3 on Arduino Uno
23:16:17.149 -> 
23:16:17.149 -> [11123] Modem init...
23:16:27.127 -> [21156] Cannot init

Could anyone please help to tell me which part did I do wrong? I really appreciate your help.

You need to be using 0.6.1 unless you are part of the Blynk beta testing programme, in which case your code isn’t structured correctly anyway.

Is your GPRS shield expecting a connection on pins 2 & 3 with a baud rate of 9600?

Pete.

I did with the 0.6.1 version before and I never succeeded. Regarding the GPRS shield, I’ve tried its own default baud rate of 115200 but it also didn’t work. Thank you for your reply, I will try and check again.

SoftwareSerial wont work at 115200, With an Uno you should stick to 9600, but you need to tell your shield to expect data at this speed, by configuring it with AT commands.

You certainly won’t succeed unless you have 0.6.1 installed and have the correct communication with your shield.

Pete.