Tutorial: como utilizar o Cellular Shield com Arduino

 

***************************************************************************************************************************************************

ATENÇÃO: ESTE TUTORIAL FOI ATUALIZADO, VOCÊ PODE ACESSÁ-LO CLICANDO AQUI.

***************************************************************************************************************************************************

Neste tutorial, vamos mostrar como utilizar o Cellular Shield com Arduino. Com este shield pode fazer e receber ligações, mandar e receber mensagens e permite receber o mandar dados.

Para usar o Cellular Shield é necessário um chip de celular (SIM Card), pode ser pré ou pós-pago.

Aqui vamos mostrar apenas como utilizá-lo mandando ou recebendo mensagens, pois o método é praticamente o mesmo nas outras operações. Para saber mais informações, clique aqui.

Antes de mais nada. É necessário ver o esquemático da placa:

Podemos ver que podemos escolher, quais entradas podem ser modificadas, de fábrica o Shield vem com as conexões para Software Serial, sendo as portas digitais 2 e 3 do arduino. Pode-se mudar apenas mudando os jumpers soldados na placa como mostrado na figura abaixo:

Ao tirar as soldas e soldar os pads da direita e do meio, você mudará para os pinos digitais 0 e 1, onde se encontra o RX e TX do Arduino. Mas como neste tutorial, vamos utilizar como veio de fábrica, então não é necessário fazer este processo.

O Shield vem apenas com uma antena soldada na placa, caso queira utilizar o alto-falante e o microfone, é necessário soldá-los na placa nos pinos mostrados na figura abaixo:

Os pinos SPK_P e SPK_N são os pinos para o alto-falante. Os pinos MIC_P e MIC_N são os pinos para o microfone. E o GND que é o comum (terra).

Agora, precisamos saber um pouco sobre a lista de comandos para poder fazer as comunicações.

Alguns comandos que vamos utilizar neste tutorial:

  • AT - comando para checar o estado do módulo
  • ATE - comando para selecionar o ECHO Mode
  • AT+CMGF - comando para mandar mensagem SMS
  • AT+CMGL - comando para listar mensagens SMS recebidas

 

Para saber mais sobre outros comandos, clique aqui.

 

Agora, baixe a programação exemplo encontrada aqui. Mude os paramêtros em vermelho (para a IDE versão 1.0):

 

/
SparkFun Cellular Shield - Pass-Through Sample Sketch
SparkFun Electronics
Written by Ryan Owens
3/8/10

Description: This sketch is written to interface an Arduino Duemillanove to a Cellular Shield from SparkFun Electronics.
The cellular shield can be purchased here: http://www.sparkfun.com/commerce/product_info.php?products_id=9607
In this sketch serial commands are passed from a terminal program to the SM5100B cellular module; and responses from the cellular
module are posted in the terminal. More information is found in the sketch comments.

An activated SIM card must be inserted into the SIM card holder on the board in order to use the device!

This sketch utilizes the NewSoftSerial library written by Mikal Hart of Arduiniana. The library can be downloaded at this URL:
http://arduiniana.org/libraries/NewSoftSerial/

This code is provided under the Creative Commons Attribution License. More information can be found here:
http://creativecommons.org/licenses/by/3.0/

(Use our code freely! Please just remember to give us credit where it's due. Thanks!)
*/
#include <SoftwareSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h> //Used for string manipulations

char incoming_char=0; //Will hold the incoming character from the Serial Port.

SoftwareSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

void setup()
{
//Initialize serial ports for communication.
Serial.begin(9600);
cell.begin(9600);

//Let's get started!
Serial.println("Starting SM5100B Communication...");
}

void loop() {
//If a character comes in from the cellular module...
if(cell.available() >0)
{
incoming_char=cell.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
//If a character is coming from the terminal to the Arduino...
if(Serial.available() >0)
{
incoming_char=Serial.read(); //Get the character coming from the terminal
cell.print(incoming_char); //Send the character to the cellular module.
}
}

/* SM5100B Quck Reference for AT Command Set
*Unless otherwise noted AT commands are ended by pressing the 'enter' key.

1.) Make sure the proper GSM band has been selected for your country. For the US the band must be set to 7.
To set the band, use this command: AT+SBAND=7

2.) After powering on the Arduino with the shield installed, verify that the module reads and recognizes the SIM card.
With a terimal window open and set to Arduino port and 9600 buad, power on the Arduino. The startup sequence should look something
like this:

Starting SM5100B Communication...

+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1

Communication with the module starts after the first line is displayed. The second line of communication, +SIND: 10, tells us if the module
can see a SIM card. If the SIM card is detected every other field is a 1; if the SIM card is not detected every other field is a 0.

3.) Wait for a network connection before you start sending commands. After the +SIND: 10 response the module will automatically start trying
to connect to a network. Wait until you receive the following repsones:

+SIND: 11
+SIND: 3
+SIND: 4

The +SIND response from the cellular module tells the the modules status. Here's a quick run-down of the response meanings:
0 SIM card removed
1 SIM card inserted
2 Ring melody
3 AT module is partially ready
4 AT module is totally ready
5 ID of released calls
6 Released call whose ID=<idx>
7 The network service is available for an emergency call
8 The network is lost
9 Audio ON
10 Show the status of each phonebook after init phrase
11 Registered to network

After registering on the network you can begin interaction. Here are a few simple and useful commands to get started:

To make a call:
AT command - ATDxxxyyyzzzz
Phone number with the format: (xxx)yyy-zzz

If you make a phone call make sure to reference the devices datasheet to hook up a microphone and speaker to the shield.

To send a txt message:
AT command - AT+CMGF=1
This command sets the text message mode to 'text.'
AT command = AT+CMGS="xxxyyyzzzz"(carriage return)'Text to send'(CTRL+Z)
This command is slightly confusing to describe. The phone number, in the format (xxx)yyy-zzzz goes inside double quotations. Press 'enter' after closing the quotations.
Next enter the text to be send. End the AT command by sending CTRL+Z. This character can't be sent from Arduino's terminal. Use an alternate terminal program like Hyperterminal,
Tera Term, Bray Terminal or X-CTU.

The SM5100B module can do much more than this! Check out the datasheets on the product page to learn more about the module.*/

 

Conecte o Shield e coloque um cartão SIM no Shield. Agora, abra a IDE do arduino e cole o código. Conecte o Arduino no PC e na IDE do Arduino selecione a versão da placa Arduino (UNO, Duemilanove, etc) e a porta (COMx, ttyUSBx, ttyACMx, etc). Clique em UPLOAD.

Para utilizá-lo é necessário um programa de acesso a Serial, pois o Serial Monitor não detecta certos comandos (CTRL+Z). Aqui vamos utilizar o PUTTY.

Abrindo o PUTTY, selecione Serial, depois a porta em que o Arduino está conectado e a velocidade que é 9600. e por fim clique OPEN. Irá abrir a tela abaixo:

Ao abrir o tela, o Arduino irá conectar e mostrará os paramêtros da tela acima:

  • +SIND: 1 - o Cartão SIM está conectado;
  • +SIND: 10 - o Cartão SIM está conectado e funcionando;
  • +SIND: 3 - preparando módulo;
  • +SIND: 4 - módulo pronto;
  • +SIND: 7 - somente chamada de emergência;
  • +SIND: 11 - conectado a rede.

 

Pronto, seu Cellular Shield está pronto para o uso. Agora, para mandar uma mensagem SMS digite os comandos:

  • AT+CMGF=1 <ENTER>,
  • AT+CMGS="(DDD)xxxxxxxx" (o número do celular que você quer mandar a mensagem)<ENTER>.
  • Irá aparecer um '>' significando que você pode digitar a mensagem. Ao terminar de digitar a mensagem SMS, pressione 'CTRL+Z' e como resposta irá aparecer '+CMGS: um número qualquer' e depois 'OK'.

 

Agora para receber mensagem SMS, utilize os seguintes comandos:

  • AT+CMGF=1 <ENTER>;
  • AT+CMGL="ALL"; Irá aparecer +CMGL: 1,2,"REC READ","o nº do celular que mandou a mensagem SMS","o horário" e depois a mensagem escrita.

     

 

E é isso! Esperamos que tenha gostado! Se tiver dúvidas, poste aqui mesmo neste blog! Caso tenha sugestões para tutoriais, clique aqui! Para ver outros tutoriais e projetos desenvolvidos pela equipe LdG e por outros garagistas, clique aqui e aqui, respectivamente! Até a próxima!

 

Referências:

http://www.labdegaragem.org/loja/index.php/31-shields/cellular-shie...

http://www.sparkfun.com/products/9607

http://www.sparkfun.com/datasheets/DevTools/Arduino/cellular%20shie...

http://www.sparkfun.com/Code/Cellular_Shield_Passthrough.zip

http://www.sparkfun.com/datasheets/CellularShield/SM5100B%20Datashe...

http://www.sparkfun.com/datasheets/CellularShield/SM5100B%20AT%20Co...

http://www.sparkfun.com/datasheets/CellularShield/SM5100B%20SMS%20A...

http://www.sparkfun.com/datasheets/CellularShield/SM5100B%20TCPIP%2...

Exibições: 18874

Comentar

Você precisa ser um membro de Laboratorio de Garagem (arduino, eletrônica, robotica, hacking) para adicionar comentários!

Entrar em Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)

Comentário de Marcus A G da Rocha em 18 outubro 2012 às 20:03

Como faço pra descobrir qual das descrições do abaixo é o da minha operadora.

Comentário de Laboratório de Garagem em 17 outubro 2012 às 10:22

Oi Andre,

Você pode colocar uma antena de roteador normal, ou qualquer antena que tenha o mesmo encaixe do cellular shield.... 

Pode ser que mesmo com uma antena, o cellular shield perca sinal também, por causa da operadora que você está utilizando nele.... Sendo assim, experimente pegar um chip de outra operadora....

Abraços!!

Comentário de Andre Mescoloti em 16 outubro 2012 às 21:16

olá, eu gostaria de saber qual antena comprar para utilizar neste shield, eu o adquiri com vocês.
Porem estou tendo problemas com sinal. visto que este não possui uma antena adequada apenas o conector para esta.

Muito Obrigado desde já !

Comentário de Laboratório de Garagem em 16 outubro 2012 às 10:46

Pessoal, este tutorial foi testado e está funcionando.......

Para mudar a banda de operação para sua operadora digite: AT+SBAND=número da banda.

Para ver qual o número referente a banda da operadora vocês podem ver aqui ou ver na figura abaixo:

Abraços!

Comentário de Laboratório de Garagem em 16 outubro 2012 às 10:29

Oi Márcio,

Verifique se o seu código não está muito grande.... Se o código estiver com cerca de 30K, o seu Arduino pode travar.... 

Caso não seja isto, experimente tirar e colocar o módulo GSM da shield (uma placa metálica)... Às vezes pode ser algum mau contato no encaixe do módulo....

Senão o seu código pode ter alguma coisa errada que pode estar travando seu Arduino.... Às vezes é uma linha de código como condição dentro de um for ou while por exemplo....

Comentário de Márcio Muniz Arruda em 15 outubro 2012 às 11:05

Olá pessoal.

Estou fazendo um projeto onde teremos um GPS e o shield Celular que ao receber uma requisição por SMS o mesmo deverá responder para o requisitante o SMS com informações de Latitude e Longitude. Meu shield celular esta travando em algumas ocasiões, alguém já fez algo parecido e poderia me ajudar ?

Obrigado

Márcio 

Comentário de Marcus A G da Rocha em 12 outubro 2012 às 12:38

Estou encontrando problemas, existe uma falha no tutorial. Ele foi copiado ao pé da letra como se estivessemos no EUA, as bandas de transmissão GSM aqui no brasil não são as mesmas de lá.

Mesmo sendo leigo consegui detectar isso. nos EUA o comando para escolha da banda é  AT+SBAND=7

aqui não sabemos qual é.

infelizmente só detectamos o problema depois de comprar o sheild.

sacanagem o cara ter postado um tutorial sem ter testado!

Comentário de Andre Mescoloti em 16 agosto 2012 às 17:32

Estou com problemas, meu conhecimento em arduino não é muito grande.

Porem em programação esta tudo ok.

Eu segui tudo passo a passo, porem não conecta na rede da 8 e fica dando 4 logo mais, se alguem souber como me ajudar, e se possivel me enviar um email ficarei grato.

Estou com urgencia preciso terminar um projeto que envia sms.

Muito Obrigado desde ja!

Att

Comentário de Eduardo castellani em 29 junho 2012 às 13:22

Pra mim que sou novato ( em arduino e programação ) a coisa pega, mas vamos lá tentar. abraço e obrigado

Comentário de Fumio Sak em 26 junho 2012 às 21:53

Comprei esta placa e estou aguardando, quero fazer um teste conectando em um alarme e quando ele disparar o Arduino enviara uma mensagem indicando que o alarme disparou....quem sabe depois de pegar o jeito

colocar uma camera e tal.... mas com este tutorial já tenho por onde começar... valeu galera!!

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço