Gps collar help

Hi everyone, i was wondering if it is possible to do polygon algorithm 2x, meaning a box within a box. I found this website GPS Dog Fence | Hackaday.io i can modify to my board and gps module or is it possible to set it up like if the dog gets 5ft from the fence it starts beeping, like how wired fencing is.

Thank you so much for your help

i was wondering if it is possible to do polygon algorithm 2x, meaning a box within a box.

Of course it is. The point of interest (the dog) is in a box, or it isn't. If you know whether in-a-box means that the dog is where it belongs, or not, then you know whether the dog is where it belongs, or not.

If the two boxes represent the yard and the rose garden, and the dog is in both boxes, the roses are in danger. If the dog is in the yard but not in the rose garden, the roses are safe (from the dog).

Just define the "dog box" (the containing polygon) to be 5 feet from the fence, everywhere.

I would think 5’ is pushing the gps capability , and also the response time - dog reaches fence whilst gps is thinking about it

this is the code so far, I cant figure out how to input the 2nd set of grid cords.


l ______________ l
l l l l
l l /\ l l
l l l_l l l
l l______________l l
l_________________l

#include <TinyGPS++.h>
#include <SoftwareSerial.h>      // Include software serial library

#define S_RX     4                // Define software serial RX pin
#define S_TX     3                // Define software serial TX pin
#define D7       7                // pinmode number 7
#define buzzer   8                // pinmode number 8

TinyGPSPlus gps;

bool sat_connection = false;
double lat,lon;
bool c;
int i,j;
long unsigned fix_age;
long unsigned sat;
int count1 = 0;
int count2 = 0;

double latitude[100] = {XX.xxxxxx, XX.xxxxxx, XX.xxxxxx, XX.xxxxxx}; // Insert at least 4 latitude coordinates (Do not put your first coordinate again at the end to complete the polygon, the algorithm does this for you)
double longitude[100] = {XX.xxxxxx, XX.xxxxxx, XX.xxxxxx, XX.xxxxxx}; // and their matching longitude points
int numPoints = 4;  // Put the number of latitude and longitude pairs you used here



SoftwareSerial SoftSerial(S_RX, S_TX);    // Configure SoftSerial library

void setup() {
Serial.begin(9600);
SoftSerial.begin(4800);
pinMode(D7,OUTPUT);  // setup the pin used to turn on collar trigger circuit
pinMode(Buzzer,OUTPUT);  // setup the pin used to turn on collar buzzer circit
}

void loop() {

    while (SoftSerial.available() > 0) {
     gps.encode(SoftSerial.read());
     lat = gps.location.rawLat().billionths;
     lon = gps.location.rawLng().billionths;
     lat = gps.location.lat(), 8;
     lon = gps.location.lng(), 8;
    // display position
    Serial.print("Position: ");
    Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
    Serial.print("lon: ");Serial.println(lon);// print longitude
    sat = gps.satellites.value();
    Serial.print("Num Satelites: ");Serial.println(sat);
    
         
    }
    
    double testx = lon;
    double testy = lat;
    Serial.print("testx = ");
    Serial.print(testx, 8);
    Serial.print("\n");
    Serial.print("testy = ");
    Serial.print(testy, 8);
    Serial.print("\n");
    
    c = false;
    for (i = 0, j = numPoints-1; i < numPoints; j = i++) {
        Serial.print("latitude[i] = ");
        Serial.print(latitude[i], 8);
        Serial.print("\n");
        Serial.print("latitude[j] = ");
        Serial.print(latitude[j], 8);
        Serial.print("\n");
        Serial.print("longitude[i] = ");
        Serial.print(longitude[i], 8);
        Serial.print("\n");
        Serial.print("longitude[j] = ");
        Serial.print(longitude[j], 8);
        Serial.print("\n");
        // BELOW IS THE POINT IN POLYGON ALGORITHM.  I COMPLETELY BORROWED THIS CODE, BUT IT WORKS.
    if ( ((latitude[i]>testy) != (latitude[j]>testy)) &&
   (testx < (longitude[j]-longitude[i]) * (testy-latitude[i]) / (latitude[j]-latitude[i]) + longitude[i]) ){
       c = !c;
       Serial.print("is this happening?");
   }
       
  }
//-----
//-----
    
   if ((sat_connection == true) && (c == false)){
Serial.print("Outside Fence \n");
        if (count1 == 0){
            count1 = 1;
        }
        if (count2 == 0){
            digitalWrite(D7,HIGH);

        }
        else if (count2 == 1){
            digitalWrite(D7,LOW);
        }
}
  if ((sat_connection == false) ||  (c == true)){
    digitalWrite(D7,LOW);
    Serial.print("Inside Fence \n");


   }  
   if (c ==true){
    count1 = 0;
    count2 = 0;
   }
    }

how to input the 2nd set of grid cords.

What do you mean by this? What is the 1st set?

No sense in declaring arrays to be of length 100, when you are storing only four points.

Drop the ", 8" as seen below. It is used (nonsensically in this case) with Serial.print().

     lat = gps.location.lat(), 8;

Hint: First, just get a basic program running that demonstrates correct use of the polygon routine, and verify that it gives the correct results for a point inside or outside the polygon. When you finally and completely understand how it works, add the GPS stuff later.

The second set is inter perimeter will turn on the buzzer, the first set is outer perimeter will turn on the shocker. Im not using the Particle Electron & Copernicus II GPS like the original code is intended for. Serial.print is in the original code, i can post it if you would like

Suggest you try reading ALL of each reply before responding. But if reading more two lines is a problem:

Hint: First, just get a basic program running that demonstrates correct use of the polygon routine