Problema accensione via SMS

Salve, ho provato ad accendere e spegnere la lampadina con Arduino Uno R3 e Arduino GSM shield inviando via SMS off (spegni) e on (accendi).Per alimentare la lampadina ho usato questo relè TinkerKit Modulo Relay.All'entrata ho collegato il filo neutro (blu) al NO e il secondo (blu) al COM.L'uscita i tre cavetti ho collegato all'Arduino GSM shield il cavetto nero alla massa (GND), il cavetto rosso all'alimentazione (5V) e il cavetto arancione al PIN 12.Il codice ho copiato da Arduino Tutorial Wired SMSHeather http://playground.arduino.cc/Italiano/TutorialWired#SMSHeather.Mi potete indicarmi che cosa devo scrivere nel codice. Qui ho inserito il mio numero di telefono cellulare

// String to hold the incoming message
String message = "";

o devo inserire il numero della SIM di Arduino GSM Shield.Grazie.

Ciao,
chi mi può aiutare come inviare SMS per accendere e spegnere?Grazie Il codice è questo:

/*
 SMS heather remote control
 
 This sketch, designed for the GSM shield, allows you to remotely control any
 device connected to your Arduino. By sending an SMS, through certain keywords, 
 it's possible, as in this case, to turn on or off a simple heater.
 
 The GSM module, mounted on an Arduino board, processes the message and executes an action.
 Then, it sends a notification message containing the state of the device.
 If the message doesn't contain any valid keyword, the Arduino doesn't execute any 
 operation and the message is deleted from the sim card. 
 The sketch also manages keywords with uppercase or lowercase.
 
 Circuit:
 * GSM shield and an Arduino board
 * SIM card that can send/receive SMS
 * a relay connected to digital pin 12
 
 based on the ReceiveSMS example by Javier Zorzano / TD
 modified by Federico Vanzati & Alberto Cicchi (03/2013)
 
 */

// include the GSM library
#include <GSM.h>

const int heaterControlPin = 12;

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];  

// String to hold the incoming message
String message = "";

// String that will contain the parsed values from the message
String commandID, deviceID;

void setup() 
{
  // set the pin connected to the relay that control the heater as output
  pinMode(heaterControlPin, OUTPUT);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  } 

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin()==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");

}

void loop() 
{
  char c;

  // If there are any SMS available  
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    // usually anonymous messages starts with #
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while(c = sms.read())
      message += c;

    // cancella message ricevuto 
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  // if there is a new message start to parse the command and the device to control
  if(message != "") {

    // put the incoming characters that compose the message to lower case
    message.toLowerCase();

    int i=0; 

    // deviceID and commandID are separated by a space
    // find it and store the position in two strings
    while(message.charAt(i) != ' ') i++;

    commandID = message.substring(0,i);
    deviceID = message.substring(i+1, message.length());

    // check the device to control
    if(deviceID == "stufetta")
    {
      //check the command to execute
      if(commandID == "accendi") {
        sendFeedbackSMS(senderNumber, deviceID, "ON");  // send the feedback to the sender
        digitalWrite(heaterControlPin, HIGH);
      }
      if(commandID == "spegni") {
        sendFeedbackSMS(senderNumber, deviceID, "OFF"); // send the feedback to the sender
        digitalWrite(heaterControlPin, LOW);
      }
    }

    // clear the message that has just been processed
    message = "";
  }

  delay(1000);
}

// this function, given a phone number and two strings representing the device and 
// its state send a feedback text message to the phone number
void sendFeedbackSMS(char remoteNum[], String devString, String devState) {
  String txtMsg = devString + " " + devState;
  Serial.println(txtMsg);
  Serial.println(remoteNum);

  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS(); 
}

Ciao,
prima di tutto prova il codice as-is e invia il messaggio “accendi stufetta” o “spegni stufetta”
Il codice cerca infatti lo spazio " " in mezzo alle due parole per separarle e capire quindi se vuoi accendere o spegnere il carico.
Poi prova a fare le tue modifche.
Se vuoi inviare un messaggio diverso, devi lavorare sulla parte del codice che fa il parsing del messaggio, ovvero:

// if there is a new message start to parse the command and the device to control
  if(message != "") {

    // put the incoming characters that compose the message to lower case
    message.toLowerCase();

    int i=0; 

    // deviceID and commandID are separated by a space
    // find it and store the position in two strings
    while(message.charAt(i) != ' ') i++;

    commandID = message.substring(0,i);
    deviceID = message.substring(i+1, message.length());

    // check the device to control
    if(deviceID == "stufetta")
    {
      //check the command to execute
      if(commandID == "accendi") {
        sendFeedbackSMS(senderNumber, deviceID, "ON");  // send the feedback to the sender
        digitalWrite(heaterControlPin, HIGH);
      }
      if(commandID == "spegni") {
        sendFeedbackSMS(senderNumber, deviceID, "OFF"); // send the feedback to the sender
        digitalWrite(heaterControlPin, LOW);
      }
    }

    // clear the message that has just been processed
    message = "";
  }

poi:

Qui ho inserito il mio numero di telefono cellulare

lascia stare, che quella variabile serve a registrare il messaggio in arrivo…

EDIT:
Sullo shield che SIM hai montato?

Stai usando la SIM movistar che hai ricevuto insieme allo shield?

Si uso la SIM movistar che ho ricevuto insieme allo shield.

Ecco allora il problema è lì. Essendo una sim M2M (machine-to-machine) ha la limitazione di poter funzionare solo all'interno del circuito di sim M2M movistar. Detto in soldoni, per motivi di sicurezza (le sim non sono associate a persone fisiche) c'è un firewall che blocca SMS e voce sia in ingresso che in uscita verso tutti gli altri operatori.

Per scrivere quel tutorial abbiamo usato un'altra sim "tradizionale".

Devo provare ad inserire la SIM tradizionale del telefono cellulare per esempio Vodafone.E se non funziona che altre SIM posso usare?

Ciao,
ho provato ad inserire la scheda SIM tradizionale,ma non ho ricevuto nessun risultato.Ma la SIM ha il codice PIN,devo modificare lo script?E’ dove devo scrivere questo script per fare funzionare? Che cosa devo fare? Grazie.

/*
 SMS heather remote control
 
 This sketch, designed for the GSM shield, allows you to remotely control any
 device connected to your Arduino. By sending an SMS, through certain keywords, 
 it's possible, as in this case, to turn on or off a simple heater.
 
 The GSM module, mounted on an Arduino board, processes the message and executes an action.
 Then, it sends a notification message containing the state of the device.
 If the message doesn't contain any valid keyword, the Arduino doesn't execute any 
 operation and the message is deleted from the sim card. 
 The sketch also manages keywords with uppercase or lowercase.
 
 Circuit:
 * GSM shield and an Arduino board
 * SIM card that can send/receive SMS
 * a relay connected to digital pin 12
 
 based on the ReceiveSMS example by Javier Zorzano / TD
 modified by Federico Vanzati & Alberto Cicchi (03/2013)
 
 */

// include the GSM library
#include <GSM.h>

const int heaterControlPin = 12;

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];  

// String to hold the incoming message
String message = "";

// String that will contain the parsed values from the message
String commandID, deviceID;

void setup() 
{
  // set the pin connected to the relay that control the heater as output
  pinMode(heaterControlPin, OUTPUT);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  } 

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin()==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(500);
    }
  }

  Serial.println("GSM initialized");

}

void loop() 
{
  char c;

  // If there are any SMS available  
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    // usually anonymous messages starts with #
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while(c = sms.read())
      message += c;

    // cancella message ricevuto 
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  // if there is a new message start to parse the command and the device to control
  if(message != "") {

    // put the incoming characters that compose the message to lower case
    message.toLowerCase();

    int i=0; 

    // deviceID and commandID are separated by a space
    // find it and store the position in two strings
    while(message.charAt(i) != ' ') i++;

    commandID = message.substring(0,i);
    deviceID = message.substring(i+1, message.length());

    // check the device to control
    if(deviceID == "stufetta")
    {
      //check the command to execute
      if(commandID == "accendi") {
        sendFeedbackSMS(senderNumber, deviceID, "ON");  // send the feedback to the sender
        digitalWrite(heaterControlPin, HIGH);
      }
      if(commandID == "spegni") {
        sendFeedbackSMS(senderNumber, deviceID, "OFF"); // send the feedback to the sender
        digitalWrite(heaterControlPin, LOW);
      }
    }

    // clear the message that has just been processed
    message = "";
  }

  delay(500);
}

// this function, given a phone number and two strings representing the device and 
// its state send a feedback text message to the phone number
void sendFeedbackSMS(char remoteNum[], String devString, String devState) {
  String txtMsg = devString + " " + devState;
  Serial.println(txtMsg);
  Serial.println(remoteNum);

  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS(); 
}

christiaan:
…Ma la SIM ha il codice PIN,devo modificare lo script?..

Inseriscila in un telefonino e togli il codice PIN ! :slight_smile:

Guglielmo

Togli il PIN :) gpb, mi hai battuto di qualche ciclo macchina ;)

Ciao, ho tolto il codice PIN,ma ancora non funziona.

Ho provato ad accendere e spegnere la lampadina senza GSM shield.Ho copiato e modificato questo codice script da
http://www.tinkerkit.com/relay-tutorial/.

/*
  based on Blink, Arduino's "Hello World!"
  Turns on an LED on for one second, then off for one second, repeatedly.
  The Tinkerkit Led Modules (T010110-7) is hooked up on O0

  created in Dec 2011
  by Federico Vanzati

  This example code is in the public domain.
 */
 
// include the TinkerKit library
#include <TinkerKit.h>

TKLed led(12);	// creating the object 'led' that belongs to the 'TKLed' class 
		// and giving the value to the desired output pin

void setup() {
// TinkerKit 'object' eliminate the need for pin declaration with pinMode()
}

void loop() 
{
  led.on();       // set the LED on
  delay(500);    // wait for a second
  led.off();      // set the LED off
  delay(500);    // wait for a second
}

ed ha funzionato.Come faccio con GSM Shield? Ho tolto il PIN della SIM.

Ciao, stai provando con il codice del Playground così com'è, inviando SMS "accendi stufetta" e "spegni stufetta"?

Con relè attaccato a piedino 12?

Ciao, si,sto provando con il codice del Playground così com'è, inviando SMS "accendi stufetta" e "spegni stufetta" con relè attaccato a piedino 12.

puoi far gestire il pin allo shield passandolo come parametro nel metodo begin(). Esempio:

while(notConnected)
  {
    if(gsmAccess.begin("1234")==GSM_READY)
      notConnected = false;

Al monitor seriale mi appare questo:

GSM initialized
Message received from:
+39340****** (numero del telefono cellulare)
MESSAGE DELETED

All’uscita del relè ho collegato il cavo blu (NO e COM),ma la luce non si accende.Il codice è questo:

/*
 SMS heather remote control
 
 This sketch, designed for the GSM shield, allows you to remotely control any
 device connected to your Arduino. By sending an SMS, through certain keywords, 
 it's possible, as in this case, to turn on or off a simple heater.
 
 The GSM module, mounted on an Arduino board, processes the message and executes an action.
 Then, it sends a notification message containing the state of the device.
 If the message doesn't contain any valid keyword, the Arduino doesn't execute any 
 operation and the message is deleted from the sim card. 
 The sketch also manages keywords with uppercase or lowercase.
 
 Circuit:
 * GSM shield and an Arduino board
 * SIM card that can send/receive SMS
 * a relay connected to digital pin 12
 
 based on the ReceiveSMS example by Javier Zorzano / TD
 modified by Federico Vanzati & Alberto Cicchi (03/2013)
 
 */

// include the GSM library
#include <GSM.h>

const int heaterControlPin = 12;

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];  

// String to hold the incoming message
String message = "";

// String that will contain the parsed values from the message
String commandID, deviceID;

void setup() 
{
  // set the pin connected to the relay that control the heater as output
  pinMode(heaterControlPin, OUTPUT);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  } 

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin("1234")==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(500);
    }
  }

  Serial.println("GSM initialized");

}

void loop() 
{
  char c;

  // If there are any SMS available  
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    // usually anonymous messages starts with #
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while(c = sms.read())
      message += c;

    // cancella message ricevuto 
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  // if there is a new message start to parse the command and the device to control
  if(message != "") {

    // put the incoming characters that compose the message to lower case
    message.toLowerCase();

    int i=0; 

    // deviceID and commandID are separated by a space
    // find it and store the position in two strings
    while(message.charAt(i) != ' ') i++;

    commandID = message.substring(0,i);
    deviceID = message.substring(i+1, message.length());

    // check the device to control
    if(deviceID == "stufetta")
    {
      //check the command to execute
      if(commandID == "accendi") {
        sendFeedbackSMS(senderNumber, deviceID, "ON");  // send the feedback to the sender
        digitalWrite(heaterControlPin, HIGH);
      }
      if(commandID == "spegni") {
        sendFeedbackSMS(senderNumber, deviceID, "OFF"); // send the feedback to the sender
        digitalWrite(heaterControlPin, LOW);
      }
    }

    // clear the message that has just been processed
    message = "";
  }

  delay(500);
}

// this function, given a phone number and two strings representing the device and 
// its state send a feedback text message to the phone number
void sendFeedbackSMS(char remoteNum[], String devString, String devState) {
  String txtMsg = devString + " " + devState;
  Serial.println(txtMsg);
  Serial.println(remoteNum);

  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS(); 
}

Ciao Cristiaan. Ho acquistato due giorni fa lo shield GSM/GPRS sviluppata da Telefonica. Avevo anche io il tuo stesso problema. Ho intanto sostituito la SIM e ho ricopiato lo sketch del Playground. Il messaggio da spedire (e qui era "l'inghippo") è accendi stufetta o spegni stufetta. Senza virgolette, solo lo spazio tra le due parole. Spero comunque tu abbia risolto il problema.

anche io ho problemi con questo script…l’ho modificato leggermente e poi aggiunto qualche messaggio qua e la per vedere dov’era il problema ma non lo trovo…
Sms vengono ricevuti e comandi individuati correttamente…l’sms di risposta arriva ma il relay non si eccita.

di seguito il codice:

// include the GSM library
#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];

// String to hold the incoming message
String message = "";

// String that will contain the parsed values from the message
String commandID, deviceID;

void setup() {
    // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

    // set the pin connected to the relay that control the heater as output
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;
  // Start GSM connection
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
  
}

void loop() {
  char c;
  // If there are any SMSs available()
  if (sms.available()) {
    Serial.println("Message received from:");

    // 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("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while (c = sms.read()) {
      message += c;
      Serial.println(message);
    }

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }
  
// if there is a new message start to parse the command and the device to control
  if(message != "") {

    // put the incoming characters that compose the message to lower case
    message.toLowerCase();

    int i=0; 

    // deviceID and commandID are separated by a space
    // find it and store the position in two strings
    while(message.charAt(i) != ' ') i++;

    deviceID = message.substring(0,i);
    commandID = message.substring(i+1, message.length());
    Serial.println(commandID);
    Serial.println(deviceID);

    // check the device to control
    if(deviceID == "stufa")
    {
      Serial.println("device found");
      //check the command to execute
      if(commandID == "on") {
        Serial.println("comand ON");
        sendFeedbackSMS(senderNumber, deviceID, "ON");  // send the feedback to the sender
        digitalWrite(12, HIGH);
      }
      if(commandID == "off") {
        Serial.println("comand OFF");
        sendFeedbackSMS(senderNumber, deviceID, "OFF"); // send the feedback to the sender
        digitalWrite(12, LOW);
      }
    }

    // clear the message that has just been processed
    message = "";
  }
  delay(1000);

}

// this function, given a phone number and two strings representing the device and 
// its state send a feedback text message to the phone number
void sendFeedbackSMS(char remoteNum[], String devString, String devState) {
  String txtMsg = devString + " " + devState;
  Serial.println(txtMsg);
  Serial.println(remoteNum);

  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS(); 
}