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
- Linksprite GSM shield
- Linksprite breakout shield
- linksprite thermal module
- Arduino Uno
- Data/M2M Sim Card
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);
}