Advertisement
Guest User

RX

a guest
Feb 22nd, 2015
1,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. // Include VirtualWire library
  2. #include <VirtualWire.h>
  3. #include <SoftwareSerial.h>
  4. SoftwareSerial SIM900(2, 3); // configure software serial port
  5.  
  6. // Pins definition
  7.  
  8. const int receive_pin = 9;
  9. int minSecsBetweenCalls = 30; // 0.5 min
  10. long lastSend = -minSecsBetweenCalls * 1000l;
  11.  
  12. void setup()
  13. {
  14. SIM900.begin(19200);
  15. Serial.begin(19200);
  16.  
  17.  
  18. delay(20000); // give time to log on to network.
  19.  
  20. digitalWrite(6, HIGH);
  21. delay(1000);
  22. digitalWrite(6, LOW);
  23. // software equivalent of pressing the GSM shield "power" button
  24.  
  25. // Initialise the IO and ISR
  26. vw_set_rx_pin(receive_pin);
  27. vw_setup(4000); // Transmission rate
  28. // Start the receiver PLL
  29. vw_rx_start();
  30. // Set LED pin and Buzzer
  31.  
  32. }
  33.  
  34. void loop()
  35. {
  36. long now = millis();
  37.  
  38. uint8_t buf[VW_MAX_MESSAGE_LEN];
  39. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  40.  
  41. // Check if a message was received
  42. if (vw_get_message(buf, &buflen))
  43. {
  44. if(buf[0]=='1')
  45. {
  46. if (now > (lastSend + minSecsBetweenCalls * 1000l))
  47. {
  48. Serial.println("Motion detected!");
  49. SIM900.println("ATD + +47xxxxxxxx;"); // dial number (language code between + and your phone number)
  50. lastSend = now;
  51. delay(100);
  52. SIM900.println();
  53. delay(30000); // wait for 30 seconds...
  54. SIM900.println("ATH"); // hang up
  55. }
  56. if(buf[0]=='0')
  57. {
  58. Serial.println("Motion ended!");
  59.  
  60.  
  61. delay(300);
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement