Advertisement
dimoura

Untitled

May 27th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // ---------SMS-----------//
  2. #include "SIM900.h"
  3. #include <SoftwareSerial.h>
  4. //Carrega a biblioteca SMS
  5. #include "sms.h"
  6.  
  7. SMSGSM sms;
  8.  
  9. int numdata;
  10. boolean started=false;
  11. char smsbuffer[160];
  12. char n[20];
  13. // ----------------------//
  14.  
  15. // ---------Rele---------//
  16. int porta_rele1 = 7;
  17. //----------------------//
  18.  
  19. void setup()
  20. {
  21. pinMode(porta_rele1, OUTPUT);
  22.  
  23. Serial.begin(9600);
  24. Serial.println("Testando GSM shield...");
  25. //Inicia a configuracao do Shield
  26. if (gsm.begin(2400))
  27. {
  28. Serial.println("nstatus=READY");
  29. started=true;
  30. }
  31. else Serial.println("nstatus=IDLE");
  32. }
  33. void loop()
  34. {
  35. leitura_sensores();
  36. envia_sms();
  37. }
  38. void leitura_sensores()
  39. {
  40. // -----------------------------------------//
  41. int sensorValue = analogRead(A0);
  42. Serial.println(sensorValue);
  43. delay(2000);
  44. // -----------------------------------------//
  45.  
  46. if (sensorValue <= 1000)
  47. {
  48. pinMode(porta_rele1, LOW);
  49. }
  50. else
  51. {
  52. pinMode(porta_rele1, HIGH);
  53. }
  54. }
  55. void envia_sms()
  56. {
  57. if(started)
  58. {
  59. if (sms.SendSMS("+5562XXXXXXX", "Sistema Ligado"))
  60. Serial.println("nSMS sent OK");
  61. }
  62. else
  63. {
  64. // --- Sistema Desligado ---
  65. if(started)
  66. {
  67. if (sms.SendSMS("+5562XXXXXXX", "Sistema Desligado"))
  68. Serial.println("nSMS sent OK");
  69. }
  70. }
  71. }
  72. // --------Fim SMS-------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement