Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 11336

Problema Arduino a devolver SMS

$
0
0
Boa noite!

Tou a fazer o controlo de um rela por sms!
O que acontece é o seguinte se eu tiver so a controlar o rela funciona bem consigo ligar e desligar o problema e quando coloco o codigo para me devolver uma sms porque ele comeca a enviar sms e não para!

Vou deixar aqui o cod haver se alguem me consegue dar uma dica!!

Obg


#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);
int  porta = 13;
int x,y;
String textForSMS;

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(100);
  digitalWrite(9, LOW);
  delay(100);
}





void setup()
{
     pinMode(porta,OUTPUT);
     digitalWrite(porta,HIGH);



  Serial.begin(19200);

  // wake up the GSM shield
  SIM900power();
  SIM900.begin(19200);
  delay(200);  // give time to log on to network.
  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out

  Serial.println("Ready...");

}



void loop()

{


  //If a character comes in from the cellular module...
    if(SIM900.available() >0)

    {

      inchar=SIM900.read();



       if (inchar=='L')
                   {
                     digitalWrite(porta,HIGH);
                     Serial.println("Luz Ligada ");


                delay(100);
                  SIM900.println("AT + CMGS = \"003519382*****\"");                                     // recipient's mobile number, in international format
                  delay(100);
                  SIM900.println("Luz Ligada Sr. Custodio!!");        // 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


                   }

    if (inchar=='D')
                 {

                 digitalWrite(porta,LOW);
                 Serial.println("Luz Desligada");




                  delay(100);
                  SIM900.println("AT + CMGS = \"003519382****\"");                                     // recipient's mobile number, in international format
                  delay(100);
                  SIM900.println("Luz Desligada Sr. Custodio!!");        // 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


            }




      }




}

Viewing all articles
Browse latest Browse all 11336

Trending Articles