GPRS Thermometer with Arduino MEGA 2560 and SIM800L

In this example, we will create a device that transmits temperature and humidity readings from a warehouse to the VizIoT server every 5 minutes. A SIM800L GSM module will be used for internet connectivity, and an SHT31-D sensor for measurements.


What You'll Need


Adding and Configuring the Device in VizIoT

  1. Create a new device in VizIoT, for example, "Test GPRS Thermometer".
  2. Add parameters:
    • tem — type Temperature, °C
    • hum — type Humidity, %
  3. In the "General Settings" section, copy the Access Key and Access Password — you will need them in the firmware.

Arduino Firmware

1. Create a New Project in Arduino IDE

2. Copy the Example Code:

#define TINY_GSM_MODEM_SIM800

#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
#include <Wire.h>
#include "Adafruit_SHT31.h" // https://github.com/adafruit/Adafruit_SHT31

#define SerialMon Serial
#define SerialAT Serial1

Adafruit_SHT31 sht31 = Adafruit_SHT31();

// Access Point settings
const char apn[]  = "YourAPN";
const char user[] = "";
const char pass[] = "";

// VizIoT device credentials
String VizIoT_Device_key  = "................";
String VizIoT_Device_pass = "....................";

// VizIoT Server
const char server[] = "VizIoT.com";
const int  port     = 48656;

TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
HttpClient http(client, server, port);

void setup() {
  SerialMon.begin(115200);
  delay(10);

  SerialAT.begin(115200);
  delay(3000);

  SerialMon.println(F("Initializing modem..."));
  modem.restart();

  String modemInfo = modem.getModemInfo();
  SerialMon.print(F("Modem: "));
  SerialMon.println(modemInfo);

  Serial.println("Searching for SHT31-D sensor");
  if (!sht31.begin(0x44)) {
    Serial.println("Couldn't find SHT31-D (check wiring)");
  }
}

void loop() {
  SerialMon.print(F("Waiting for network..."));
  if (!modem.waitForNetwork()) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  SerialMon.print(F("Connecting to APN "));
  SerialMon.print(apn);
  if (!modem.gprsConnect(apn, user, pass)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  SerialMon.print(F("Sending HTTP GET request... "));

  int err = http.get(getResource().c_str());
  if (err != 0) {
    SerialMon.println(F("connection failed"));
    delay(10000);
    return;
  }

  http.stop();
  SerialMon.println(F("Disconnected from server"));

  modem.gprsDisconnect();
  SerialMon.println(F("GPRS disconnected"));

  delay(5 * 60 * 1000); // sleep for 5 minutes
}

String getResource() {
  String resource = String("/update?key=") + VizIoT_Device_key +
                    "&pass=" + VizIoT_Device_pass;

  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (!isnan(t)) {
    Serial.print("Temperature °C = ");
    Serial.println(t);
    resource += String("&tem=") + t;
  } else {
    Serial.println("Failed to read temperature");
  }

  if (!isnan(h)) {
    Serial.print("Humidity % = ");
    Serial.println(h);
    resource += String("&hum=") + h;
  } else {
    Serial.println("Failed to read humidity");
  }

  return resource;
}

3. Install the Required Libraries

4. Set the Variable Values in the Firmware

  • apn — GSM access point name
  • user — APN user
  • pass — password
  • VizIoT_Device_key — access key
  • VizIoT_Device_pass — access password

Hardware Connection

Connecting the SHT31-D Sensor

Sensor Pin Arduino Pin
VIN 3.3V
GND GND
SCL SCL
SDA SDA

Connecting SIM800L to Arduino MEGA 2560

⚠️ Important! The SIM800L module cannot be powered directly from the Arduino — an external 4.0V power source is required.

SIM800L Pin Connection
VIN +4V external source
GND Source GND and Arduino GND
TX Arduino RX1
RX Arduino TX1 via a voltage divider

Voltage Divider Schematic for RX:

Arduino GND ----[10kΩ]---+
                         +---- RX SIM800L
Arduino TX ----[10kΩ]----+

For more connection details, see the article on SIM800L at Codius.ru.


Uploading the Firmware

Connect the Arduino to your computer, select the port, and upload the sketch.


Adding Widgets in VizIoT

  1. Create a dashboard, for example: "Test Temp Humidity Panel"
  2. Add widgets:

a) Air Temperature

  • Type: Graph
  • Device: Test GPRS Thermometer
  • Parameter: tem

b) Air Humidity

  • Type: Graph
  • Device: Test GPRS Thermometer
  • Parameter: hum

c) Temperature and Humidity Changes

  • Type: Changes Histogram
  • Parameters: tem and hum

All Set!

The device is configured — now just wait for its first connection to the VizIoT server. After connecting, you will start receiving temperature and humidity data every 5 minutes.