Renewable Energy Innovation

  • Increase font size
  • Default font size
  • Decrease font size
Email Print

No image

I've been wanting to play around with sending data via a mobile SIM card and, after needing to do it for another project, here is a short post on my attempts at getting it all going.

I used an off the shelf GSM/GPRS module (the SIM900).

I tried this using both the Arduino Uno and the Arduino Leonardo.

Here are the results from my tests.

Hardware

A SIMcom SIM900 unit was purchased from iTead Studio for  around $37 + delivery. These SIM900 based units are available from a number of sources.

This was connected to an Arduino Leonardo and to an Arduino Uno with the GND, 5V, Tx and Rx pins, along with the power pin, which was connected to pin D9, so the device could be toggled on and off.

I bought a low cost pay as you go SIM card. This was loaded with £1 of credit. This was not activated when I first tried these tests and so would not work before I gave the customer support a ring - ensure you test your SIM card and make sure you have credit on the card before doing any of this.

No Image

No Image

No Image

Software

There is a tutorial here from Tronixstuff about connecting these modules to Arduino.

You need the SIM900 datasheet and the AT command list for controlling it.

Testing

The SIM900 unit uses relatively simple AT commands. These are listed in the AT command document. You must note that the standard comms frequency is 19200 baud, so ensure you set up your serial to that.

Making a phone call

I followed the (great) Tronixstuff tutorial and created a softwareserial port and copied the example, but with my normal mobile phone number in it.

After a short while my Arduino gave me a ring. Spooky.

I tested this with the Arduino uno and it worked fine, with Rx and Tx on pins D2 and D3 respectively.

When I tested this on my Arduino Leonardo boards (ones I had just designed for another project) and it did not work. A bit of research and you find that the Leonardo (due to the different microcontroller used) cannot have interrupts on all the pins, so you can only have Rx on pins 8,9,10,11, 14,15,16 as noted by Arduino here.

The Tx and Rx pins were changed to pins 10 and 11. This worked and it called me, but only one time out of ten, the other times it seemed to be browning out. This might be due to power supply issues and the fact I was using a cheap micro-USB which probably does not have much copper in it so cannot take much current. (Edit: I had an incorrect regulator IC on the board which was probably causing some issues)

I added an external power supply and tried again. This worked OK, although I still had an issue with the unit only working one time in three or four.

I was not using a proper GSM ariel (just a piece of wire), so I have ordered an SMA GSM arial to fix on and test out and will note back here any improvement.

Here is the Arduino code used to send AT commands to phone the phone number. The Phone number is entered along with the country code (in the UK this is 44), but without the initial 0. For example a UK phone number of 07812345678 is sent as 447812345678.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(10, 11); // configure software serial port
// Note: Leonardo cannot have interrupts on all pins, so Rx can only be on 8,9,10,11,14,15,16
// Note from: http://arduino.cc/en/Reference/softwareSerial

void setup()
{
  pinMode(9, OUTPUT);
  Serial.begin(9600);
  SIM900.begin(19200);
  delay(2000);
  SIM900power();  
  delay(60000);  // give time to log on to network.
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  Serial.println("Power Reset Start");
  delay(1000);
  digitalWrite(9, LOW);
  
  Serial.println("Power Reset End");
  delay(5000);
}
 
void callSomeone()
{
  SIM900.println("ATD + +447812345678;"); // dial UK phone
  Serial.println("ATD + +447812345678;");
  delay(100);
  SIM900.println();
  delay(10000);            // wait for 5 seconds...
  SIM900.println("ATH");   // hang up
  Serial.println("ATH - HANG UP");
}
 
void loop()
{  
  callSomeone(); // call someone
  SIM900power();   // power off GSM shield
  do {} while (1); // do nothing
}

No Image

This is the SIM900 module connected to (my design) Arduino Leonardo board and the 99p shop SIM card.

Sending a text

The next test was sending text messages. Information to do this is also on the Tronixstuff post. This also used the AT commands and is also pretty simple. 

The Arduino code to do this is here:

#include <SoftwareSerial.h>
SoftwareSerial SIM900(10, 11); // configure software serial port
// Note: Leonardo cannot have interrupts on all pins, so Rx can only be on 8,9,10,11,14,15,16
// Note from: http://arduino.cc/en/Reference/softwareSerial

void setup()
{
  pinMode(9, OUTPUT);
  Serial.begin(9600);
  SIM900.begin(19200);
  delay(2000);
  SIM900power();  
  delay(60000);  // give time to log on to network.
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  Serial.println("Power Reset Start");
  delay(1000);
  digitalWrite(9, LOW);
  
  Serial.println("Power Reset End");
  delay(5000);
}
 
void callSomeone()
{
  SIM900.println("ATD + +447812345678;"); // dial UK phone
  Serial.println("ATD + +447812345678;");
  delay(100);
  SIM900.println();
  delay(10000);            // wait for 5 seconds...
  SIM900.println("ATH");   // hang up
  Serial.println("ATH - HANG UP");
}
 
void loop()
{  
  sendSMS();
  
  // callSomeone(); // call someone
  // SIM900power();   // power off GSM shield
  do {} while (1); // do nothing
}

void sendSMS()
{
  SIM900.print("AT+CMGF=1\r");
// AT command to send SMS message delay(100); SIM900.println("AT + CMGS = \"+447812345678\"");
// recipient's mobile number, in international format delay(100); SIM900.println("Hello, world. This is a text message from an Arduino Uno.");
// message to send delay(100); SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26 delay(100); SIM900.println(); delay(5000); // give module time to send SMS SIM900power(); // turn off module }

I used their examples to send a text to my phone....

No Image

My Arduino is texting me. Too wierd....

Sending text messages is a great way of adding fault finding functionality to remote units, such as charge controllers and data loggers. This is very easy to do, as long as there is credit on the phone SIM card.....

The Tronixstuff post goes into detail about receiving a call to the SIM900. This is fun, but not so much use to me.

Sending packets of data

I really want to be able to send packets of data, longer than a 160 character text message. This could be used for remote data-logging.

Doing a quick search I came up with the following information:

Information on the GSM library for GSM/GPRS.

This is good example code for attaching to a GPRS network.

GSM supports 2G services, including phone calls, SMS and data transfer through GPRS.

GPRS (General Packet Radio Service)  is a packet switching technology for 56-114k bit/sec data rates.

In order to send larger packets of information then an APN (Access Point Name) is required from your mobile provider.

So the first thing for me is to find a mobile provider which allows data transfer. I had a NOW mobile SIM card and they do a data service of either £1 for a day or £10 for a month.

I then needed the APN settings and found them on this (pretty bad coloured) website.

Now Mobile (Any SIM)
APN: nowmobilenet
Username: [leave blank]
Password: [leave blank]

So I am all set to try this out. I would like to be able to transfer a .csv file to a webhost location (such as my own webserver).

 

This is a work-in-progress, please check back for more info.