Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KB
- String Comando; //Nós declaramos uma
- variável do tipo String para armazenar o texto SMS recebidos
- String teste;
- Strimg comando2;
- String led[2]={"off", "on"};
- #define LED1 12 //pino que está ligado (Digital 12) LED2
- #define LED2 13 //pino que está ligado (Digital 13) LED1
- void setup(){
- Serial.begin(9600); //Começamos a comunicação Serial
- Serial1.begin (9600);
- //Serial1.begin(9600);
- Serial.println("AT+CMGF=1"); //configurar o módulo para trabalhar com SMS em modo texto
- Serial1.println("AT+CNMI=1,2,0,0,0"); // configurar o módulo para nos mostrar o SMS recebido pela comunicação serial
- pinMode(LED1, OUTPUT); //definimos o pino onde o LED1 está ligado como saída
- pinMode(LED2, OUTPUT); //definimos o pino onde o LED2 está ligado como saída
- digitalWrite(LED1, LOW);//o LED1 inicia Desligado
- digitalWrite(LED2, LOW);//o LED2 inicia Desligado
- delay(1000); //Pausa de 1 segundo
- }
- void loop(){
- if (Serial.available()){ //Se os dados estão disponíveis
- Comando = Serial.readString(); //Aloja na variável de comando
- }
- if (Serial1.available()){ //Se os dados estão disponíveis
- Comando2 = Serial1.readString(); //Aloja na variável de comando
- }
- if(Comando2.indexOf("LED1 ON")>=0){ //Se a variável contém a palavra LED1 ON
- Serial.println("LED1 LIGADO"); //Avisamos por comunicacion serial
- digitalWrite(LED1, HIGH); //ativar o LED1
- retornaSMS();
- Comando = ""; //esvaziado a variável
- }
- if(Comando2.indexOf("LED1 OFF")>=0){ //Se a variável contém o comando palavra LED1 OFF
- Serial.println("LED1 DESLIGADO"); //Avisamos por comunicacion serial
- digitalWrite(LED1, LOW); //Desactivar o LED1
- retornaSMS();
- Comando = ""; //esvaziado a variável
- }
- if(Comando2.indexOf("LED2 ON")>=0){ //Se a variável contém a palavra LED2 ON
- Serial.println("LED2 LIGADO"); //Avisamos por comunicacion serial
- digitalWrite(LED2, HIGH); //ativar o LED2
- retornaSMS();
- Comando = ""; //esvaziado a variável
- }
- if(Comando2.indexOf("LED2 OFF")>=0){ //Se a variável contém o comando palavra LED2 OFF
- Serial.println("LED2 DESLIGADO"); //Avisamos por comunicacion serial
- digitalWrite(LED2, LOW); //Desactivar o LED2
- Comando = ""; //esvaziado a variável
- }
- }
- void retornaSMS()
- {
- teste="LED1= ";
- teste+=led[digitalRead(LED1)];
- teste+="\nLED2= ";
- teste+=led[digitalRead(LED2)];
- //teste+="\nLED3= "; //----------------so ir colocando as linhas dessa forma
- //teste+=led[digitalRead(LED3)];
- Serial.println("AT+CMGF=1"); //Define o módulo GSM no modo de texto
- delay(1000);
- Serial1.println("AT+CMGS=\"+5587988326471\"\r"); //Substituir x pelo número de celular
- delay(1000);
- Serial1.println(teste);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement