Boa noite!

Estou realizando um projeto onde uso o arduino duemilanove e o shield sim900d.A minha intençao é receber um sms pelo arduino, após ele receber acionar um led e enviar um sms ao número que chamou com a informação de que o led foi aceso.

Eu já consegui recber o sms, mas não sei acrescentar no código a informação para ele acionar o led e enviar o sms de volta.

Se alguém puder me ajudar vou ficar muito agradecido. Abaixo o código que estou usando:

#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];  
int powerkey =  5;
int statuspin = 6;
int pinState = 0;
String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
char inChar;


void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
     pinMode(powerkey, OUTPUT);
  pinMode(statuspin, INPUT);
  inputString.reserve(200);
  } delay(100);

  Serial.println("Serial conectada");
    
  // connection state
  boolean notConnected = true;
 
  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Nao conectado");
      delay(1000);
    }
  }
 
  Serial.println("GSM inicializado");
  Serial.println("Aguardando novas mensagens");
}

void loop()
{
  char c;
 
  // If there are any SMSs available()  
  if (sms.available())
  {
    Serial.println("Mensagem recebida de:");
    
    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    if(sms.peek()=='#')
    {
      Serial.println("SMS Descartada");
      sms.flush();
    }
    
    // Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);
      
    Serial.println("\nFim da Mensagem");
    
    // Delete message from modem memory
    sms.flush();
    Serial.println("MENSAGEM APAGADA");
  }

  delay(1000);

}

Abraços

Alencar

Exibições: 220

Responder esta

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço