Guest User

Untitled

a guest
Oct 8th, 2016
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <nRF905.h>
  2. #include <SPI.h>
  3.  
  4. #define RXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of this device (4 bytes)
  5. #define TXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of device to send to (4 bytes)
  6.  
  7. #define TIMEOUT 1000 // 1 second ping timeout
  8.  
  9. #define PIR 33
  10.  
  11. String Payload;
  12. boolean PIRval;
  13. String dataType;
  14.  
  15.  
  16. void setup()
  17. {
  18.  
  19. pinMode(PIR, INPUT);
  20.  
  21. // Start up
  22. nRF905_init();
  23.  
  24. // Set address of this device
  25. byte addr[] = RXADDR;
  26. nRF905_setRXAddress(addr);
  27.  
  28. // Put into receive mode
  29. nRF905_receive();
  30.  
  31. nRF905_setTXAddress(addr);
  32.  
  33. Serial.begin(9600);
  34.  
  35. Serial.println(F("Client started"));
  36. }
  37.  
  38. void loop()
  39. {
  40. PIRval = digitalRead(PIR);
  41. Serial.println(PIRval);
  42.  
  43. if (PIRval != 0) {
  44. dataType = "PR";
  45. Payload = dataType + "NO INTRUSION!!!";
  46. Payload.trim();
  47. }
  48. else if (PIRval == 0) {
  49. dataType = "PR";
  50. Payload = dataType + " URGENT!!!";
  51. Payload.trim();
  52. }
  53.  
  54. // Make data
  55. char data[NRF905_MAX_PAYLOAD] = {0};
  56. Payload.toCharArray(data, 32);
  57.  
  58. // Set address of device to send to
  59. byte addr[] = TXADDR;
  60. nRF905_setTXAddress(addr);
  61.  
  62. // Set payload data
  63. nRF905_setData(data, sizeof(data));
  64.  
  65. // Send payload (send fails if other transmissions are going on, keep trying until success)
  66. nRF905_send();
  67.  
  68. // Put into receive mode
  69. nRF905_receive();
  70.  
  71. Serial.println("sent!");
  72. Serial.print(data);
  73. Serial.println();
  74. delay(1000);
  75. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×