Connor Owensby
Published © GPL3+

IoT Project

Pet collar radio tracking device that utilizes a Particle Photon and a nRF24L01 radio transceiver.

BeginnerFull instructions provided1 hour957
IoT Project

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Code

Tranmitter Code

C/C++
#include <particle-rf24.h>              //nrf24l01 library
RF24 radio(D0,D1);                      //Set the CE and CSE pins for SPI Connection
const byte address[6]= "00001";         //Set Channel Name


int subtime=millis();                   //Setup for variable to keep track of the last subscribe time
const char text[32]="HELLO WORLD";      //Set the message to be sent
int flag=0;


void setup() {
    pinMode(D7,OUTPUT);                 //LED Output
    pinMode(D0,OUTPUT);                 // CE Output
    pinMode(D1,OUTPUT);                 //CSE Output
    
    SPI.begin();
    Serial.begin();
    radio.begin();
    
    radio.openWritingPipe(address);     //Set up the Channel
    radio.setPALevel(RF24_PA_MIN);      //Set Transmittion Strength
    radio.stopListening();              //Set as Transmitting
}


void loop() {

    if(millis()-subtime>1000){          //sets a delay without having a pause 
        radio.write(text, sizeof(text));//Sends the "HELLO WORLD" Messege
        delay(1000);
        Particle.subscribe("recieved",chart,MY_DEVICES);//Compiles the recieved code from the Receiver
        subtime=millis();               //Reset the delay 
    }
}


int chart(const char *event, const char *data){

    delay(50);                          //Flashs the LED
    digitalWrite(D7,HIGH);              //
    delay(50);                          //
    digitalWrite(D7,LOW);     
   if(*data=='2'){
        Particle.publish("chart","2");//Send Data from one source so that IFFT can work with it
    }
   if(*data=='1'){
        Particle.publish("chart","1");//Send Data from one source so that IFFT can work with it
    }
}

Reciever Code

C/C++
#include <particle-rf24.h>                  //nrf24l01 library 

 
RF24 radio(D0,D1);                          //Set the CE and CSE pins for SPI Connection
const byte address[6]= "00001";             //Set Channel Name
 char text[32] = "";                        
int STime=millis();                         //Set a Delay on Publishing 

 
void setup() {                      
    pinMode(D0,OUTPUT);                     //CE Output
    pinMode(D1,OUTPUT);                     //CSE Output
    
    SPI1.begin();                           
    Serial.begin();
    
    radio.begin();
    radio.openReadingPipe(1,address);       // Set the Radio Channel
    radio.setPALevel(RF24_PA_MIN);          //Set Low Power Mode
    radio.startListening();                 // Set Radio For receiver
}

void loop() {
    if(radio.available()){               // If there is activity on the channel
        radio.read(text, sizeof(text));   //Read the Messege
        if (millis()-STime>10000){     //if the last publish time was x millis ago
            Particle.publish("recieved","1",PRIVATE);//publish that the data was received and the particle that received it
            STime=millis();        //Reset the delay
        }
    }
}

Credits

Connor Owensby

Connor Owensby

1 project • 0 followers

Comments