Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. KB
  2. String Comando; //Nós declaramos uma
  3. variável do tipo String para armazenar o texto SMS recebidos
  4. String teste;
  5. Strimg comando2;
  6. String led[2]={"off", "on"};
  7. #define LED1 12 //pino que está ligado (Digital 12) LED2
  8. #define LED2 13 //pino que está ligado (Digital 13) LED1
  9.  
  10. void setup(){
  11. Serial.begin(9600); //Começamos a comunicação Serial
  12. Serial1.begin (9600);
  13. //Serial1.begin(9600);
  14. Serial.println("AT+CMGF=1"); //configurar o módulo para trabalhar com SMS em modo texto
  15. Serial1.println("AT+CNMI=1,2,0,0,0"); // configurar o módulo para nos mostrar o SMS recebido pela comunicação serial
  16. pinMode(LED1, OUTPUT); //definimos o pino onde o LED1 está ligado como saída
  17. pinMode(LED2, OUTPUT); //definimos o pino onde o LED2 está ligado como saída
  18. digitalWrite(LED1, LOW);//o LED1 inicia Desligado
  19. digitalWrite(LED2, LOW);//o LED2 inicia Desligado
  20. delay(1000); //Pausa de 1 segundo
  21. }
  22.  
  23. void loop(){
  24. if (Serial.available()){ //Se os dados estão disponíveis
  25. Comando = Serial.readString(); //Aloja na variável de comando
  26. }
  27. if (Serial1.available()){ //Se os dados estão disponíveis
  28. Comando2 = Serial1.readString(); //Aloja na variável de comando
  29. }
  30. if(Comando2.indexOf("LED1 ON")>=0){ //Se a variável contém a palavra LED1 ON
  31. Serial.println("LED1 LIGADO"); //Avisamos por comunicacion serial
  32. digitalWrite(LED1, HIGH); //ativar o LED1
  33. retornaSMS();
  34. Comando = ""; //esvaziado a variável
  35. }
  36.  
  37. if(Comando2.indexOf("LED1 OFF")>=0){ //Se a variável contém o comando palavra LED1 OFF
  38. Serial.println("LED1 DESLIGADO"); //Avisamos por comunicacion serial
  39. digitalWrite(LED1, LOW); //Desactivar o LED1
  40. retornaSMS();
  41. Comando = ""; //esvaziado a variável
  42. }
  43. if(Comando2.indexOf("LED2 ON")>=0){ //Se a variável contém a palavra LED2 ON
  44. Serial.println("LED2 LIGADO"); //Avisamos por comunicacion serial
  45. digitalWrite(LED2, HIGH); //ativar o LED2
  46. retornaSMS();
  47. Comando = ""; //esvaziado a variável
  48. }
  49.  
  50. if(Comando2.indexOf("LED2 OFF")>=0){ //Se a variável contém o comando palavra LED2 OFF
  51. Serial.println("LED2 DESLIGADO"); //Avisamos por comunicacion serial
  52. digitalWrite(LED2, LOW); //Desactivar o LED2
  53. Comando = ""; //esvaziado a variável
  54. }
  55. }
  56. void retornaSMS()
  57. {
  58. teste="LED1= ";
  59. teste+=led[digitalRead(LED1)];
  60. teste+="\nLED2= ";
  61. teste+=led[digitalRead(LED2)];
  62. //teste+="\nLED3= "; //----------------so ir colocando as linhas dessa forma
  63. //teste+=led[digitalRead(LED3)];
  64. Serial.println("AT+CMGF=1"); //Define o módulo GSM no modo de texto
  65. delay(1000);
  66. Serial1.println("AT+CMGS=\"+5587988326471\"\r"); //Substituir x pelo número de celular
  67. delay(1000);
  68. Serial1.println(teste);
  69. delay(1000);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement