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

Temp monitor with SIM900 and Arduino Uno

Intro

I’d been looking to try and get GSM working with Blynk for some time. Now with release 4.3 of the Blynk Library, it’s finally working !! So I put together a basic Sketch to get my Arduino Uno sending Temp readings to Blynk.

Materials

What it looks like

A Sim900 sandwhich. Sim900 Salami, with an Arduino Uno and breakout shield bread ciabatta, topped with a thermal sensor for presentation

The Blynk Project App screen

Granted, somewhat lacking in presentation… but despite successfully getting this working, it was 4am and I had lost the will to live, let alone make my project look pretty… another time, I’ll add some bling to my Blynk later

What you should see on the serial monitor

Hopefully without the dodgy sim card issue

Yes I made my video look like a hip hop video, all be it the least bling hip hop video of all time… because… because… I got side tracked playing with the video editor in youtube… why not…

Code Source

This takes the Sim800/Sim900 GSM example sketch from the Blynk library (v4,3). I had to modify the software serial pins to use pins 7 and 8, rather than 2 and 3. I also had to change the baud from 115200 to 19200, as it didn’t work as suggested even with 38400.

The linksprite site has some really cool modular sensors which plug straight into the breakout shield, similar to the Seeed grove kits. On the linksprite web site you can get code snippets for each sensor or led or whatever . These typically use serial.print to display results (which I have kept in the code of my sketch for visual feedback in the serial monitor), but writting to virtual pins for Blynk to read is nice and simple. In the code below, the Thermal module is plugged into pin A0 and I’ve taken the Celsius temp reading and written to virtual pin 1, to use with Blynk, but left in the float values for Fahrenheit and Voltage printing to the serial monitor, so these could also be written to virtual pins.

Code Function

Arduino Uno connects to Blynk server via GSM using Sim900.

Takes temperature readings from temp module at pin A0, converts to Fahrenheit and Celsius and makes Celsius reading available through virtual pin V1. Voltage, Fahrenheit and Celsius values are all displayed in the serial monitor at 5 second intervals.

I do plan to change the sketch to use the simpletimer library rather than the delay function, but it’s 3am… and I couldn’t be bothered.

Anyway, I hope someone finds this useful

##Code

/**************************************************************
 * 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!
 *
 **************************************************************/

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures

#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

#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

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

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "";
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 setup()
{
  // Set console baud rate
  Serial.begin(19200);
  delay(10);

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

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

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

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

void loop()
{
  Blynk.run();

 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 // print out the voltage
 Serial.print(voltage); Serial.println(" volts");
 
 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");
Blynk.virtualWrite(V1, temperatureC);
 
 // now convert to Fahrenheight
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(5000);  
  
}
10 Likes

Nice project, I have been interested in this kind of projects, like a remote start my car, so cold around here!

Quick question:

do you need to buy a SIM card, or the module provides everything for the GSM communication?

You’ll need to get a sim card. If you do a google search on M2M sims, there are some good deals on pay as you go, low throughput data sims.

Glad you found the project a worthwhile read

FYI, linksprite do a mosfet relay straight off the base shield which could be handy for what you want.

http://linksprite.com/wiki/index.php5?title=Mosfet_Module#Application_Ideas

i have tried this code with SIM 900A shield

/**************************************************************
 * 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>

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

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "";
char user[] = "";
char pass[] = "";

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

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

TinyGsm modem(SerialAT);

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

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

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

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

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

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

i have added this to code .

#define TINY_GSM_MODEM_SIM900

without defining gsm modem type getting number of errors.
getting this output for above code.

[13298] Modem init...
[23555] Cannot init
[13254] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on Arduino Uno

[13298] Modem init...
[23555] Cannot init
[13254] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on Arduino Uno

[13298] Modem init...
[23555] Cannot init
[13254] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on Arduino Uno

[13298] Modem init...
[23555] Cannot init
[13254] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on Arduino Uno

[13298] Modem init...
[23555] Cannot init

it doesn’t connecting,

@saurabh47, use the diagnostics tool sketch from TinyGSM

What Vhymanskyy said, but also, my GSM module wouldn’t initiate properly running off power from my Arduino and I had to use a separate power supply. Have you tried running your SIM900A shield off an independent power supply ?

I would also check the software serial pins. Mine doesn’t run over pins 2 and 3 and I had to change it to pins 7 and 8. Worth looking at that.

No,i will try this.

Mine sheild works well with pin 2,3.

Just a reminder: I’m sure you know, that original SIM900A is a dual band modem. I don’t know the location you are trying to run this thing, but in Europe it doesn’t work “out of the box”. It cannot initialize SIM - “invalid SIM error”, or sth like that.

By the way: :tada: HAPPY NEW YEAR TO A WHOLE COMMUNITY! :tada:

This module works fine in india.
HAPPY NEW YEAR

I tried it using sim808 …it took a while initializing too… But it eventually connected…
I hope someone can suggest something I can do to get it connected instantly

This looks very helpful, just one query can we use hardware serial Rx-Tx(0,1) with uno, in case if not using serial monitor for display

You could, but then you lose a lot of debugging potential.
using #define BLYNK_PRINT Serial gives a lot of valuable data about the connection attempts to the Blynk server, and if things stop working then you’ll miss this functionality.

Bearing in mind that the original post was 4 years ago, things have moved-on considerably since. I’d go for the TTGO T-Call ESP32 board with built-in GSM modem/SIM card slot if I were you. This overcomes the lack of hardware serial ports too.

Pere.

1 Like

Yeah, I am facing a lot of problems in debugging, it is disconnecting so randomly. I will try to implement it using software serial. Thank you for valuable reply.

Using SoftwareSerial for baud rates above 9600 won’t give reliable results.

Pete.

1 Like