Such modules provide integration with the world of GSM, GPRS and GPS and all is achieved through very simple Arduino commands thanks to the open-source dedicated library. It is possible to place phone calls or to send SMS with few simple functions.

From the time of the last post presented, the library has been also improved with additional features such as DTMF tones management capabilities and the ability to send e-mails.

In this article, we’ll discuss the main innovations introduced in the software library and then, in future posts, we’ll show more examples of its features.

Let’s remember that, for reasons related to the optimization of RAM usage, the library is divided into classes, each with a specific function. As a result, if you want to use the phone calls, you should be including the related class:

#include “call.h”

In case of sms you’ll have include in the sketch:

#include “sms.h”

Th functionality to send DTMF (Dual-Tone Multi-Frequency) tones, is included in the class for call as it’s related.

To use these functions you just need to include the corresponding file and instantiate the object within the program. The functions shown in Table 1 refers to an object created with the following command at the beginning of the sketch: CallGSM call;

void SendDTMF(char* number_string, int time)

During an active call, it sends the string passed as a parameter, specifying the duration of each tone in tenths of a second.

The string can be composed of the following characters: 0-9, #, *, AD.

call.SendDTMF(“1,2,3,4,*”,2)

Table 1

EXAMPLE 1

This first example shows how to make a call to a preset number when an alarm condition occurs.

Such a condition occurs when the chosen analog input pin goes to less than 50. Remember that Arduino samples input voltages with 10 bits values: with the basic configuration, 1023 is equivalent to 5 volts, 50 will amount to approximately 0.25 volts.

A similar condition, with the appropriate choice of threshold values, may represent exceeding a limit temperature by a heat sensor or, similarly, the increase (or decrease) of brightness measured by a photoresistor.

With a few simple steps is possible to realize an alarm that able to alert about an alarm condition without additional expenses (it would be even sufficient to refuse the call, so to avoid connection charges).

Let’s see how to achieve that: if the alarm condition occurs a call is made ​​through the above-mentioned function call.Call (number).

To prevent a phone call is made ​​when there is already one active, the function first checks the state of the phone calls.

To check the status of the call, simply call the function call.CallStatus() and make sure that it returns a value other than CALL_ACTIVE_VOICE.

The above example could create some problems in case of values ​​that close to the threshold level: in fact, because of the noise on the sensor or even for rapid oscillations around the threshold, the alarm may repeatedly be activated or inactivated, generating problems.

To avoid this you should use a hysteresis cycle or just a filter on the measurement.

Regarding hysteresis, two different threshold values ​​are chosen to delay the activation and deactivation of the alarm, so that for the alarm to turn off it is necessary to move away significantly from the alarm condition.

Now we’ll show, instead, how to realize a small discrete-time low-pass filter of the first order to avoid that the high frequency oscillations may accidentally repeatedly activate the warning condition.

Unlike the previous example, we’ll use the following additional variables:

int mov_av=0;

float threshold=0.9;

In the setup we’ll initialize the first sample with the command:

lpf_val =analogRead(pin);

And in the loop() we will update the as it follows:

value=analogRead(pin);

lpf_val = lpf_val *threshold+(1-threshold)*value;

The variable lpf_val therefore will contain the filtered value. The cutoff frequency is determined by the value of the threshold (in this case it’s 0.9). Values ​​that are close to one lower the cutoff frequency, vice versa, values ​​that are close to zero raise the cutoff frequency by passing also the higher frequencies.

Obviously the condition will be evaluated on the filtered value with:

if (lpf_val <50)

EXAMPLE 3

In this example, that is similar to the above, we will make a call each time the state of a digital input changes state. In case of answer, you’ll hear a single DTMF in case the status on the chosen input is low, conversely two DTMF mean its high.

In future versions of SIM908 a DTMF tones decoder will also be implemented which you can use to decipher the tones sent by the user to the SIMCOM module. This feature is already available on the SIM900 sold in our store (not all SIM900 available in the market have this feature).

Looking at the code, there is a simple logic for alarm condition, that activates the communication routine for the given number.

As in previous examples, the presence of an active call is checked: if no calls ongoing, a new one is placed to the preset number, while if a call is ongoing the status of the selected input is first checked and subsequently this is communicated via DTMF tones.

call.SendDTMF(“0”, 1);

call.SendDTMF(“0,0”, 1)

The first command sends a string made of one number, on the contrary, the second one sends a string composed of two characters (note the use of the comma to separate characters) .

Adding a delay is key to avoid communicating continuously via the DTMF tones with the risk of misinterpreting the communication. In this case we have chosen a delay of 5 s.

At the end of the code you can see how the status update is made ​​only when a call is not active, to avoid making different communications during the same call.

In contrast the previous example, in this case we will decide when to query Arduino for the verification of the inputs: this is done thanks to a call.

The module will check if the calling number is among those authorized and eventually accept the call, communicating then with DTMF tones.

Regarding the authentication mechanism, we will use the function:

call.CallStatusWithAuth(number,8,10);

which will check if the number that is making the call is saved on the SIM in a position between the 8 and 10. The first string passed as a parameter will contain the the caller number. It is always advisable to choose not too large intervals, since each SIM query to get the numbers from the address book, requires few tenth of a second.

Unlike the previous distinguish whether the active call, or on arrival, belongs to a number saved on the SIM in a position between the initial and final, passed as parameters. The possible output byte are listed under the following names:

CALL_NONE or 0: No call.

CALL_INCOM_VOICE_AUTH or 3: Incoming call from a number authenticated.

CALL_INCOM_VOICE_NOT_AUTH or 4: Incoming call from a number not authenticated.

If(call.CallStatusWithAuth (number,9,9)==CALL_INCOM_VOICE_AUTH)

Serial.println(“INCOMING CALL FROM AN AUTH NUMBER, SAVED ON THE SIM IN POSITION 9”);

We’ll show you only the portion of code that regards the number verification, where to find also the functions to manage the call answer and closure:

call.PickUp();

call.HangUp();

state=call.CallStatusWithAuth(number,8,10);

if(state==CALL_INCOM_VOICE_AUTH)

{

[…]

}

delay(500);

};

EXAMPLE 5

Always in a purpose of saving expenses, let’s see how to make a similar example without generating any costs related to making calls.

The idea is to communicate the status of the input by refusing (or not) an incoming call. If the state is low, there will be no action, leaving the module ring. Conversely, if the input state is high, the call will be rejected.In this way you can be aware of the state without worrying about the cost of communication.

Inside the code you will notice the authentication mechanism. Indeed, in the case of an incoming call by an unauthorized number, no action is taken, leaving the module ringing regardless of the state of the inputs.

Incredible examples, I don´t understand what is the reason to use the Software Serial library if you are not declaring the pins to use. Could you tell me what are the pins that the program uses to active the gsm please, because I have a trouble when I try to connect a matricial keypad and I think the problem is where I connect the pins for the matricial keypad THANKS!!

BorisLandoni

See the library. Here you can find the used pins to comunicate with the module

marciokoko

Why do the Rx/Tx from SIM900 need to be connected to the 18/19 of MEGA? Cant they also be connected to the other Rx/Tx pins on the board? And how in code do I edit that if in fact I wish to use other pin sets on my MEGA?

BorisLandoni

Yes you can, but Mega has more HW serial

marciokoko

ATA is the command for answering a call. AT+CPBR=? reads all phonebook entries while CPBS= reads a specific entry and CPBW= [,, [,[]]] writes a number to memory.

Nigel

I am having trouble getting the sim card to register to the network, I see 1.5 volts on SimVDD then nothing. All searches on internet seem to point to power supply issues, but this should be a working design by OE, The GPS is working fine, I can communicate with the Sim908 using AT command example, but anything to do with sim just replies No Sim inserted! Why is this, this is just so frustrating!!!!!

BorisLandoni

You have to remove the welding from the rear of the PCB

suresh

i am trying to receive the dtmf tones but it is not happening , any one can help me?

Categories

Categories

Sponsors

About us

Open Source Electronics is the brainchild of a world leader in hobby electronics Futura Group srl.Open Source Electronics is devoted to support development, hacking and playing with electronics: we share exciting open projects and create amazing products!

Open Source Electronics is not just a container of ideas: it is also a web site lead by a team of engineers and geeks who will take part in the discussions and give support.

Our mission is to become a reference Open Source hacking site with ideas and feedback aimed to enrich the community.