Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <nRF905.h>
- #include <SPI.h>
- #define RXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of this device (4 bytes)
- #define TXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of device to send to (4 bytes)
- #define TIMEOUT 1000 // 1 second ping timeout
- #define PIR 33
- String Payload;
- boolean PIRval;
- String dataType;
- void setup()
- {
- pinMode(PIR, INPUT);
- // Start up
- nRF905_init();
- // Set address of this device
- byte addr[] = RXADDR;
- nRF905_setRXAddress(addr);
- // Put into receive mode
- nRF905_receive();
- nRF905_setTXAddress(addr);
- Serial.begin(9600);
- Serial.println(F("Client started"));
- }
- void loop()
- {
- PIRval = digitalRead(PIR);
- Serial.println(PIRval);
- if (PIRval != 0) {
- dataType = "PR";
- Payload = dataType + "NO INTRUSION!!!";
- Payload.trim();
- }
- else if (PIRval == 0) {
- dataType = "PR";
- Payload = dataType + " URGENT!!!";
- Payload.trim();
- }
- // Make data
- char data[NRF905_MAX_PAYLOAD] = {0};
- Payload.toCharArray(data, 32);
- // Set address of device to send to
- byte addr[] = TXADDR;
- nRF905_setTXAddress(addr);
- // Set payload data
- nRF905_setData(data, sizeof(data));
- // Send payload (send fails if other transmissions are going on, keep trying until success)
- nRF905_send();
- // Put into receive mode
- nRF905_receive();
- Serial.println("sent!");
- Serial.print(data);
- Serial.println();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement